Skip to content

Commit c1b1b70

Browse files
committed
Use FastAPI instrumentor
1 parent 38c44a5 commit c1b1b70

File tree

3 files changed

+155
-153
lines changed

3 files changed

+155
-153
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ http = [
3737
"fastapi>=0.99.0",
3838
"jinja2<4.0.0,>=3.1.2",
3939
# We use the generic ASGI instrumentation, so that if we decide to change
40-
# Framework it will still work consistently.
40+
# framework it will still name metrics with a generic naming.
4141
"opentelemetry-instrumentation-asgi",
42+
"opentelemetry-instrumentation-fastapi",
4243
"pyjwt>=2.10.1",
43-
"starlette-prometheus<1.0.0,>=0.10.0",
4444
"strawberry-graphql[debug-server]>=0.204.0",
4545
"uvicorn[standard]<1.0.0,>=0.34.0",
4646
]

src/http_app/__init__.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
from typing import Union
33

44
from fastapi import FastAPI, Request
5-
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
65
from starlette.responses import JSONResponse
7-
from starlette_prometheus import PrometheusMiddleware, metrics
86

97
from common import AppConfig, application_init
108
from http_app import context
@@ -34,21 +32,6 @@ def create_app(
3432

3533
init_routes(app)
3634

37-
"""
38-
OpenTelemetry prometheus exporter does not work together with automatic
39-
instrumentation, for now we keep the prometheus middleware even if
40-
having 2 different middlewares will add overhead.
41-
"""
42-
app.add_middleware(PrometheusMiddleware)
43-
app.add_route("/metrics/", metrics)
44-
45-
"""
46-
OpenTelemetry middleware has to be the last one to make sure the
47-
tracing data handling is the outermost logic
48-
Some typing issues to be addressed in OpenTelemetry but it works.
49-
"""
50-
app.add_middleware(OpenTelemetryMiddleware) # type: ignore
51-
5235
return app
5336

5437

0 commit comments

Comments
 (0)