diff --git a/opentelemetry-api/setup.cfg b/opentelemetry-api/setup.cfg index 9435d92f197..4ad44c64519 100644 --- a/opentelemetry-api/setup.cfg +++ b/opentelemetry-api/setup.cfg @@ -55,6 +55,9 @@ opentelemetry_meter_provider = default_meter_provider = opentelemetry.metrics:DefaultMeterProvider opentelemetry_tracer_provider = default_tracer_provider = opentelemetry.trace:DefaultTracerProvider +opentelemetry_propagator = + tracecontext = opentelemetry.trace.propagation.tracecontext:TraceContextTextMapPropagator + baggage = opentelemetry.baggage.propagation:BaggagePropagator [options.extras_require] test = diff --git a/opentelemetry-api/src/opentelemetry/propagators/__init__.py b/opentelemetry-api/src/opentelemetry/propagators/__init__.py index f34e3c588b4..5e6d5bb2606 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagators/__init__.py @@ -54,14 +54,16 @@ def example_route(): """ import typing +from logging import getLogger -from opentelemetry.baggage.propagation import BaggagePropagator +from pkg_resources import iter_entry_points + +from opentelemetry.configuration import Configuration from opentelemetry.context.context import Context from opentelemetry.propagators import composite from opentelemetry.trace.propagation import textmap -from opentelemetry.trace.propagation.tracecontext import ( - TraceContextTextMapPropagator, -) + +logger = getLogger(__name__) def extract( @@ -104,9 +106,25 @@ def inject( get_global_textmap().inject(set_in_carrier, carrier, context) -_HTTP_TEXT_FORMAT = composite.CompositeHTTPPropagator( - [TraceContextTextMapPropagator(), BaggagePropagator()], -) # type: textmap.TextMapPropagator +try: + + propagators = [] + + for propagator in ( + Configuration().get("PROPAGATORS", "tracecontext,baggage").split(",") + ): + + propagators.append( + next( + iter_entry_points("opentelemetry_propagator", propagator) + ).load()() + ) + +except Exception: # pylint: disable=broad-except + logger.exception("Failed to load configured propagators") + raise + +_HTTP_TEXT_FORMAT = composite.CompositeHTTPPropagator(propagators) def get_global_textmap() -> textmap.TextMapPropagator: diff --git a/opentelemetry-api/tests/configuration/test_configuration.py b/opentelemetry-api/tests/configuration/test_configuration.py index 557591513b8..c699b4ca464 100644 --- a/opentelemetry-api/tests/configuration/test_configuration.py +++ b/opentelemetry-api/tests/configuration/test_configuration.py @@ -20,9 +20,10 @@ class TestConfiguration(TestCase): - def tearDown(self) -> None: - # This call resets the attributes of the Configuration class so that - # each test is executed in the same conditions. + + # These calls reset the attributes of the Configuration class so that each + # test is executed in the same conditions. + def setUp(self) -> None: Configuration._reset() def test_singleton(self) -> None: