I followed the instructions and the sample project here: https://github.com/microsoft/ApplicationInsights-Python/blob/05a8b1dd3556ab5e7c268c22ee30a365eaf5ec7a/azure-monitor-opentelemetry/samples/tracing/http_fastapi.py#L15. I set up my app insights account and I can see exceptions and dependencies properly getting logged.
However, the requests table is not getting populated.. Based on the link above, requests to my FastAPI should automatically be populated. Am I doing something wrong?
I have also encountered this issue recently after migrating a FastAPI app from openCensus to OpenTelemetry. The issue can be due to importing the FastAPI or Flask app before you initialize the logger. From the following link, which has plenty of useful other debugging information: https://learn.microsoft.com/en-us/troubleshoot/azure/azure-monitor/app-insights/telemetry/opentelemetry-troubleshooting-python
If you are missing Requests table data but not other categories, it is likely that your http framework is not being instrumented. This can occur in FastAPI and Flask apps using the Azure Monitor OpenTelemetry Distro client library for Python if you don't structure your import declarations correctly. You might be importing the fastapi.FastAPI or flask.Flask respectively before you call the configure_azure_monitor function to instrument the FastAPI and Flask libraries. For example, the following code doesn't successfully instrument the FastAPI and Flask apps:
# FastAPI
from azure.monitor.opentelemetry import configure_azure_monitor
from fastapi import FastAPI
configure_azure_monitor()
app = FastAPI()
But doing the following resulted in the requests table successfully being populated:
# FastAPI
from azure.monitor.opentelemetry import configure_azure_monitor
configure_azure_monitor()
from fastapi import FastAPI
app = FastAPI(__name__)
For completeness the article also suggests the following to fix the issue:
Instead, we recommend that you import the fastapi or flask modules as a whole, and then call configure_azure_monitor to configure OpenTelemetry to use Azure Monitor before you access fastapi.FastAPI or flask.Flask:
# FastAPI
from azure.monitor.opentelemetry import configure_azure_monitor
import fastapi
configure_azure_monitor()
app = fastapi.FastAPI(__name__)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With