From 38cbc87b3244974c8ea018953293dd1fbc1532ae Mon Sep 17 00:00:00 2001 From: c-salv Date: Wed, 15 Oct 2025 11:07:05 +0200 Subject: [PATCH 1/3] feat: add FastAPI example application with Docker --- examples/fastapi/Dockerfile | 17 +++++++++++++++++ examples/fastapi/README.md | 23 +++++++++++++++++++++++ examples/fastapi/app.py | 8 ++++++++ 3 files changed, 48 insertions(+) create mode 100644 examples/fastapi/Dockerfile create mode 100644 examples/fastapi/README.md create mode 100644 examples/fastapi/app.py diff --git a/examples/fastapi/Dockerfile b/examples/fastapi/Dockerfile new file mode 100644 index 00000000..7172587d --- /dev/null +++ b/examples/fastapi/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.12-slim + +WORKDIR /app + +COPY . /app + +RUN pip install fastapi uvicorn elastic-opentelemetry + +# Install all the instrumentations available for the installed packages +RUN edot-bootstrap -a install + +EXPOSE 5000 + +# Set some resource attributes to make our service recognizable +ENV OTEL_RESOURCE_ATTRIBUTES="service.name=FastAPIService,service.version=0.0.1,deployment.environment=development" + +CMD ["opentelemetry-instrument", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000"] diff --git a/examples/fastapi/README.md b/examples/fastapi/README.md new file mode 100644 index 00000000..47be5a6b --- /dev/null +++ b/examples/fastapi/README.md @@ -0,0 +1,23 @@ +# FastAPI autoinstrumented application + +This is a barebone FastAPI app used for demonstrating autoinstrumentation with EDOT. + +You can build the application image it with: + +``` +docker build --load -t edot-fastapi:latest . +``` + +You can run the application with: + +``` +export OTEL_EXPORTER_OTLP_ENDPOINT=https://my-deployment.apm.us-west1.gcp.cloud.es.io +export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer P....l" +docker run -e OTEL_EXPORTER_OTLP_ENDPOINT="$OTEL_EXPORTER_OTLP_ENDPOINT" \ + -e OTEL_EXPORTER_OTLP_HEADERS="$OTEL_EXPORTER_OTLP_HEADERS" \ + -p 5000:5000 -it --rm edot-fastapi:latest +``` + +You can access the application from [http://127.0.0.1:5000](http://127.0.0.1:5000). + +``` diff --git a/examples/fastapi/app.py b/examples/fastapi/app.py new file mode 100644 index 00000000..41910f15 --- /dev/null +++ b/examples/fastapi/app.py @@ -0,0 +1,8 @@ +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +async def root(): + return {"message": "Hello, world!"} From de0057419e54b384362daa3e91f752e972f03123 Mon Sep 17 00:00:00 2001 From: c-salv Date: Wed, 15 Oct 2025 11:10:24 +0200 Subject: [PATCH 2/3] typo fix README --- examples/fastapi/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/fastapi/README.md b/examples/fastapi/README.md index 47be5a6b..8d07d00a 100644 --- a/examples/fastapi/README.md +++ b/examples/fastapi/README.md @@ -19,5 +19,3 @@ docker run -e OTEL_EXPORTER_OTLP_ENDPOINT="$OTEL_EXPORTER_OTLP_ENDPOINT" \ ``` You can access the application from [http://127.0.0.1:5000](http://127.0.0.1:5000). - -``` From 454127b02ecdf9046bc4507738a8641f2b2541f9 Mon Sep 17 00:00:00 2001 From: c-salv Date: Wed, 15 Oct 2025 11:11:49 +0200 Subject: [PATCH 3/3] chore: add copyright notice to FastAPI example application --- examples/fastapi/app.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/examples/fastapi/app.py b/examples/fastapi/app.py index 41910f15..59080656 100644 --- a/examples/fastapi/app.py +++ b/examples/fastapi/app.py @@ -1,3 +1,19 @@ +# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +# or more contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from fastapi import FastAPI app = FastAPI()