Skip to content
Draft
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion ddtrace/internal/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Tuple # noqa:F401
from typing import Union # noqa:F401

from ddtrace.internal.constants import BAGGAGE_TAG_PREFIX


class ArgumentError(Exception):
"""
Expand Down Expand Up @@ -77,7 +79,7 @@ def _get_metas_to_propagate(context):
metas_to_propagate = []
# copying context._meta.items() to avoid RuntimeError: dictionary changed size during iteration
for k, v in list(context._meta.items()):
if isinstance(k, str) and k.startswith("_dd.p."):
if isinstance(k, str) and (k.startswith("_dd.p.") or k.startswith(BAGGAGE_TAG_PREFIX)):
metas_to_propagate.append((k, v))
return metas_to_propagate

Expand Down
19 changes: 19 additions & 0 deletions tests/contrib/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,25 @@ def test_baggage_span_tagging_default(client, tracer, test_spans):
assert request_span.get_tag("baggage.region") is None


def test_baggage_span_tags_propagate_to_child_spans(client, tracer, test_spans):
# Baggage header contains keys where user.id/account.id are in the default allowlist,
# and region is not. We expect the allowed baggage tags to appear on all spans.
response = client.get("/", headers={"baggage": "user.id=123,account.id=456,region=us-west"})

assert response.status_code == 200

traces = test_spans.pop_traces()
assert len(traces) >= 1
spans = traces[0]
assert len(spans) >= 1

for span in spans:
assert span.get_tag("baggage.user.id") == "123"
assert span.get_tag("baggage.account.id") == "456"
# Since "region" is not in the default list, its baggage tag should not be present.
assert span.get_tag("baggage.region") is None


def test_baggage_span_tagging_no_headers(client, tracer, test_spans):
response = client.get("/", headers={})
assert response.status_code == 200
Expand Down
Loading