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 2c3f4e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 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 =
31 changes: 24 additions & 7 deletions opentelemetry-api/src/opentelemetry/propagators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ def example_route():
https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-propagators.md
"""

from pkg_resources import iter_entry_points
from logging import getLogger
import typing

from opentelemetry.baggage.propagation import BaggagePropagator
from opentelemetry.context.context import Context
from opentelemetry.propagators import composite
from opentelemetry.trace.propagation import textmap
from opentelemetry.trace.propagation.tracecontext import (
TraceContextTextMapPropagator,
)
from opentelemetry.configuration import Configuration

logger = getLogger(__name__)


def extract(
Expand Down Expand Up @@ -104,9 +105,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

0 comments on commit 2c3f4e2

Please sign in to comment.