diff --git a/CHANGELOG.md b/CHANGELOG.md index 164a02b669a..7b152c2ae73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/docs/examples/datadog_exporter/server.py b/docs/examples/datadog_exporter/server.py index 662d3ebe97c..f032887a122 100644 --- a/docs/examples/datadog_exporter/server.py +++ b/docs/examples/datadog_exporter/server.py @@ -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__) @@ -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()) diff --git a/opentelemetry-api/setup.cfg b/opentelemetry-api/setup.cfg index e712564260f..99d52838fb1 100644 --- a/opentelemetry-api/setup.cfg +++ b/opentelemetry-api/setup.cfg @@ -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] diff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py index 6c63edec3cb..7095d0eb987 100644 --- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py @@ -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``. @@ -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: diff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py index c027f638dcd..b06e385b588 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -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: @@ -80,3 +82,10 @@ 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. + """ diff --git a/opentelemetry-api/tests/propagators/test_composite.py b/opentelemetry-api/tests/propagators/test_composite.py index ef9fae2a1ac..d6bf6960cdf 100644 --- a/opentelemetry-api/tests/propagators/test_composite.py +++ b/opentelemetry-api/tests/propagators/test_composite.py @@ -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): @@ -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, {}) @@ -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) @@ -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] ) @@ -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] ) @@ -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, diff --git a/opentelemetry-api/tests/propagators/test_propagators.py b/opentelemetry-api/tests/propagators/test_propagators.py index 80299d34904..bcc01094656 100644 --- a/opentelemetry-api/tests/propagators/test_propagators.py +++ b/opentelemetry-api/tests/propagators/test_propagators.py @@ -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): @@ -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