azure-sdk-for-python: ASGI opentelemetry.instrumentation packages incompatible with azure-monitor-opentelemetry-exporter
- azure-monitor-opentelemetry-exporter
- Package Version - azure-monitor-opentelemetry-exporter = {version = “^1.0.0-beta.3”, allow-prereleases = true}
- Operating System - macOS Mojave v10.14.6
- Python Version - v3.9.0
Describe the bug We are using FastAPI in our production and successfully implemented log exporting using Azure log handers to Azure App Insights. On implementing OpenTelemetry, no versions of azure-monitor-opentelemetry-exporter match >1.0.0-beta.3,<2.0.0, opentelemetry-instrumentation-fastapi (>=0.19b0,<0.20) is incompatible with azure-monitor-opentelemetry-exporter (>=1.0.0-beta.3,<2.0.0)
ASGI open telemetry packages like,
FastAPI Instrumentation Starlette Instrumentation ASGI instrumentation
face the same dependency conflict with Azure monitor exporter
To Reproduce Steps to reproduce the behavior: After installing the required packages, try running the following FastAPI app: `import os import fastapi import uvicorn from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
app = fastapi.FastAPI()
@app.get(“/foor”) async def foo(): return {“message”: “hello world”}
trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer(name) span_processor = BatchExportSpanProcessor( AzureMonitorTraceExporter.from_connection_string( os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "] ) ) trace.get_tracer_provider().add_span_processor(span_processor)
FastAPIInstrumentor.instrument_app(app)
if name == “main”: uvicorn.run(app, host=“0.0.0.0”, port=8000)`
On installing the required packages, there would be a dependency conflict as illustrated in the screenshots in below sections.
Expected behavior Ability to gather telemetry from FastAPI(ASGI) apps; on the lines of this Flask sample posted in this repo Flask
Screenshots If applicable, add screenshots to help explain your problem. Listing the dependencies version for azure-monitor-opentelemetry-exporter (with allow pre-releases):
Dependency resolver error when trying to add opentelemetry-instrumentation package:
Additional context In an attempt to track incoming requests, we followed this article OpenCensus FastAPI implementation Unfortunately this instrumentation is leading to OOM issues in our Kubernetes deployment and ended up pivoting to open telemetry.
Open telemetry version: opentelemetry-instrumentation-fastapi 0.19b0
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (11 by maintainers)
Thanks @rakshith91 @lzchen for all the help.
Closing the issue.
P.S. unlike the OpenCensus implementation, did not encounter OOM issue whilst using the opentelemetry azure monitor with fastapi instrumentation package. Thanks again for all this awesome work.
@rakshith91
SimpleExportSpanProcessor Used SimpleSpanProcessor instead of SimpleExportSpanProcessor based on previous directions.
Docs for azure core tracing need updating.
Difficult to say what the culprit is in terms of what is causing the OOM. I would suggest removing components one by one until the source of what is not being garbage collected or cleaned up properly can be found. Also, implementing an actual FastAPI integration might be a solution as well.