Skip to content

Commit c2c326e

Browse files
committed
remove confusing comment and simplify wrapper logic
1 parent 843d8c7 commit c2c326e

File tree

1 file changed

+3
-18
lines changed
  • instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi

1 file changed

+3
-18
lines changed

instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/__init__.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,6 @@ def instrument_app(
290290
schema_url=_get_schema_url(sem_conv_opt_in_mode),
291291
)
292292

293-
# In order to make traces available at any stage of the request
294-
# processing - including exception handling - we wrap ourselves as
295-
# the new, outermost middleware. However in order to prevent
296-
# exceptions from user-provided hooks of tearing through, we wrap
297-
# them to return without failure unconditionally.
298293
def build_middleware_stack(self: Starlette) -> ASGIApp:
299294
inner_server_error_middleware: ASGIApp = ( # type: ignore
300295
self._original_build_middleware_stack() # type: ignore
@@ -320,19 +315,9 @@ def build_middleware_stack(self: Starlette) -> ASGIApp:
320315
# are handled.
321316
# This should not happen unless there is a bug in OpenTelemetryMiddleware, but if there is we don't want that
322317
# to impact the user's application just because we wrapped the middlewares in this order.
323-
if isinstance(
324-
inner_server_error_middleware, ServerErrorMiddleware
325-
): # usually true
326-
outer_server_error_middleware = ServerErrorMiddleware(
327-
app=otel_middleware,
328-
)
329-
else:
330-
# Something else seems to have patched things, or maybe Starlette changed.
331-
# Just create a default ServerErrorMiddleware.
332-
outer_server_error_middleware = ServerErrorMiddleware(
333-
app=otel_middleware
334-
)
335-
return outer_server_error_middleware
318+
return ServerErrorMiddleware(
319+
app=otel_middleware,
320+
)
336321

337322
app._original_build_middleware_stack = app.build_middleware_stack
338323
app.build_middleware_stack = types.MethodType(

0 commit comments

Comments
 (0)