Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename CompositeHTTPPropagator, add deprecation notice #1807

Merged
merged 9 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Fixed OTLP gRPC exporter silently failing if scheme is not specified in endpoint.
([#1806](https://github.com/open-telemetry/opentelemetry-python/pull/1806))
- Rename CompositeHTTPPropagator to CompositePropagator as per specification.
([#1807](https://github.com/open-telemetry/opentelemetry-python/pull/1807))

### Removed
- Moved `opentelemetry-instrumentation` to contrib repository.
Expand Down
8 changes: 3 additions & 5 deletions docs/examples/datadog_exporter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from opentelemetry.exporter.datadog.propagator import DatadogFormat
from opentelemetry.propagate import get_global_textmap, set_global_textmap
from opentelemetry.propagators.composite import CompositeHTTPPropagator
from opentelemetry.propagators.composite import CompositePropagator
from opentelemetry.sdk.trace import TracerProvider

app = Flask(__name__)
Expand All @@ -38,13 +38,11 @@

# append Datadog format for propagation to and from Datadog instrumented services
global_textmap = get_global_textmap()
if isinstance(global_textmap, CompositeHTTPPropagator) and not any(
if isinstance(global_textmap, CompositePropagator) and not any(
isinstance(p, DatadogFormat) for p in global_textmap._propagators
):
set_global_textmap(
CompositeHTTPPropagator(
global_textmap._propagators + [DatadogFormat()]
)
CompositePropagator(global_textmap._propagators + [DatadogFormat()])
)
else:
set_global_textmap(DatadogFormat())
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-api/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ packages=find_namespace:
zip_safe = False
include_package_data = True
install_requires =
Deprecated >= 1.2.6
aiocontextvars; python_version<'3.7'

[options.packages.find]
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-api/src/opentelemetry/propagate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
API for propagation of context.

The propagators for the
``opentelemetry.propagators.composite.CompositeHTTPPropagator`` can be defined
``opentelemetry.propagators.composite.CompositePropagator`` can be defined
via configuration in the ``OTEL_PROPAGATORS`` environment variable. This
variable should be set to a comma-separated string of names of values for the
``opentelemetry_propagator`` entry point. For example, setting
``OTEL_PROPAGATORS`` to ``tracecontext,baggage`` (which is the default value)
would instantiate
``opentelemetry.propagators.composite.CompositeHTTPPropagator`` with 2
``opentelemetry.propagators.composite.CompositePropagator`` with 2
propagators, one of type
``opentelemetry.trace.propagation.tracecontext.TraceContextTextMapPropagator``
and other of type ``opentelemetry.baggage.propagation.W3CBaggagePropagator``.
Expand Down Expand Up @@ -142,7 +142,7 @@ def inject(
logger.exception("Failed to load configured propagators")
raise

_HTTP_TEXT_FORMAT = composite.CompositeHTTPPropagator(propagators) # type: ignore
_HTTP_TEXT_FORMAT = composite.CompositePropagator(propagators) # type: ignore


def get_global_textmap() -> textmap.TextMapPropagator:
Expand Down
12 changes: 10 additions & 2 deletions opentelemetry-api/src/opentelemetry/propagators/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
import logging
import typing

from deprecated import deprecated

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

logger = logging.getLogger(__name__)


class CompositeHTTPPropagator(textmap.TextMapPropagator):
"""CompositeHTTPPropagator provides a mechanism for combining multiple
class CompositePropagator(textmap.TextMapPropagator):
"""CompositePropagator provides a mechanism for combining multiple
propagators into a single one.

Args:
Expand Down Expand Up @@ -80,3 +82,9 @@ def fields(self) -> typing.Set[str]:
composite_fields.add(field)

return composite_fields


@deprecated(version="1.2.0", reason="You should use CompositePropagator") # type: ignore
class CompositeHTTPPropagator(CompositePropagator):
"""CompositeHTTPPropagator provides a mechanism for combining multiple
propagators into a single one.
12 changes: 6 additions & 6 deletions opentelemetry-api/tests/propagators/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import unittest
from unittest.mock import Mock

from opentelemetry.propagators.composite import CompositeHTTPPropagator
from opentelemetry.propagators.composite import CompositePropagator


def get_as_list(dict_object, key):
Expand Down Expand Up @@ -67,7 +67,7 @@ def setUpClass(cls):
)

def test_no_propagators(self):
propagator = CompositeHTTPPropagator([])
propagator = CompositePropagator([])
new_carrier = {}
propagator.inject(new_carrier)
self.assertEqual(new_carrier, {})
Expand All @@ -78,7 +78,7 @@ def test_no_propagators(self):
self.assertEqual(context, {})

def test_single_propagator(self):
propagator = CompositeHTTPPropagator([self.mock_propagator_0])
propagator = CompositePropagator([self.mock_propagator_0])

new_carrier = {}
propagator.inject(new_carrier)
Expand All @@ -90,7 +90,7 @@ def test_single_propagator(self):
self.assertEqual(context, {"mock-0": "context"})

def test_multiple_propagators(self):
propagator = CompositeHTTPPropagator(
propagator = CompositePropagator(
[self.mock_propagator_0, self.mock_propagator_1]
)

Expand All @@ -106,7 +106,7 @@ def test_multiple_propagators(self):
def test_multiple_propagators_same_key(self):
# test that when multiple propagators extract/inject the same
# key, the later propagator values are extracted/injected
propagator = CompositeHTTPPropagator(
propagator = CompositePropagator(
[self.mock_propagator_0, self.mock_propagator_2]
)

Expand All @@ -120,7 +120,7 @@ def test_multiple_propagators_same_key(self):
self.assertEqual(context, {"mock-0": "context2"})

def test_fields(self):
propagator = CompositeHTTPPropagator(
propagator = CompositePropagator(
[
self.mock_propagator_0,
self.mock_propagator_1,
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-api/tests/propagators/test_propagators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


class TestPropagators(TestCase):
@patch("opentelemetry.propagators.composite.CompositeHTTPPropagator")
@patch("opentelemetry.propagators.composite.CompositePropagator")
def test_default_composite_propagators(self, mock_compositehttppropagator):
def test_propagators(propagators):

Expand All @@ -48,7 +48,7 @@ def test_propagators(propagators):
reload(opentelemetry.propagate)

@patch.dict(environ, {OTEL_PROPAGATORS: "a,b,c"})
@patch("opentelemetry.propagators.composite.CompositeHTTPPropagator")
@patch("opentelemetry.propagators.composite.CompositePropagator")
@patch("pkg_resources.iter_entry_points")
def test_non_default_propagators(
self, mock_iter_entry_points, mock_compositehttppropagator
Expand Down