Skip to content

Commit

Permalink
move textmap propagators to opentelemetry.propagators (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Mar 3, 2021
1 parent 74e2441 commit a046518
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
# Otherwise, set variable to the commit of your branch on
# opentelemetry-python-contrib which is compatible with these Core repo
# changes.
CONTRIB_REPO_SHA: 3ceaa0ec08801a8efccee328a805c038f9a7648e
CONTRIB_REPO_SHA: 16ae58b341b960df52c1cf4541695164821b3638

jobs:
build:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1656])(https://github.com/open-telemetry/opentelemetry-python/pull/1656)
- Rename `DefaultSpan` to `NonRecordingSpan`
([#1661])(https://github.com/open-telemetry/opentelemetry-python/pull/1661)
- Moving `Getter`, `Setter` and `TextMapPropagator` out of `opentelemetry.trace.propagation` and
into `opentelemetry.propagators`
([#1662])(https://github.com/open-telemetry/opentelemetry-python/pull/1662)

## [0.18b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v0.18b0) - 2021-02-16

Expand Down
14 changes: 4 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,10 @@
# with "class reference target not found: ObjectProxy".
("py:class", "ObjectProxy"),
# TODO: Understand why sphinx is not able to find this local class
("py:class", "opentelemetry.trace.propagation.textmap.TextMapPropagator",),
("py:class", "opentelemetry.trace.propagation.textmap.DictGetter",),
(
"any",
"opentelemetry.trace.propagation.textmap.TextMapPropagator.extract",
),
(
"any",
"opentelemetry.trace.propagation.textmap.TextMapPropagator.inject",
),
("py:class", "opentelemetry.propagators.textmap.TextMapPropagator",),
("py:class", "opentelemetry.propagators.textmap.DictGetter",),
("any", "opentelemetry.propagators.textmap.TextMapPropagator.extract",),
("any", "opentelemetry.propagators.textmap.TextMapPropagator.inject",),
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/auto-instrumentation/server_instrumented.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
from opentelemetry import trace
from opentelemetry.instrumentation.wsgi import collect_request_attributes
from opentelemetry.propagate import extract
from opentelemetry.propagators.textmap import DictGetter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
ConsoleSpanExporter,
SimpleSpanProcessor,
)
from opentelemetry.trace.propagation.textmap import DictGetter

app = Flask(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
from opentelemetry import baggage
from opentelemetry.context import get_current
from opentelemetry.context.context import Context
from opentelemetry.trace.propagation import textmap
from opentelemetry.propagators import textmap


class BaggagePropagator(textmap.TextMapPropagator):
"""Extracts and injects Baggage which is used to annotate telemetry.
"""
"""Extracts and injects Baggage which is used to annotate telemetry."""

MAX_HEADER_LENGTH = 8192
MAX_PAIR_LENGTH = 4096
Expand All @@ -39,7 +38,7 @@ def extract(
"""Extract Baggage from the carrier.
See
`opentelemetry.trace.propagation.textmap.TextMapPropagator.extract`
`opentelemetry.propagators.textmap.TextMapPropagator.extract`
"""

if context is None:
Expand Down Expand Up @@ -81,7 +80,7 @@ def inject(
"""Injects Baggage into the carrier.
See
`opentelemetry.trace.propagation.textmap.TextMapPropagator.inject`
`opentelemetry.propagators.textmap.TextMapPropagator.inject`
"""
baggage_entries = baggage.get_all(context=context)
if not baggage_entries:
Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-api/src/opentelemetry/propagate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def example_route():

from opentelemetry.context.context import Context
from opentelemetry.environment_variables import OTEL_PROPAGATORS
from opentelemetry.propagators import composite
from opentelemetry.trace.propagation import textmap
from opentelemetry.propagators import composite, textmap

logger = getLogger(__name__)

Expand Down
14 changes: 7 additions & 7 deletions opentelemetry-api/src/opentelemetry/propagators/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import typing

from opentelemetry.context.context import Context
from opentelemetry.trace.propagation import textmap
from opentelemetry.propagators import textmap

logger = logging.getLogger(__name__)


class CompositeHTTPPropagator(textmap.TextMapPropagator):
""" CompositeHTTPPropagator provides a mechanism for combining multiple
"""CompositeHTTPPropagator provides a mechanism for combining multiple
propagators into a single one.
Args:
Expand All @@ -39,12 +39,12 @@ def extract(
carrier: textmap.TextMapPropagatorT,
context: typing.Optional[Context] = None,
) -> Context:
""" Run each of the configured propagators with the given context and carrier.
"""Run each of the configured propagators with the given context and carrier.
Propagators are run in the order they are configured, if multiple
propagators write the same context key, the propagator later in the list
will override previous propagators.
See `opentelemetry.trace.propagation.textmap.TextMapPropagator.extract`
See `opentelemetry.propagators.textmap.TextMapPropagator.extract`
"""
for propagator in self._propagators:
context = propagator.extract(getter, carrier, context)
Expand All @@ -56,12 +56,12 @@ def inject(
carrier: textmap.TextMapPropagatorT,
context: typing.Optional[Context] = None,
) -> None:
""" Run each of the configured propagators with the given context and carrier.
"""Run each of the configured propagators with the given context and carrier.
Propagators are run in the order they are configured, if multiple
propagators write the same carrier key, the propagator later in the list
will override previous propagators.
See `opentelemetry.trace.propagation.textmap.TextMapPropagator.inject`
See `opentelemetry.propagators.textmap.TextMapPropagator.inject`
"""
for propagator in self._propagators:
propagator.inject(set_in_carrier, carrier, context)
Expand All @@ -71,7 +71,7 @@ def fields(self) -> typing.Set[str]:
"""Returns a set with the fields set in `inject`.
See
`opentelemetry.trace.propagation.textmap.TextMapPropagator.fields`
`opentelemetry.propagators.textmap.TextMapPropagator.fields`
"""
composite_fields = set()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

import opentelemetry.trace as trace
from opentelemetry.context.context import Context
from opentelemetry.trace.propagation import textmap
from opentelemetry.propagators import textmap
from opentelemetry.trace.span import TraceState


class TraceContextTextMapPropagator(textmap.TextMapPropagator):
"""Extracts and injects using w3c TraceContext's headers.
"""
"""Extracts and injects using w3c TraceContext's headers."""

_TRACEPARENT_HEADER_NAME = "traceparent"
_TRACESTATE_HEADER_NAME = "tracestate"
Expand All @@ -41,7 +40,7 @@ def extract(
) -> Context:
"""Extracts SpanContext from the carrier.
See `opentelemetry.trace.propagation.textmap.TextMapPropagator.extract`
See `opentelemetry.propagators.textmap.TextMapPropagator.extract`
"""
header = getter.get(carrier, self._TRACEPARENT_HEADER_NAME)

Expand Down Expand Up @@ -91,7 +90,7 @@ def inject(
) -> None:
"""Injects SpanContext into the carrier.
See `opentelemetry.trace.propagation.textmap.TextMapPropagator.inject`
See `opentelemetry.propagators.textmap.TextMapPropagator.inject`
"""
span = trace.get_current_span(context)
span_context = span.get_span_context()
Expand All @@ -116,6 +115,6 @@ def fields(self) -> typing.Set[str]:
"""Returns a set with the fields set in `inject`.
See
`opentelemetry.trace.propagation.textmap.TextMapPropagator.fields`
`opentelemetry.propagators.textmap.TextMapPropagator.fields`
"""
return {self._TRACEPARENT_HEADER_NAME, self._TRACESTATE_HEADER_NAME}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from opentelemetry import baggage
from opentelemetry.baggage.propagation import BaggagePropagator
from opentelemetry.context import get_current
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.propagators.textmap import DictGetter

carrier_getter = DictGetter()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from opentelemetry import baggage, trace
from opentelemetry.propagate import extract, inject
from opentelemetry.propagators.textmap import DictGetter
from opentelemetry.trace import get_current_span, set_span_in_context
from opentelemetry.trace.propagation.textmap import DictGetter

carrier_getter = DictGetter()

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/trace/propagation/test_textmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import unittest

from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.propagators.textmap import DictGetter


class TestDictGetter(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from unittest.mock import Mock, patch

from opentelemetry import trace
from opentelemetry.propagators.textmap import DictGetter
from opentelemetry.trace.propagation import tracecontext
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.trace.span import TraceState

FORMAT = tracecontext.TraceContextTextMapPropagator()
Expand Down Expand Up @@ -187,8 +187,7 @@ def test_propagate_invalid_context(self):
self.assertFalse("traceparent" in output)

def test_tracestate_empty_header(self):
"""Test tracestate with an additional empty header (should be ignored)
"""
"""Test tracestate with an additional empty header (should be ignored)"""
span = trace.get_current_span(
FORMAT.extract(
carrier_getter,
Expand All @@ -203,8 +202,7 @@ def test_tracestate_empty_header(self):
self.assertEqual(span.get_span_context().trace_state["foo"], "1")

def test_tracestate_header_with_trailing_comma(self):
"""Do not propagate invalid trace context.
"""
"""Do not propagate invalid trace context."""
span = trace.get_current_span(
FORMAT.extract(
carrier_getter,
Expand All @@ -219,8 +217,7 @@ def test_tracestate_header_with_trailing_comma(self):
self.assertEqual(span.get_span_context().trace_state["foo"], "1")

def test_tracestate_keys(self):
"""Test for valid key patterns in the tracestate
"""
"""Test for valid key patterns in the tracestate"""
tracestate_value = ",".join(
[
"1a-2f@foo=bar1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import opentelemetry.trace as trace
from opentelemetry.context import Context
from opentelemetry.trace.propagation.textmap import (
from opentelemetry.propagators.textmap import (
Getter,
Setter,
TextMapPropagator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import opentelemetry.propagators.b3 as b3_format
import opentelemetry.sdk.trace as trace
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.propagators.textmap import DictGetter

FORMAT = b3_format.B3Format()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import opentelemetry.sdk.trace.id_generator as id_generator
import opentelemetry.trace as trace_api
from opentelemetry.context import get_current
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.propagators.textmap import DictGetter

FORMAT = b3_format.B3Format()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import opentelemetry.trace as trace
from opentelemetry import baggage
from opentelemetry.context import Context, get_current
from opentelemetry.trace.propagation.textmap import (
from opentelemetry.propagators.textmap import (
Getter,
Setter,
TextMapPropagator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from opentelemetry.propagators import ( # pylint: disable=no-name-in-module
jaeger,
)
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.propagators.textmap import DictGetter

FORMAT = jaeger.JaegerPropagator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
from opentelemetry.baggage import get_baggage, set_baggage
from opentelemetry.context import Context, attach, detach, get_value, set_value
from opentelemetry.propagate import get_global_textmap
from opentelemetry.propagators.textmap import DictGetter
from opentelemetry.shim.opentracing_shim import util
from opentelemetry.shim.opentracing_shim.version import __version__
from opentelemetry.trace import INVALID_SPAN_CONTEXT, Link, NonRecordingSpan
Expand All @@ -112,7 +113,6 @@
get_current_span,
set_span_in_context,
)
from opentelemetry.trace.propagation.textmap import DictGetter
from opentelemetry.util.types import Attributes

ValueT = TypeVar("ValueT", int, float, bool, str)
Expand Down
2 changes: 1 addition & 1 deletion tests/util/src/opentelemetry/test/mock_textmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from opentelemetry import trace
from opentelemetry.context import Context, get_current
from opentelemetry.trace.propagation.textmap import (
from opentelemetry.propagators.textmap import (
Getter,
Setter,
TextMapPropagator,
Expand Down

0 comments on commit a046518

Please sign in to comment.