Skip to content

Commit

Permalink
Trevorriles/temp (#910)
Browse files Browse the repository at this point in the history
Add support for thrift header propagation.
  • Loading branch information
trevorriles authored May 6, 2024
1 parent b324b3b commit b0177ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions baseplate/lib/propagator_redditb3_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,40 @@ def extract(
context = Context()

extracted_trace_id = _extract_first_element(getter.get(carrier, self.TRACE_ID_KEY))
if extracted_trace_id is None:
# try lowercase
extracted_trace_id = _extract_first_element(getter.get(carrier, self.TRACE_ID_KEY.lower()))

logger.debug(
"Extracted trace_id from carrier. [carrier=%s, context=%s, trace_id=%s]",
carrier,
context,
extracted_trace_id,
)
extracted_span_id = _extract_first_element(getter.get(carrier, self.SPAN_ID_KEY))
if extracted_span_id is None:
# try lowercase
extracted_span_id = _extract_first_element(getter.get(carrier, self.SPAN_ID_KEY.lower()))
logger.debug(
"Extracted span_id from carrier. [carrier=%s, context=%s, span_id=%s]",
carrier,
context,
extracted_span_id,
)
sampled = _extract_first_element(getter.get(carrier, self.SAMPLED_KEY), default="0")
if sampled is None:
# try lowercase
sampled = _extract_first_element(getter.get(carrier, self.SAMPLED_KEY.lower()))
logger.debug(
"Extracted sampled from carrier. [carrier=%s, context=%s, sampled=%s]",
carrier,
context,
sampled,
)
flags = _extract_first_element(getter.get(carrier, self.FLAGS_KEY))
if flags is None:
# try lowercase
flags = _extract_first_element(getter.get(carrier, self.FLAGS_KEY.lower()))
logger.debug(
"Extracted flags from carrier. [carrier=%s, context=%s, flags=%s]",
carrier,
Expand Down
3 changes: 2 additions & 1 deletion baseplate/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from baseplate.lib.log_formatter import CustomJsonFormatter
from baseplate.lib.prometheus_metrics import is_metrics_enabled
from baseplate.lib.propagator_redditb3_http import RedditB3HTTPFormat
from baseplate.lib.propagator_redditb3_thrift import RedditB3ThriftFormat
from baseplate.server import einhorn
from baseplate.server import reloader
from baseplate.server.net import bind_socket
Expand Down Expand Up @@ -275,7 +276,7 @@ def configure_tracing(config: Configuration) -> None:

otlp_exporter = OTLPSpanExporter(endpoint=config.tracing["endpoint"], insecure=insecure)
propagate.set_global_textmap(
CompositePropagator([RedditB3HTTPFormat(), TraceContextTextMapPropagator()])
CompositePropagator([RedditB3ThriftFormat(), RedditB3HTTPFormat(), TraceContextTextMapPropagator()])
)
provider = TracerProvider(sampler=sampler, resource=resource)
provider.add_span_processor(
Expand Down

0 comments on commit b0177ef

Please sign in to comment.