It looks like you're facing issues with duplicate logs in Azure Application Insights when using FastAPI. Duplicate logs can be a bit tricky, but let's go through some potential reasons and solutions.
Why You Might Be Seeing Duplicate Logs:
- Multiple SDK Activations: If you have both the OpenCensus SDK and OpenTelemetry activated in the same application, that can lead to duplicate telemetry.
- Ingestion Behavior: Azure's ingestion pipeline might reprocess data due to local instabilities, which could introduce duplicates.
- Diagnostic Settings Misconfiguration: If you have configured diagnostic settings to export Application Insights data to a Log Analytics workspace while still sending data to Application Insights itself, you could see duplication.
- Logging Configuration: Ensure that the logger configurations, especially with propagate, are set correctly to avoid logging redundancies.
Recommended Steps to Resolve Duplicate Logs:
- Check for Overlapping SDKs: Ensure you're only using one SDK for monitoring in your FastAPI application.
- Review Logging Configuration:
- Double-check your logger setup, making sure you have only one logger initialized for each use case.
- If not required, set logger.propagate = False correctly to prevent logs from propagating to the root logger.
- Debug Diagnostic Settings:
- Verify the diagnostic settings in your Application Insights resource to ensure you're not inadvertently logging to multiple workspaces.
- Ensure the Log Analytics workspace you are exporting to is different from the one your Application Insights resource is based on.
- Use KQL for Duplicate Analysis: To analyze the logs, you can use Kusto Query Language (KQL) to identify duplicates in your Application Insights:
let data =
traces
| where timestamp > ago(2h);
let _data = materialize(data);
_data
| summarize Count=count() by tostring(customDimensions['some_property'])
| where Count > 1
Follow-Up Questions for More Context:
- Have you confirmed that no other logging configuration or SDK is running concurrently with your FastAPI application?
- Can you provide details about how you are running your application (e.g., the exact command and environment)?
- Have you checked the Application Insights diagnostic settings to see if duplicates could be originating from here?
- Are there specific log entries that are being duplicated, or is it all log entries?
I hope these insights help you resolve your issue with duplicate logs! If the problem persists after trying these steps, it might be useful to gather additional information and analyze the logs in depth. Feel free to reach out with any more questions!