mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-01 17:34:38 +08:00
Rename HTTPTextFormat to TextMapPropagator (#1085)
This commit is contained in:
@ -50,7 +50,7 @@ a distributed trace.
|
|||||||
trace.get_tracer_provider().add_span_processor(span_processor)
|
trace.get_tracer_provider().add_span_processor(span_processor)
|
||||||
|
|
||||||
# Optional: use Datadog format for propagation in distributed traces
|
# Optional: use Datadog format for propagation in distributed traces
|
||||||
propagators.set_global_httptextformat(DatadogFormat())
|
propagators.set_global_textmap(DatadogFormat())
|
||||||
|
|
||||||
with tracer.start_as_current_span("foo"):
|
with tracer.start_as_current_span("foo"):
|
||||||
print("Hello world!")
|
print("Hello world!")
|
||||||
|
@ -17,18 +17,18 @@ import typing
|
|||||||
from opentelemetry import trace
|
from opentelemetry import trace
|
||||||
from opentelemetry.context import Context
|
from opentelemetry.context import Context
|
||||||
from opentelemetry.trace import get_current_span, set_span_in_context
|
from opentelemetry.trace import get_current_span, set_span_in_context
|
||||||
from opentelemetry.trace.propagation.httptextformat import (
|
from opentelemetry.trace.propagation.textmap import (
|
||||||
Getter,
|
Getter,
|
||||||
HTTPTextFormat,
|
|
||||||
HTTPTextFormatT,
|
|
||||||
Setter,
|
Setter,
|
||||||
|
TextMapPropagator,
|
||||||
|
TextMapPropagatorT,
|
||||||
)
|
)
|
||||||
|
|
||||||
# pylint:disable=relative-beyond-top-level
|
# pylint:disable=relative-beyond-top-level
|
||||||
from . import constants
|
from . import constants
|
||||||
|
|
||||||
|
|
||||||
class DatadogFormat(HTTPTextFormat):
|
class DatadogFormat(TextMapPropagator):
|
||||||
"""Propagator for the Datadog HTTP header format.
|
"""Propagator for the Datadog HTTP header format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -39,8 +39,8 @@ class DatadogFormat(HTTPTextFormat):
|
|||||||
|
|
||||||
def extract(
|
def extract(
|
||||||
self,
|
self,
|
||||||
get_from_carrier: Getter[HTTPTextFormatT],
|
get_from_carrier: Getter[TextMapPropagatorT],
|
||||||
carrier: HTTPTextFormatT,
|
carrier: TextMapPropagatorT,
|
||||||
context: typing.Optional[Context] = None,
|
context: typing.Optional[Context] = None,
|
||||||
) -> Context:
|
) -> Context:
|
||||||
trace_id = extract_first_element(
|
trace_id = extract_first_element(
|
||||||
@ -81,8 +81,8 @@ class DatadogFormat(HTTPTextFormat):
|
|||||||
|
|
||||||
def inject(
|
def inject(
|
||||||
self,
|
self,
|
||||||
set_in_carrier: Setter[HTTPTextFormatT],
|
set_in_carrier: Setter[TextMapPropagatorT],
|
||||||
carrier: HTTPTextFormatT,
|
carrier: TextMapPropagatorT,
|
||||||
context: typing.Optional[Context] = None,
|
context: typing.Optional[Context] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
span = get_current_span(context)
|
span = get_current_span(context)
|
||||||
@ -120,8 +120,8 @@ def format_span_id(span_id: int) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def extract_first_element(
|
def extract_first_element(
|
||||||
items: typing.Iterable[HTTPTextFormatT],
|
items: typing.Iterable[TextMapPropagatorT],
|
||||||
) -> typing.Optional[HTTPTextFormatT]:
|
) -> typing.Optional[TextMapPropagatorT]:
|
||||||
if items is None:
|
if items is None:
|
||||||
return None
|
return None
|
||||||
return next(iter(items), None)
|
return next(iter(items), None)
|
||||||
|
Reference in New Issue
Block a user