Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
composite.py94 linesDownload Raw Back to propagators
1# Copyright The OpenTelemetry Authors2#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 at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# 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 and13# limitations under the License.14import logging15import typing16 17from typing_extensions import deprecated18 19from opentelemetry.context.context import Context20from opentelemetry.propagators import textmap21 22logger = logging.getLogger(__name__)23 24 25class CompositePropagator(textmap.TextMapPropagator):26    """CompositePropagator provides a mechanism for combining multiple27    propagators into a single one.28 29    Args:30        propagators: the list of propagators to use31    """32 33    def __init__(34        self, propagators: typing.Sequence[textmap.TextMapPropagator]35    ) -> None:36        self._propagators = propagators37 38    def extract(39        self,40        carrier: textmap.CarrierT,41        context: typing.Optional[Context] = None,42        getter: textmap.Getter[textmap.CarrierT] = textmap.default_getter,43    ) -> Context:44        """Run each of the configured propagators with the given context and carrier.45        Propagators are run in the order they are configured, if multiple46        propagators write the same context key, the propagator later in the list47        will override previous propagators.48 49        See `opentelemetry.propagators.textmap.TextMapPropagator.extract`50        """51        for propagator in self._propagators:52            context = propagator.extract(carrier, context, getter=getter)53        return context  # type: ignore54 55    def inject(56        self,57        carrier: textmap.CarrierT,58        context: typing.Optional[Context] = None,59        setter: textmap.Setter[textmap.CarrierT] = textmap.default_setter,60    ) -> None:61        """Run each of the configured propagators with the given context and carrier.62        Propagators are run in the order they are configured, if multiple63        propagators write the same carrier key, the propagator later in the list64        will override previous propagators.65 66        See `opentelemetry.propagators.textmap.TextMapPropagator.inject`67        """68        for propagator in self._propagators:69            propagator.inject(carrier, context, setter=setter)70 71    @property72    def fields(self) -> typing.Set[str]:73        """Returns a set with the fields set in `inject`.74 75        See76        `opentelemetry.propagators.textmap.TextMapPropagator.fields`77        """78        composite_fields = set()79 80        for propagator in self._propagators:81            for field in propagator.fields:82                composite_fields.add(field)83 84        return composite_fields85 86 87@deprecated(88    "You should use CompositePropagator. Deprecated since version 1.2.0."89)90class CompositeHTTPPropagator(CompositePropagator):91    """CompositeHTTPPropagator provides a mechanism for combining multiple92    propagators into a single one.93    """94 
codekingpro/portable-devtools · Team Ai