Comments (3)
I have the same problem I think
I followed the same example
My context : when deployed I use Azure App Service + Fastapi inside a docker container and in local I just run Fastapi
Those are my libs with poetry :
opentelemetry-api = "1.17.0"
opentelemetry-sdk = "1.17.0"
azure-monitor-opentelemetry = {version = "^1.0.0b13", allow-prereleases = true}
I tested the tracing and the metrics
For the metrics, it works as expected and for the tracing when I test my routes there is no display of tracing of my routes.
Also I tested also with opentelemetry + azure-monitor-opentelemetry-exporter directly with those libs and following some tutos
azure-monitor-opentelemetry-exporter = {version = "^1.0.0b14", allow-prereleases = true}
opentelemetry-instrumentation-fastapi = "^0.39b0"
opentelemetry-api = "1.18.0"
opentelemetry-sdk = "1.18.0"
opentelemetry-instrumentation-fastapi = "^0.39b0"
and it works
This is the pseudo code I put to make it works
from fastapi.responses import JSONResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from opentelemetry.context import get_current as get_current_context
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider, _Span
from opentelemetry.sdk.trace.export import (BatchSpanProcessor,
ConsoleSpanExporter,
SimpleSpanProcessor)
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
tracer = TracerProvider()
tracer.add_span_processor(
SimpleSpanProcessor(ConsoleSpanExporter())
)
exporter = AzureMonitorTraceExporter.from_connection_string(
"MY_KEY"
)
tracer.add_span_processor(
BatchSpanProcessor(exporter)
)
app = FastAPI()
FastAPIInstrumentor.instrument_app(app, tracer_provider=tracer)
@app.exception_handler(StarletteHTTPException)
async def http_exception_handler(request: Request, exc):
span_key = list(get_current_context().keys())[0]
span = get_current_context().get(span_key)
assert isinstance(span, _Span)
return JSONResponse(
{
"message": str(exc.detail),
"trace_id": span.context.trace_id,
"span_id": span.context.span_id
},
status_code=exc.status_code
)
from applicationinsights-python.
Hi! I ended up solving this, but I had to just use the opencensus package.. in the end, the problem was how the instrumentation key was being set...
app.add_middleware(FastAPIMiddleware, exporter=AzureExporter(connection_string=application_insights_connection_string))
application_insights_connection_string= 'InstrumentationKey=XXXX'
this in addition to using from opencensus.ext.azure.trace_exporter import AzureExporter
did it for me
from applicationinsights-python.
Hey @kevinco26
Thanks for the tips
what is this FastAPIMiddleware ? is it your or someone custom middleware, if yes can you share it ?
from applicationinsights-python.
Related Issues (20)
- Log level cannot be configured through `logging_level` argument HOT 1
- Vendor instrumentations
- Add custom exporter support for all pillars HOT 1
- Separate Attach logic into new package that depends on distro HOT 1
- Add documentation for useful instrumentation configurations. HOT 1
- This repo is missing important files HOT 1
- Confirm licensing approach for vendoring is correct HOT 1
- Support for OpenTelemetry instrumentation aiohttp-client HOT 2
- Support for OpenTelemetry instrumentation grpc HOT 2
- Benefit from this package without using AzureInsights? (Offline Use within docker-compose?) HOT 4
- No tracing with Opentelemetry distro for Azure + Python + Fastapi HOT 3
- Unwanted dependencies are tracked which are not required HOT 3
- Not able to set cloudrole name HOT 3
- Flask auto-instrumentation doesn't configure itself properly HOT 9
- No insights in application map from sample code correlated logs HOT 2
- 'MessageData' is required but missing or empty HOT 3
- What's the problem with duplicated logs? HOT 12
- Too much traces in AppInsights HOT 8
- Resource error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from applicationinsights-python.