fix: fix upload bug#457
Open
ShreyasW-Microsoft wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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 replaceopentelemetry.instrumentation.fastapi._get_route_detailswith 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
OPTIONSrequests, 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.pathattribute.Key changes:
Bug Fixes and Compatibility:
Added a
_patch_fastapi_route_detailsfunction inpatch_instrumentor.pyto patchopentelemetry.instrumentation.fastapi._get_route_details, making it robust against routes without a.pathattribute (such as_IncludedRouterin 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?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid
Other Information