From 09d24782e03d8d43e5b1aaf3f571b0b5c78ff089 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 3 May 2021 12:57:44 -0700 Subject: [PATCH 1/6] rename CompositeHTTPPropagator, add deprecation notice --- docs/examples/datadog_exporter/server.py | 8 +++----- opentelemetry-api/setup.cfg | 1 + .../src/opentelemetry/propagate/__init__.py | 6 +++--- .../src/opentelemetry/propagators/composite.py | 10 ++++++++-- .../tests/propagators/test_composite.py | 12 ++++++------ .../tests/propagators/test_propagators.py | 4 ++-- 6 files changed, 23 insertions(+), 18 deletions(-) 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..f2c7b052889 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -13,6 +13,7 @@ # limitations under the License. import logging import typing +from deprecated import deprecated from opentelemetry.context.context import Context from opentelemetry.propagators import textmap @@ -20,8 +21,8 @@ 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 +81,8 @@ def fields(self) -> typing.Set[str]: composite_fields.add(field) return composite_fields + + +@deprecated(version="1.2.0", reason="You should use CompositePropagator") +class CompositeHTTPPropagator(CompositePropagator): + """Alias for CompositePropagator""" 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 From 070b37c6e40bd892e104922fd1b915a0900a456f Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 3 May 2021 13:17:13 -0700 Subject: [PATCH 2/6] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae8eb424a67..d82b03ed021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added example for running Django with auto instrumentation ([#1803](https://github.com/open-telemetry/opentelemetry-python/pull/1803)) +### Changed +- Rename CompositeHTTPPropagator to CompositePropagator as per specification. + ([#1807](https://github.com/open-telemetry/opentelemetry-python/pull/1807)) + ### Removed - Moved `opentelemetry-instrumentation` to contrib repository ([#1797](https://github.com/open-telemetry/opentelemetry-python/pull/1797)) From 3d36fd38aec7a9d7fb57b1b57af7c466bedce337 Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 3 May 2021 13:23:44 -0700 Subject: [PATCH 3/6] fix lint --- opentelemetry-api/src/opentelemetry/propagators/composite.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py index f2c7b052889..ff3adeab885 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -13,6 +13,7 @@ # limitations under the License. import logging import typing + from deprecated import deprecated from opentelemetry.context.context import Context From e364aa9c3e81b0f96dd29872f427e6b740ef381f Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 3 May 2021 14:28:07 -0700 Subject: [PATCH 4/6] fix mypy --- opentelemetry-api/src/opentelemetry/propagators/composite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py index ff3adeab885..b83dde8628a 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -84,6 +84,6 @@ def fields(self) -> typing.Set[str]: return composite_fields -@deprecated(version="1.2.0", reason="You should use CompositePropagator") +@deprecated(version="1.2.0", reason="You should use CompositePropagator") # type: ignore class CompositeHTTPPropagator(CompositePropagator): """Alias for CompositePropagator""" From 230fe317e87de1d513ad9d9ed066857893bd1c96 Mon Sep 17 00:00:00 2001 From: alrex Date: Fri, 7 May 2021 13:26:54 -0700 Subject: [PATCH 5/6] Update opentelemetry-api/src/opentelemetry/propagators/composite.py Co-authored-by: Diego Hurtado --- opentelemetry-api/src/opentelemetry/propagators/composite.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py index b83dde8628a..651ca051ed2 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -86,4 +86,5 @@ def fields(self) -> typing.Set[str]: @deprecated(version="1.2.0", reason="You should use CompositePropagator") # type: ignore class CompositeHTTPPropagator(CompositePropagator): - """Alias for CompositePropagator""" + """CompositeHTTPPropagator provides a mechanism for combining multiple + propagators into a single one. From 50b506f3e8b4b6a1588d9099dd2bed5bfc8834f9 Mon Sep 17 00:00:00 2001 From: alrex Date: Fri, 7 May 2021 13:52:59 -0700 Subject: [PATCH 6/6] Update composite.py --- opentelemetry-api/src/opentelemetry/propagators/composite.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py index 651ca051ed2..b06e385b588 100644 --- a/opentelemetry-api/src/opentelemetry/propagators/composite.py +++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py @@ -88,3 +88,4 @@ def fields(self) -> typing.Set[str]: class CompositeHTTPPropagator(CompositePropagator): """CompositeHTTPPropagator provides a mechanism for combining multiple propagators into a single one. + """