Rename HTTPTextFormat to TextMapPropagator (#1085)

This commit is contained in:
alrex
2020-09-09 13:23:56 -07:00
committed by alrex
parent 97e1a3debc
commit d3c69d4e98
2 changed files with 11 additions and 11 deletions

View File

@ -50,7 +50,7 @@ a distributed trace.
trace.get_tracer_provider().add_span_processor(span_processor)
# 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"):
print("Hello world!")

View File

@ -17,18 +17,18 @@ import typing
from opentelemetry import trace
from opentelemetry.context import 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,
HTTPTextFormat,
HTTPTextFormatT,
Setter,
TextMapPropagator,
TextMapPropagatorT,
)
# pylint:disable=relative-beyond-top-level
from . import constants
class DatadogFormat(HTTPTextFormat):
class DatadogFormat(TextMapPropagator):
"""Propagator for the Datadog HTTP header format.
"""
@ -39,8 +39,8 @@ class DatadogFormat(HTTPTextFormat):
def extract(
self,
get_from_carrier: Getter[HTTPTextFormatT],
carrier: HTTPTextFormatT,
get_from_carrier: Getter[TextMapPropagatorT],
carrier: TextMapPropagatorT,
context: typing.Optional[Context] = None,
) -> Context:
trace_id = extract_first_element(
@ -81,8 +81,8 @@ class DatadogFormat(HTTPTextFormat):
def inject(
self,
set_in_carrier: Setter[HTTPTextFormatT],
carrier: HTTPTextFormatT,
set_in_carrier: Setter[TextMapPropagatorT],
carrier: TextMapPropagatorT,
context: typing.Optional[Context] = None,
) -> None:
span = get_current_span(context)
@ -120,8 +120,8 @@ def format_span_id(span_id: int) -> str:
def extract_first_element(
items: typing.Iterable[HTTPTextFormatT],
) -> typing.Optional[HTTPTextFormatT]:
items: typing.Iterable[TextMapPropagatorT],
) -> typing.Optional[TextMapPropagatorT]:
if items is None:
return None
return next(iter(items), None)