Skip to content

Commit 3cb1c08

Browse files
authored
Introduce examples dir with an autoinstrumented flask app (#168)
* Introduce examples dir with an autoinstrumented flask app * Reword opentelemetry-bootstrap comment * Add license header to the flask example * Update examples/flask/Dockerfile
1 parent 61a5bb4 commit 3cb1c08

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

examples/flask/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
COPY . /app
6+
7+
RUN pip install flask elastic-opentelemetry
8+
9+
# Install all the instrumentations available for the installed packages
10+
RUN opentelemetry-bootstrap -a install
11+
12+
# default flask run port
13+
EXPOSE 5000
14+
15+
# Set some resource attributes to make our service recognizable
16+
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=FlaskService,service.version=0.0.1,deployment.environment=development"
17+
18+
CMD ["opentelemetry-instrument", "flask", "run"]

examples/flask/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Flask autoinstrumented application
2+
3+
This is a barebone Flask app used for demonstrating autoinstrumentation with EDOT.
4+
5+
You can build the application image it with:
6+
7+
```
8+
docker build --load -t edot-flask:latest .
9+
```
10+
11+
You can run the application with:
12+
13+
```
14+
export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.apm.us-west1.gcp.cloud.es.io
15+
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer P....l"
16+
docker run -e OTEL_EXPORTER_OTLP_ENDPOINT="$OTEL_EXPORTER_OTLP_ENDPOINT" \
17+
-e OTEL_EXPORTER_OTLP_HEADERS="$OTEL_EXPORTER_OTLP_HEADERS" \
18+
-p 5000:5000 -it --rm edot-flask:latest
19+
```
20+
21+
You can access the application from [http://127.0.0.1:5000](http://127.0.0.1:5000).

examples/flask/app.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
# or more contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from flask import Flask, jsonify
18+
19+
app = Flask(__name__)
20+
21+
22+
@app.route("/", methods=["GET"])
23+
def home():
24+
return jsonify(message="Hello, world!")

0 commit comments

Comments
 (0)