Skip to content

Commit 16b89b1

Browse files
committed
add test verifying OTEL_PROPAGATORS env var is ignored by configure_propagator
Assisted-by: Claude Sonnet 4.6
1 parent 7f51034 commit 16b89b1

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

opentelemetry-sdk/tests/_configuration/test_propagator.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
# limitations under the License.
1414

1515
import unittest
16+
from os import environ
1617
from unittest.mock import MagicMock, patch
1718

1819
# CompositePropagator stores its propagators in _propagators (private).
1920
# We access it here to assert composition correctness.
2021
# pylint: disable=protected-access
2122
from opentelemetry.baggage.propagation import W3CBaggagePropagator
23+
from opentelemetry.environment_variables import OTEL_PROPAGATORS
2224
from opentelemetry.propagators.composite import CompositePropagator
2325
from opentelemetry.sdk._configuration._propagator import (
2426
configure_propagator,
@@ -257,3 +259,19 @@ def test_configure_propagator_with_config(self):
257259
propagator = mock_set.call_args[0][0]
258260
self.assertIsInstance(propagator, CompositePropagator)
259261
self.assertEqual(len(propagator._propagators), 1) # type: ignore[attr-defined]
262+
263+
@patch.dict(environ, {OTEL_PROPAGATORS: "baggage"})
264+
def test_otel_propagators_env_var_ignored(self):
265+
"""OTEL_PROPAGATORS env var must not influence configure_propagator output."""
266+
config = PropagatorConfig(
267+
composite=[TextMapPropagatorConfig(tracecontext={})]
268+
)
269+
with patch(
270+
"opentelemetry.sdk._configuration._propagator.set_global_textmap"
271+
) as mock_set:
272+
configure_propagator(config)
273+
propagator = mock_set.call_args[0][0]
274+
self.assertEqual(len(propagator._propagators), 1) # type: ignore[attr-defined]
275+
self.assertIsInstance(
276+
propagator._propagators[0], TraceContextTextMapPropagator # type: ignore[attr-defined]
277+
)

0 commit comments

Comments
 (0)