You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix FastAPI issue with APIRoute subclasses (#3681)
* fix(fastapi): issue with APIRoute subclasses
Fixes: #3671
When an APIRoute subclass would overwrite the matches method with an implementation that depended
on non-standard fields existing on the HTTP connection scope, this would cause a failure when the
OpenTelemetryMiddleware tried to get the default span details for the incoming request. This has
been fixed by using the matches implementation on the Route class for any subclass of Route. This
should be sufficient since the only information we are trying to get from that method is the path
for the request.
* test(fastapi): added tests for custom api route implementation fix
This commit adds tests that illustrate the original issue that was being
experienced for custom api route implementations when they depended on
non-standard fields existing on the ASGI HTTP connection scope. Before
the fix was implemented, the inclusion of a custom API route in the
FastAPI application would cause an exception to be raised inside the
OpenTelemetryMiddleware since the non-standard fields do not exist on
the ASGI HTTP connection scope until after the subsequent middleware
runs and adds the expected fields.
* test(fastapi): added span assertions for custom api route tests
* Update CHANGELOG.md
---------
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Copy file name to clipboardExpand all lines: instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py
0 commit comments