Skip to content

Commit 7f238c0

Browse files
committed
Switch to weakset
1 parent 9c8b280 commit 7f238c0

File tree

1 file changed

+2
-4
lines changed
  • instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette

1 file changed

+2
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
177177
from __future__ import annotations
178178

179179
from typing import TYPE_CHECKING, Any, Collection, cast
180+
from weakref import WeakSet
180181

181182
from starlette import applications
182183
from starlette.routing import Match
@@ -300,7 +301,7 @@ class _InstrumentedStarlette(applications.Starlette):
300301
_server_request_hook: ServerRequestHook = None
301302
_client_request_hook: ClientRequestHook = None
302303
_client_response_hook: ClientResponseHook = None
303-
_instrumented_starlette_apps: set[applications.Starlette] = set()
304+
_instrumented_starlette_apps: WeakSet[applications.Starlette] = WeakSet()
304305

305306
def __init__(self, *args: Any, **kwargs: Any):
306307
super().__init__(*args, **kwargs)
@@ -331,9 +332,6 @@ def __init__(self, *args: Any, **kwargs: Any):
331332
# adding apps to set for uninstrumenting
332333
_InstrumentedStarlette._instrumented_starlette_apps.add(self)
333334

334-
def __del__(self):
335-
_InstrumentedStarlette._instrumented_starlette_apps.discard(self)
336-
337335

338336
def _get_route_details(scope: dict[str, Any]) -> str | None:
339337
"""

0 commit comments

Comments
 (0)