Skip to content

fix: fix upload bug#457

Open
ShreyasW-Microsoft wants to merge 1 commit into
devfrom
psl-fix-upload-bug
Open

fix: fix upload bug#457
ShreyasW-Microsoft wants to merge 1 commit into
devfrom
psl-fix-upload-bug

Conversation

@ShreyasW-Microsoft

Copy link
Copy Markdown

Purpose

This pull request introduces a patch to improve compatibility with FastAPI >= 0.119.0 when using the OpenTelemetry FastAPI instrumentation. The main change is the addition of a workaround to prevent crashes during span-name resolution for CORS preflight OPTIONS requests, which previously caused 500 errors due to an AttributeError. The patch ensures that the telemetry instrumentation can safely handle routes that do not have a .path attribute.

Key changes:

Bug Fixes and Compatibility:

  • Added a _patch_fastapi_route_details function in patch_instrumentor.py to patch opentelemetry.instrumentation.fastapi._get_route_details, making it robust against routes without a .path attribute (such as _IncludedRouter in FastAPI >= 0.119.0), thereby preventing 500 errors on CORS preflight requests.

  • Updated patch_instrumentors() to invoke the new patch, ensuring the fix is applied during telemetry instrumentor setup.

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.

What to Check

Verify that the following are valid

  • ...

Other Information

@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report •
FileStmtsMissCoverMissing
common/telemetry
   patch_instrumentor.py534613%23–30, 52–57, 59–73, 75–78, 93–94, 97–100, 103–104, 107–110, 115
TOTAL224841181% 

Tests Skipped Failures Errors Time
282 0 💤 1 ❌ 0 🔥 10.296s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request patches the backend telemetry bootstrap to improve compatibility between FastAPI (>= 0.119.0) and opentelemetry-instrumentation-fastapi, preventing crashes during span-name resolution (notably on CORS preflight OPTIONS requests) when a route object lacks a .path attribute.

Changes:

  • Added a monkey-patch function _patch_fastapi_route_details() to replace opentelemetry.instrumentation.fastapi._get_route_details with a safer implementation.
  • Updated patch_instrumentors() to invoke the new FastAPI OpenTelemetry patch during telemetry setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +60 to +73
def _safe_get_route_details(scope: Any) -> Optional[str]:
app = scope["app"]
route = None
for starlette_route in app.routes:
try:
match, _ = starlette_route.matches(scope)
except Exception: # noqa: BLE001
continue
if match == Match.FULL:
route = getattr(starlette_route, "path", None)
break
if match == Match.PARTIAL:
route = getattr(starlette_route, "path", None)
return route
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants