From c81c044193983f11e9fc683d1b120df228fe9eed Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Wed, 19 Feb 2025 16:02:28 +0100 Subject: [PATCH 1/2] add aiohttp example --- examples/aiohttp/Dockerfile | 17 +++++++++++++++++ examples/aiohttp/README.md | 23 +++++++++++++++++++++++ examples/aiohttp/app.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 examples/aiohttp/Dockerfile create mode 100644 examples/aiohttp/README.md create mode 100644 examples/aiohttp/app.py diff --git a/examples/aiohttp/Dockerfile b/examples/aiohttp/Dockerfile new file mode 100644 index 0000000..4845046 --- /dev/null +++ b/examples/aiohttp/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.13-slim + +WORKDIR /app + +COPY . /app + +RUN pip install aiohttp elastic-opentelemetry + +# Install all the instrumentations available for the installed packages +RUN edot-bootstrap -a install + +EXPOSE 8080 + +# Set some resource attributes to make our service recognizable +ENV OTEL_RESOURCE_ATTRIBUTES="service.name=AioHttpService,service.version=0.0.1,deployment.environment=development" + +CMD ["opentelemetry-instrument", "python", "app.py"] diff --git a/examples/aiohttp/README.md b/examples/aiohttp/README.md new file mode 100644 index 0000000..7c0adb7 --- /dev/null +++ b/examples/aiohttp/README.md @@ -0,0 +1,23 @@ +# Aiohttp autoinstrumented application + +This is a barebone aiohttp app used for demonstrating autoinstrumentation with EDOT. + +You can build the application image it with: + +``` +docker build --load -t edot-aiohttp:latest . +``` + +You can run the application with: + +```sh +export OTEL_METRICS_EXPORTER=otlp +export OTEL_LOGS_EXPORTER=otlp +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 8080:8080 -it --rm edot-aiohttp:latest +``` + +You can access the application from [http://127.0.0.1:8080](http://127.0.0.1:8080). diff --git a/examples/aiohttp/app.py b/examples/aiohttp/app.py new file mode 100644 index 0000000..6495f46 --- /dev/null +++ b/examples/aiohttp/app.py @@ -0,0 +1,35 @@ +# 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. + +import logging +from aiohttp import web + + +logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") +logger = logging.getLogger(__name__) + +routes = web.RouteTableDef() + + +@routes.get("/") +async def hello(request): + logger.info("Hello, world") + return web.Response(text="Hello, world") + + +app = web.Application() +app.add_routes(routes) +web.run_app(app) From 8814a5584a0c8511b0eb22a372de352ecb976daa Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Wed, 19 Feb 2025 17:09:53 +0100 Subject: [PATCH 2/2] Update examples/aiohttp/README.md Co-authored-by: Riccardo Magliocchetti --- examples/aiohttp/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/aiohttp/README.md b/examples/aiohttp/README.md index 7c0adb7..a49b5c6 100644 --- a/examples/aiohttp/README.md +++ b/examples/aiohttp/README.md @@ -11,8 +11,6 @@ docker build --load -t edot-aiohttp:latest . You can run the application with: ```sh -export OTEL_METRICS_EXPORTER=otlp -export OTEL_LOGS_EXPORTER=otlp 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" \