Skip to content

Commit

Permalink
Add support for OTEL_PROPAGATORS
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Sep 16, 2020
1 parent 751e813 commit 49b89eb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions opentelemetry-api/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
32 changes: 25 additions & 7 deletions opentelemetry-api/src/opentelemetry/propagators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions opentelemetry-api/tests/configuration/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 49b89eb

Please sign in to comment.