We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Rename CompositeHTTPPropagator
[`CompositeHTTPPropagator`](https://github.com/open-telemetry/opentelemetry-python/blob/b73d8009904fc1693b2ba3a1e0656af376f859cf/opentelemetry-api/src/opentelemetry/propagators/composite.py#L23) has nothing to do with HTTP so this name is confusing. It should be renamed to probably just `CompositePropagator`, but we need to keep an alias of the old name for backward compatibility.

[Relevant section of spec](https://github.com/open-telemetry/opentelemetry-python/blob/b73d8009904fc1693b2ba3a1e0656af376f859cf/opentelemetry-api/src/opentelemetry/propagators/composite.py#L23)



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `docs/examples/datadog_exporter/server.py`
Content:
```
1 # Copyright The OpenTelemetry Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from flask import Flask, request
16 
17 from opentelemetry import trace
18 from opentelemetry.exporter.datadog import (
19     DatadogExportSpanProcessor,
20     DatadogSpanExporter,
21 )
22 from opentelemetry.exporter.datadog.propagator import DatadogFormat
23 from opentelemetry.propagate import get_global_textmap, set_global_textmap
24 from opentelemetry.propagators.composite import CompositeHTTPPropagator
25 from opentelemetry.sdk.trace import TracerProvider
26 
27 app = Flask(__name__)
28 
29 trace.set_tracer_provider(TracerProvider())
30 
31 trace.get_tracer_provider().add_span_processor(
32     DatadogExportSpanProcessor(
33         DatadogSpanExporter(
34             agent_url="http://localhost:8126", service="example-server"
35         )
36     )
37 )
38 
39 # append Datadog format for propagation to and from Datadog instrumented services
40 global_textmap = get_global_textmap()
41 if isinstance(global_textmap, CompositeHTTPPropagator) and not any(
42     isinstance(p, DatadogFormat) for p in global_textmap._propagators
43 ):
44     set_global_textmap(
45         CompositeHTTPPropagator(
46             global_textmap._propagators + [DatadogFormat()]
47         )
48     )
49 else:
50     set_global_textmap(DatadogFormat())
51 
52 tracer = trace.get_tracer(__name__)
53 
54 
55 @app.route("/server_request")
56 def server_request():
57     param = request.args.get("param")
58     with tracer.start_as_current_span("server-inner"):
59         if param == "error":
60             raise ValueError("forced server error")
61         return "served: {}".format(param)
62 
63 
64 if __name__ == "__main__":
65     app.run(port=8082)
66
```

Path: `opentelemetry-api/src/opentelemetry/propagate/__init__.py`
Content:
```
1 # Copyright The OpenTelemetry Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """
16 API for propagation of context.
17 
18 The propagators for the
19 ``opentelemetry.propagators.composite.CompositeHTTPPropagator`` can be defined
20 via configuration in the ``OTEL_PROPAGATORS`` environment variable. This
21 variable should be set to a comma-separated string of names of values for the
22 ``opentelemetry_propagator`` entry point. For example, setting
23 ``OTEL_PROPAGATORS`` to ``tracecontext,baggage`` (which is the default value)
24 would instantiate
25 ``opentelemetry.propagators.composite.CompositeHTTPPropagator`` with 2
26 propagators, one of type
27 ``opentelemetry.trace.propagation.tracecontext.TraceContextTextMapPropagator``
28 and other of type ``opentelemetry.baggage.propagation.W3CBaggagePropagator``.
29 Notice that these propagator classes are defined as
30 ``opentelemetry_propagator`` entry points in the ``setup.cfg`` file of
31 ``opentelemetry``.
32 
33 Example::
34 
35     import flask
36     import requests
37     from opentelemetry import propagators
38 
39 
40     PROPAGATOR = propagators.get_global_textmap()
41 
42 
43     def get_header_from_flask_request(request, key):
44         return request.headers.get_all(key)
45 
46     def set_header_into_requests_request(request: requests.Request,
47                                             key: str, value: str):
48         request.headers[key] = value
49 
50     def example_route():
51         context = PROPAGATOR.extract(
52             get_header_from_flask_request,
53             flask.request
54         )
55         request_to_downstream = requests.Request(
56             "GET", "http://httpbin.org/get"
57         )
58         PROPAGATOR.inject(
59             set_header_into_requests_request,
60             request_to_downstream,
61             context=context
62         )
63         session = requests.Session()
64         session.send(request_to_downstream.prepare())
65 
66 
67 .. _Propagation API Specification:
68     https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md
69 """
70 
71 import typing
72 from logging import getLogger
73 from os import environ
74 
75 from pkg_resources import iter_entry_points
76 
77 from opentelemetry.context.context import Context
78 from opentelemetry.environment_variables import OTEL_PROPAGATORS
79 from opentelemetry.propagators import composite, textmap
80 
81 logger = getLogger(__name__)
82 
83 
84 def extract(
85     carrier: textmap.CarrierT,
86     context: typing.Optional[Context] = None,
87     getter: textmap.Getter = textmap.default_getter,
88 ) -> Context:
89     """Uses the configured propagator to extract a Context from the carrier.
90 
91     Args:
92         getter: an object which contains a get function that can retrieve zero
93             or more values from the carrier and a keys function that can get all the keys
94             from carrier.
95         carrier: and object which contains values that are
96             used to construct a Context. This object
97             must be paired with an appropriate getter
98             which understands how to extract a value from it.
99         context: an optional Context to use. Defaults to current
100             context if not set.
101     """
102     return get_global_textmap().extract(carrier, context, getter=getter)
103 
104 
105 def inject(
106     carrier: textmap.CarrierT,
107     context: typing.Optional[Context] = None,
108     setter: textmap.Setter = textmap.default_setter,
109 ) -> None:
110     """Uses the configured propagator to inject a Context into the carrier.
111 
112     Args:
113         carrier: An object that contains a representation of HTTP
114             headers. Should be paired with setter, which
115             should know how to set header values on the carrier.
116         context: An optional Context to use. Defaults to current
117             context if not set.
118         setter: An optional `Setter` object that can set values
119             on the carrier.
120     """
121     get_global_textmap().inject(carrier, context=context, setter=setter)
122 
123 
124 try:
125 
126     propagators = []
127 
128     # Single use variable here to hack black and make lint pass
129     environ_propagators = environ.get(
130         OTEL_PROPAGATORS,
131         "tracecontext,baggage",
132     )
133 
134     for propagator in environ_propagators.split(","):
135         propagators.append(  # type: ignore
136             next(  # type: ignore
137                 iter_entry_points("opentelemetry_propagator", propagator)
138             ).load()()
139         )
140 
141 except Exception:  # pylint: disable=broad-except
142     logger.exception("Failed to load configured propagators")
143     raise
144 
145 _HTTP_TEXT_FORMAT = composite.CompositeHTTPPropagator(propagators)  # type: ignore
146 
147 
148 def get_global_textmap() -> textmap.TextMapPropagator:
149     return _HTTP_TEXT_FORMAT
150 
151 
152 def set_global_textmap(
153     http_text_format: textmap.TextMapPropagator,
154 ) -> None:
155     global _HTTP_TEXT_FORMAT  # pylint:disable=global-statement
156     _HTTP_TEXT_FORMAT = http_text_format  # type: ignore
157
```

Path: `opentelemetry-api/src/opentelemetry/propagators/composite.py`
Content:
```
1 # Copyright The OpenTelemetry Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 import logging
15 import typing
16 
17 from opentelemetry.context.context import Context
18 from opentelemetry.propagators import textmap
19 
20 logger = logging.getLogger(__name__)
21 
22 
23 class CompositeHTTPPropagator(textmap.TextMapPropagator):
24     """CompositeHTTPPropagator provides a mechanism for combining multiple
25     propagators into a single one.
26 
27     Args:
28         propagators: the list of propagators to use
29     """
30 
31     def __init__(
32         self, propagators: typing.Sequence[textmap.TextMapPropagator]
33     ) -> None:
34         self._propagators = propagators
35 
36     def extract(
37         self,
38         carrier: textmap.CarrierT,
39         context: typing.Optional[Context] = None,
40         getter: textmap.Getter = textmap.default_getter,
41     ) -> Context:
42         """Run each of the configured propagators with the given context and carrier.
43         Propagators are run in the order they are configured, if multiple
44         propagators write the same context key, the propagator later in the list
45         will override previous propagators.
46 
47         See `opentelemetry.propagators.textmap.TextMapPropagator.extract`
48         """
49         for propagator in self._propagators:
50             context = propagator.extract(carrier, context, getter=getter)
51         return context  # type: ignore
52 
53     def inject(
54         self,
55         carrier: textmap.CarrierT,
56         context: typing.Optional[Context] = None,
57         setter: textmap.Setter = textmap.default_setter,
58     ) -> None:
59         """Run each of the configured propagators with the given context and carrier.
60         Propagators are run in the order they are configured, if multiple
61         propagators write the same carrier key, the propagator later in the list
62         will override previous propagators.
63 
64         See `opentelemetry.propagators.textmap.TextMapPropagator.inject`
65         """
66         for propagator in self._propagators:
67             propagator.inject(carrier, context, setter=setter)
68 
69     @property
70     def fields(self) -> typing.Set[str]:
71         """Returns a set with the fields set in `inject`.
72 
73         See
74         `opentelemetry.propagators.textmap.TextMapPropagator.fields`
75         """
76         composite_fields = set()
77 
78         for propagator in self._propagators:
79             for field in propagator.fields:
80                 composite_fields.add(field)
81 
82         return composite_fields
83
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/docs/examples/datadog_exporter/server.py b/docs/examples/datadog_exporter/server.py
--- 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/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py
--- 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 @@
     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
--- 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 @@
                 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.
+    """

{"golden_diff": "diff --git a/docs/examples/datadog_exporter/server.py b/docs/examples/datadog_exporter/server.py\n--- a/docs/examples/datadog_exporter/server.py\n+++ b/docs/examples/datadog_exporter/server.py\n@@ -21,7 +21,7 @@\n )\n from opentelemetry.exporter.datadog.propagator import DatadogFormat\n from opentelemetry.propagate import get_global_textmap, set_global_textmap\n-from opentelemetry.propagators.composite import CompositeHTTPPropagator\n+from opentelemetry.propagators.composite import CompositePropagator\n from opentelemetry.sdk.trace import TracerProvider\n \n app = Flask(__name__)\n@@ -38,13 +38,11 @@\n \n # append Datadog format for propagation to and from Datadog instrumented services\n global_textmap = get_global_textmap()\n-if isinstance(global_textmap, CompositeHTTPPropagator) and not any(\n+if isinstance(global_textmap, CompositePropagator) and not any(\n     isinstance(p, DatadogFormat) for p in global_textmap._propagators\n ):\n     set_global_textmap(\n-        CompositeHTTPPropagator(\n-            global_textmap._propagators + [DatadogFormat()]\n-        )\n+        CompositePropagator(global_textmap._propagators + [DatadogFormat()])\n     )\n else:\n     set_global_textmap(DatadogFormat())\ndiff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py\n--- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py\n+++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py\n@@ -16,13 +16,13 @@\n API for propagation of context.\n \n The propagators for the\n-``opentelemetry.propagators.composite.CompositeHTTPPropagator`` can be defined\n+``opentelemetry.propagators.composite.CompositePropagator`` can be defined\n via configuration in the ``OTEL_PROPAGATORS`` environment variable. This\n variable should be set to a comma-separated string of names of values for the\n ``opentelemetry_propagator`` entry point. For example, setting\n ``OTEL_PROPAGATORS`` to ``tracecontext,baggage`` (which is the default value)\n would instantiate\n-``opentelemetry.propagators.composite.CompositeHTTPPropagator`` with 2\n+``opentelemetry.propagators.composite.CompositePropagator`` with 2\n propagators, one of type\n ``opentelemetry.trace.propagation.tracecontext.TraceContextTextMapPropagator``\n and other of type ``opentelemetry.baggage.propagation.W3CBaggagePropagator``.\n@@ -142,7 +142,7 @@\n     logger.exception(\"Failed to load configured propagators\")\n     raise\n \n-_HTTP_TEXT_FORMAT = composite.CompositeHTTPPropagator(propagators)  # type: ignore\n+_HTTP_TEXT_FORMAT = composite.CompositePropagator(propagators)  # type: ignore\n \n \n def get_global_textmap() -> textmap.TextMapPropagator:\ndiff --git a/opentelemetry-api/src/opentelemetry/propagators/composite.py b/opentelemetry-api/src/opentelemetry/propagators/composite.py\n--- a/opentelemetry-api/src/opentelemetry/propagators/composite.py\n+++ b/opentelemetry-api/src/opentelemetry/propagators/composite.py\n@@ -14,14 +14,16 @@\n import logging\n import typing\n \n+from deprecated import deprecated\n+\n from opentelemetry.context.context import Context\n from opentelemetry.propagators import textmap\n \n logger = logging.getLogger(__name__)\n \n \n-class CompositeHTTPPropagator(textmap.TextMapPropagator):\n-    \"\"\"CompositeHTTPPropagator provides a mechanism for combining multiple\n+class CompositePropagator(textmap.TextMapPropagator):\n+    \"\"\"CompositePropagator provides a mechanism for combining multiple\n     propagators into a single one.\n \n     Args:\n@@ -80,3 +82,10 @@\n                 composite_fields.add(field)\n \n         return composite_fields\n+\n+\n+@deprecated(version=\"1.2.0\", reason=\"You should use CompositePropagator\")  # type: ignore\n+class CompositeHTTPPropagator(CompositePropagator):\n+    \"\"\"CompositeHTTPPropagator provides a mechanism for combining multiple\n+    propagators into a single one.\n+    \"\"\"\n", "issue": "Rename CompositeHTTPPropagator\n[`CompositeHTTPPropagator`](https://github.com/open-telemetry/opentelemetry-python/blob/b73d8009904fc1693b2ba3a1e0656af376f859cf/opentelemetry-api/src/opentelemetry/propagators/composite.py#L23) has nothing to do with HTTP so this name is confusing. It should be renamed to probably just `CompositePropagator`, but we need to keep an alias of the old name for backward compatibility.\r\n\r\n[Relevant section of spec](https://github.com/open-telemetry/opentelemetry-python/blob/b73d8009904fc1693b2ba3a1e0656af376f859cf/opentelemetry-api/src/opentelemetry/propagators/composite.py#L23)\r\n\r\n\n", "before_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom flask import Flask, request\n\nfrom opentelemetry import trace\nfrom opentelemetry.exporter.datadog import (\n    DatadogExportSpanProcessor,\n    DatadogSpanExporter,\n)\nfrom opentelemetry.exporter.datadog.propagator import DatadogFormat\nfrom opentelemetry.propagate import get_global_textmap, set_global_textmap\nfrom opentelemetry.propagators.composite import CompositeHTTPPropagator\nfrom opentelemetry.sdk.trace import TracerProvider\n\napp = Flask(__name__)\n\ntrace.set_tracer_provider(TracerProvider())\n\ntrace.get_tracer_provider().add_span_processor(\n    DatadogExportSpanProcessor(\n        DatadogSpanExporter(\n            agent_url=\"http://localhost:8126\", service=\"example-server\"\n        )\n    )\n)\n\n# append Datadog format for propagation to and from Datadog instrumented services\nglobal_textmap = get_global_textmap()\nif isinstance(global_textmap, CompositeHTTPPropagator) and not any(\n    isinstance(p, DatadogFormat) for p in global_textmap._propagators\n):\n    set_global_textmap(\n        CompositeHTTPPropagator(\n            global_textmap._propagators + [DatadogFormat()]\n        )\n    )\nelse:\n    set_global_textmap(DatadogFormat())\n\ntracer = trace.get_tracer(__name__)\n\n\n@app.route(\"/server_request\")\ndef server_request():\n    param = request.args.get(\"param\")\n    with tracer.start_as_current_span(\"server-inner\"):\n        if param == \"error\":\n            raise ValueError(\"forced server error\")\n        return \"served: {}\".format(param)\n\n\nif __name__ == \"__main__\":\n    app.run(port=8082)\n", "path": "docs/examples/datadog_exporter/server.py"}, {"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nAPI for propagation of context.\n\nThe propagators for the\n``opentelemetry.propagators.composite.CompositeHTTPPropagator`` can be defined\nvia configuration in the ``OTEL_PROPAGATORS`` environment variable. This\nvariable should be set to a comma-separated string of names of values for the\n``opentelemetry_propagator`` entry point. For example, setting\n``OTEL_PROPAGATORS`` to ``tracecontext,baggage`` (which is the default value)\nwould instantiate\n``opentelemetry.propagators.composite.CompositeHTTPPropagator`` with 2\npropagators, one of type\n``opentelemetry.trace.propagation.tracecontext.TraceContextTextMapPropagator``\nand other of type ``opentelemetry.baggage.propagation.W3CBaggagePropagator``.\nNotice that these propagator classes are defined as\n``opentelemetry_propagator`` entry points in the ``setup.cfg`` file of\n``opentelemetry``.\n\nExample::\n\n    import flask\n    import requests\n    from opentelemetry import propagators\n\n\n    PROPAGATOR = propagators.get_global_textmap()\n\n\n    def get_header_from_flask_request(request, key):\n        return request.headers.get_all(key)\n\n    def set_header_into_requests_request(request: requests.Request,\n                                            key: str, value: str):\n        request.headers[key] = value\n\n    def example_route():\n        context = PROPAGATOR.extract(\n            get_header_from_flask_request,\n            flask.request\n        )\n        request_to_downstream = requests.Request(\n            \"GET\", \"http://httpbin.org/get\"\n        )\n        PROPAGATOR.inject(\n            set_header_into_requests_request,\n            request_to_downstream,\n            context=context\n        )\n        session = requests.Session()\n        session.send(request_to_downstream.prepare())\n\n\n.. _Propagation API Specification:\n    https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md\n\"\"\"\n\nimport typing\nfrom logging import getLogger\nfrom os import environ\n\nfrom pkg_resources import iter_entry_points\n\nfrom opentelemetry.context.context import Context\nfrom opentelemetry.environment_variables import OTEL_PROPAGATORS\nfrom opentelemetry.propagators import composite, textmap\n\nlogger = getLogger(__name__)\n\n\ndef extract(\n    carrier: textmap.CarrierT,\n    context: typing.Optional[Context] = None,\n    getter: textmap.Getter = textmap.default_getter,\n) -> Context:\n    \"\"\"Uses the configured propagator to extract a Context from the carrier.\n\n    Args:\n        getter: an object which contains a get function that can retrieve zero\n            or more values from the carrier and a keys function that can get all the keys\n            from carrier.\n        carrier: and object which contains values that are\n            used to construct a Context. This object\n            must be paired with an appropriate getter\n            which understands how to extract a value from it.\n        context: an optional Context to use. Defaults to current\n            context if not set.\n    \"\"\"\n    return get_global_textmap().extract(carrier, context, getter=getter)\n\n\ndef inject(\n    carrier: textmap.CarrierT,\n    context: typing.Optional[Context] = None,\n    setter: textmap.Setter = textmap.default_setter,\n) -> None:\n    \"\"\"Uses the configured propagator to inject a Context into the carrier.\n\n    Args:\n        carrier: An object that contains a representation of HTTP\n            headers. Should be paired with setter, which\n            should know how to set header values on the carrier.\n        context: An optional Context to use. Defaults to current\n            context if not set.\n        setter: An optional `Setter` object that can set values\n            on the carrier.\n    \"\"\"\n    get_global_textmap().inject(carrier, context=context, setter=setter)\n\n\ntry:\n\n    propagators = []\n\n    # Single use variable here to hack black and make lint pass\n    environ_propagators = environ.get(\n        OTEL_PROPAGATORS,\n        \"tracecontext,baggage\",\n    )\n\n    for propagator in environ_propagators.split(\",\"):\n        propagators.append(  # type: ignore\n            next(  # type: ignore\n                iter_entry_points(\"opentelemetry_propagator\", propagator)\n            ).load()()\n        )\n\nexcept Exception:  # pylint: disable=broad-except\n    logger.exception(\"Failed to load configured propagators\")\n    raise\n\n_HTTP_TEXT_FORMAT = composite.CompositeHTTPPropagator(propagators)  # type: ignore\n\n\ndef get_global_textmap() -> textmap.TextMapPropagator:\n    return _HTTP_TEXT_FORMAT\n\n\ndef set_global_textmap(\n    http_text_format: textmap.TextMapPropagator,\n) -> None:\n    global _HTTP_TEXT_FORMAT  # pylint:disable=global-statement\n    _HTTP_TEXT_FORMAT = http_text_format  # type: ignore\n", "path": "opentelemetry-api/src/opentelemetry/propagate/__init__.py"}, {"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport logging\nimport typing\n\nfrom opentelemetry.context.context import Context\nfrom opentelemetry.propagators import textmap\n\nlogger = logging.getLogger(__name__)\n\n\nclass CompositeHTTPPropagator(textmap.TextMapPropagator):\n    \"\"\"CompositeHTTPPropagator provides a mechanism for combining multiple\n    propagators into a single one.\n\n    Args:\n        propagators: the list of propagators to use\n    \"\"\"\n\n    def __init__(\n        self, propagators: typing.Sequence[textmap.TextMapPropagator]\n    ) -> None:\n        self._propagators = propagators\n\n    def extract(\n        self,\n        carrier: textmap.CarrierT,\n        context: typing.Optional[Context] = None,\n        getter: textmap.Getter = textmap.default_getter,\n    ) -> Context:\n        \"\"\"Run each of the configured propagators with the given context and carrier.\n        Propagators are run in the order they are configured, if multiple\n        propagators write the same context key, the propagator later in the list\n        will override previous propagators.\n\n        See `opentelemetry.propagators.textmap.TextMapPropagator.extract`\n        \"\"\"\n        for propagator in self._propagators:\n            context = propagator.extract(carrier, context, getter=getter)\n        return context  # type: ignore\n\n    def inject(\n        self,\n        carrier: textmap.CarrierT,\n        context: typing.Optional[Context] = None,\n        setter: textmap.Setter = textmap.default_setter,\n    ) -> None:\n        \"\"\"Run each of the configured propagators with the given context and carrier.\n        Propagators are run in the order they are configured, if multiple\n        propagators write the same carrier key, the propagator later in the list\n        will override previous propagators.\n\n        See `opentelemetry.propagators.textmap.TextMapPropagator.inject`\n        \"\"\"\n        for propagator in self._propagators:\n            propagator.inject(carrier, context, setter=setter)\n\n    @property\n    def fields(self) -> typing.Set[str]:\n        \"\"\"Returns a set with the fields set in `inject`.\n\n        See\n        `opentelemetry.propagators.textmap.TextMapPropagator.fields`\n        \"\"\"\n        composite_fields = set()\n\n        for propagator in self._propagators:\n            for field in propagator.fields:\n                composite_fields.add(field)\n\n        return composite_fields\n", "path": "opentelemetry-api/src/opentelemetry/propagators/composite.py"}], "after_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom flask import Flask, request\n\nfrom opentelemetry import trace\nfrom opentelemetry.exporter.datadog import (\n    DatadogExportSpanProcessor,\n    DatadogSpanExporter,\n)\nfrom opentelemetry.exporter.datadog.propagator import DatadogFormat\nfrom opentelemetry.propagate import get_global_textmap, set_global_textmap\nfrom opentelemetry.propagators.composite import CompositePropagator\nfrom opentelemetry.sdk.trace import TracerProvider\n\napp = Flask(__name__)\n\ntrace.set_tracer_provider(TracerProvider())\n\ntrace.get_tracer_provider().add_span_processor(\n    DatadogExportSpanProcessor(\n        DatadogSpanExporter(\n            agent_url=\"http://localhost:8126\", service=\"example-server\"\n        )\n    )\n)\n\n# append Datadog format for propagation to and from Datadog instrumented services\nglobal_textmap = get_global_textmap()\nif isinstance(global_textmap, CompositePropagator) and not any(\n    isinstance(p, DatadogFormat) for p in global_textmap._propagators\n):\n    set_global_textmap(\n        CompositePropagator(global_textmap._propagators + [DatadogFormat()])\n    )\nelse:\n    set_global_textmap(DatadogFormat())\n\ntracer = trace.get_tracer(__name__)\n\n\n@app.route(\"/server_request\")\ndef server_request():\n    param = request.args.get(\"param\")\n    with tracer.start_as_current_span(\"server-inner\"):\n        if param == \"error\":\n            raise ValueError(\"forced server error\")\n        return \"served: {}\".format(param)\n\n\nif __name__ == \"__main__\":\n    app.run(port=8082)\n", "path": "docs/examples/datadog_exporter/server.py"}, {"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nAPI for propagation of context.\n\nThe propagators for the\n``opentelemetry.propagators.composite.CompositePropagator`` can be defined\nvia configuration in the ``OTEL_PROPAGATORS`` environment variable. This\nvariable should be set to a comma-separated string of names of values for the\n``opentelemetry_propagator`` entry point. For example, setting\n``OTEL_PROPAGATORS`` to ``tracecontext,baggage`` (which is the default value)\nwould instantiate\n``opentelemetry.propagators.composite.CompositePropagator`` with 2\npropagators, one of type\n``opentelemetry.trace.propagation.tracecontext.TraceContextTextMapPropagator``\nand other of type ``opentelemetry.baggage.propagation.W3CBaggagePropagator``.\nNotice that these propagator classes are defined as\n``opentelemetry_propagator`` entry points in the ``setup.cfg`` file of\n``opentelemetry``.\n\nExample::\n\n    import flask\n    import requests\n    from opentelemetry import propagators\n\n\n    PROPAGATOR = propagators.get_global_textmap()\n\n\n    def get_header_from_flask_request(request, key):\n        return request.headers.get_all(key)\n\n    def set_header_into_requests_request(request: requests.Request,\n                                            key: str, value: str):\n        request.headers[key] = value\n\n    def example_route():\n        context = PROPAGATOR.extract(\n            get_header_from_flask_request,\n            flask.request\n        )\n        request_to_downstream = requests.Request(\n            \"GET\", \"http://httpbin.org/get\"\n        )\n        PROPAGATOR.inject(\n            set_header_into_requests_request,\n            request_to_downstream,\n            context=context\n        )\n        session = requests.Session()\n        session.send(request_to_downstream.prepare())\n\n\n.. _Propagation API Specification:\n    https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md\n\"\"\"\n\nimport typing\nfrom logging import getLogger\nfrom os import environ\n\nfrom pkg_resources import iter_entry_points\n\nfrom opentelemetry.context.context import Context\nfrom opentelemetry.environment_variables import OTEL_PROPAGATORS\nfrom opentelemetry.propagators import composite, textmap\n\nlogger = getLogger(__name__)\n\n\ndef extract(\n    carrier: textmap.CarrierT,\n    context: typing.Optional[Context] = None,\n    getter: textmap.Getter = textmap.default_getter,\n) -> Context:\n    \"\"\"Uses the configured propagator to extract a Context from the carrier.\n\n    Args:\n        getter: an object which contains a get function that can retrieve zero\n            or more values from the carrier and a keys function that can get all the keys\n            from carrier.\n        carrier: and object which contains values that are\n            used to construct a Context. This object\n            must be paired with an appropriate getter\n            which understands how to extract a value from it.\n        context: an optional Context to use. Defaults to current\n            context if not set.\n    \"\"\"\n    return get_global_textmap().extract(carrier, context, getter=getter)\n\n\ndef inject(\n    carrier: textmap.CarrierT,\n    context: typing.Optional[Context] = None,\n    setter: textmap.Setter = textmap.default_setter,\n) -> None:\n    \"\"\"Uses the configured propagator to inject a Context into the carrier.\n\n    Args:\n        carrier: An object that contains a representation of HTTP\n            headers. Should be paired with setter, which\n            should know how to set header values on the carrier.\n        context: An optional Context to use. Defaults to current\n            context if not set.\n        setter: An optional `Setter` object that can set values\n            on the carrier.\n    \"\"\"\n    get_global_textmap().inject(carrier, context=context, setter=setter)\n\n\ntry:\n\n    propagators = []\n\n    # Single use variable here to hack black and make lint pass\n    environ_propagators = environ.get(\n        OTEL_PROPAGATORS,\n        \"tracecontext,baggage\",\n    )\n\n    for propagator in environ_propagators.split(\",\"):\n        propagators.append(  # type: ignore\n            next(  # type: ignore\n                iter_entry_points(\"opentelemetry_propagator\", propagator)\n            ).load()()\n        )\n\nexcept Exception:  # pylint: disable=broad-except\n    logger.exception(\"Failed to load configured propagators\")\n    raise\n\n_HTTP_TEXT_FORMAT = composite.CompositePropagator(propagators)  # type: ignore\n\n\ndef get_global_textmap() -> textmap.TextMapPropagator:\n    return _HTTP_TEXT_FORMAT\n\n\ndef set_global_textmap(\n    http_text_format: textmap.TextMapPropagator,\n) -> None:\n    global _HTTP_TEXT_FORMAT  # pylint:disable=global-statement\n    _HTTP_TEXT_FORMAT = http_text_format  # type: ignore\n", "path": "opentelemetry-api/src/opentelemetry/propagate/__init__.py"}, {"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nimport logging\nimport typing\n\nfrom deprecated import deprecated\n\nfrom opentelemetry.context.context import Context\nfrom opentelemetry.propagators import textmap\n\nlogger = logging.getLogger(__name__)\n\n\nclass CompositePropagator(textmap.TextMapPropagator):\n    \"\"\"CompositePropagator provides a mechanism for combining multiple\n    propagators into a single one.\n\n    Args:\n        propagators: the list of propagators to use\n    \"\"\"\n\n    def __init__(\n        self, propagators: typing.Sequence[textmap.TextMapPropagator]\n    ) -> None:\n        self._propagators = propagators\n\n    def extract(\n        self,\n        carrier: textmap.CarrierT,\n        context: typing.Optional[Context] = None,\n        getter: textmap.Getter = textmap.default_getter,\n    ) -> Context:\n        \"\"\"Run each of the configured propagators with the given context and carrier.\n        Propagators are run in the order they are configured, if multiple\n        propagators write the same context key, the propagator later in the list\n        will override previous propagators.\n\n        See `opentelemetry.propagators.textmap.TextMapPropagator.extract`\n        \"\"\"\n        for propagator in self._propagators:\n            context = propagator.extract(carrier, context, getter=getter)\n        return context  # type: ignore\n\n    def inject(\n        self,\n        carrier: textmap.CarrierT,\n        context: typing.Optional[Context] = None,\n        setter: textmap.Setter = textmap.default_setter,\n    ) -> None:\n        \"\"\"Run each of the configured propagators with the given context and carrier.\n        Propagators are run in the order they are configured, if multiple\n        propagators write the same carrier key, the propagator later in the list\n        will override previous propagators.\n\n        See `opentelemetry.propagators.textmap.TextMapPropagator.inject`\n        \"\"\"\n        for propagator in self._propagators:\n            propagator.inject(carrier, context, setter=setter)\n\n    @property\n    def fields(self) -> typing.Set[str]:\n        \"\"\"Returns a set with the fields set in `inject`.\n\n        See\n        `opentelemetry.propagators.textmap.TextMapPropagator.fields`\n        \"\"\"\n        composite_fields = set()\n\n        for propagator in self._propagators:\n            for field in propagator.fields:\n                composite_fields.add(field)\n\n        return composite_fields\n\n\n@deprecated(version=\"1.2.0\", reason=\"You should use CompositePropagator\")  # type: ignore\nclass CompositeHTTPPropagator(CompositePropagator):\n    \"\"\"CompositeHTTPPropagator provides a mechanism for combining multiple\n    propagators into a single one.\n    \"\"\"\n", "path": "opentelemetry-api/src/opentelemetry/propagators/composite.py"}]}