Skip to content

fix: enhance error handling and logging in event tracking and span processing (fix CodeQL & copilot comments)#823

Merged
Avijit-Microsoft merged 2 commits into
devfrom
psl-pk-copilotcomments
Mar 20, 2026
Merged

fix: enhance error handling and logging in event tracking and span processing (fix CodeQL & copilot comments)#823
Avijit-Microsoft merged 2 commits into
devfrom
psl-pk-copilotcomments

Conversation

@Pavan-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

This pull request improves the robustness and reliability of telemetry and logging in the codebase. The main changes ensure that telemetry failures do not impact application behavior, and that the code gracefully handles potential SDK changes when modifying OpenTelemetry spans.

Telemetry reliability and error handling:

  • Updated track_event_if_configured in event_utils.py to wrap telemetry calls in a try/except block, logging any failures as warnings and ensuring exceptions are never propagated to callers. This makes telemetry strictly best-effort.

OpenTelemetry span processing improvements:

  • Modified the _unsample function in span_filters.py to handle potential AttributeError or TypeError exceptions when mutating the span context, logging debug information if unsampling is not possible due to SDK changes.
  • Improved matching logic in DropASGIResponseBodySpanProcessor.on_end to more accurately identify CosmosDB spans by checking for both the presence of .documents.azure.com anywhere in the span name and if the span name ends with documents.azure.com.

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

@Avijit-Microsoft Avijit-Microsoft merged commit 2692455 into dev Mar 20, 2026
7 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.19.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants