Skip to content

Commit fccb7c1

Browse files
committed
improve instrumentation failure error message and add test
1 parent 33ad22f commit fccb7c1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ async def __call__(
334334
):
335335
# Oops, something changed about how Starlette creates middleware stacks
336336
_logger.error(
337-
"Cannot instrument FastAPI as the expected middleware stack has changed"
337+
"Skipping FastAPI instrumentation due to unexpected middleware stack: expected %s, got %s",
338+
ServerErrorMiddleware.__name__,
339+
type(inner_server_error_middleware),
338340
)
339341
return inner_server_error_middleware
340342

instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,3 +2064,7 @@ def test_no_instrumentation(self):
20642064
if record.levelno >= logging.ERROR
20652065
]
20662066
self.assertEqual(len(errors), 1)
2067+
self.assertEqual(
2068+
errors[0].getMessage(),
2069+
"Skipping FastAPI instrumentation due to unexpected middleware stack: expected ServerErrorMiddleware, got <class 'fastapi.routing.APIRouter'>",
2070+
)

0 commit comments

Comments
 (0)