Skip to content

Commit c480d97

Browse files
ericapisaniclaude
andcommitted
fix(tests): Fix flaky OTel propagator entry point test
The old test used `importlib.reload(propagate)` with a patched `OTEL_PROPAGATORS` env var, which was flaky because OTel's `_importlib_metadata` module caches `entry_points()` with `@functools.cache`. Depending on when the cache was first populated, the "sentry" entry point might not be found during the reload. Replace with a direct `importlib.metadata.entry_points()` query that verifies the entry point is registered, has the correct value, and loads to `SentryPropagator`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e7262e9 commit c480d97

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import importlib
2-
import os
3-
from unittest.mock import patch
4-
5-
from opentelemetry import propagate
1+
from importlib.metadata import entry_points
62

73
from sentry_sdk.integrations.opentelemetry import SentryPropagator
84

95

10-
def test_propagator_loaded_if_mentioned_in_environment_variable():
11-
try:
12-
with patch.dict(os.environ, {"OTEL_PROPAGATORS": "sentry"}):
13-
importlib.reload(propagate)
6+
def test_propagator_registered_as_entry_point():
7+
eps = entry_points(group="opentelemetry_propagator", name="sentry")
8+
matches = list(eps)
9+
assert len(matches) == 1
10+
assert matches[0].value == "sentry_sdk.integrations.opentelemetry:SentryPropagator"
1411

15-
assert len(propagate.propagators) == 1
16-
assert isinstance(propagate.propagators[0], SentryPropagator)
17-
finally:
18-
importlib.reload(propagate)
12+
loaded = matches[0].load()
13+
assert loaded is SentryPropagator

0 commit comments

Comments
 (0)