Skip to content

Commit 4c23823

Browse files
authored
fix check of is_otel_instrumented (#1313)
1 parent ff9651e commit 4c23823

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
([#1208](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1208))
2222
- `opentelemetry-instrumentation-aiohttp-client` Fix producing additional spans with each newly created ClientSession
2323
- ([#1246](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1246))
24+
- Add _is_openetlemetry_instrumented check in _InstrumentedFastAPI class
25+
([#1313](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1313))
2426

2527
## [1.12.0-0.33b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.12.0-0.33b0) - 2022-08-08
2628

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

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def __init__(self, *args, **kwargs):
247247
client_response_hook=_InstrumentedFastAPI._client_response_hook,
248248
tracer_provider=_InstrumentedFastAPI._tracer_provider,
249249
)
250+
self._is_instrumented_by_opentelemetry = True
250251

251252

252253
def _get_route_details(scope):

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

+8
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ def test_request(self):
274274
self.assertEqual(span.resource.attributes["key1"], "value1")
275275
self.assertEqual(span.resource.attributes["key2"], "value2")
276276

277+
def test_mulitple_way_instrumentation(self):
278+
self._instrumentor.instrument_app(self._app)
279+
count = 0
280+
for middleware in self._app.user_middleware:
281+
if middleware.cls is OpenTelemetryMiddleware:
282+
count += 1
283+
self.assertEqual(count, 1)
284+
277285
def tearDown(self):
278286
self._instrumentor.uninstrument()
279287
super().tearDown()

0 commit comments

Comments
 (0)