Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: Only decode the traceparent and tracestate headers #1021

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions baseplate/frameworks/thrift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
["thrift_method"],
multiprocess_mode="livesum",
)
W3C_HEADERS: frozenset[bytes] = frozenset(
(
b"traceparent",
b"tracestate",
b"trace",
b"span",
b"sampled",
b"flags",
)
)


class _ContextAwareHandler:
Expand All @@ -82,9 +92,11 @@ def _set_remote_context(self, request_context: RequestContext) -> Iterator[None]
header_dict = {}
for k, v in headers.items():
try:
header_dict[k.decode()] = v.decode()
# this is only for w3c trace headers
if k.lower() in W3C_HEADERS:
header_dict[k.decode()] = v.decode()
except UnicodeDecodeError:
self.logger.info(f"Unable to decode header {k.decode()}, ignoring.")
self.logger.debug(f"Unable to decode header {k!r}={v!r}, ignoring.")

ctx = propagator.extract(header_dict)
logger.debug("Extracted trace headers. [ctx=%s, header_dict=%s]", ctx, header_dict)
Expand Down