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

ref: Forward all sentry- baggage items #1970

Merged
merged 2 commits into from
Mar 21, 2023
Merged
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
18 changes: 2 additions & 16 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,6 @@ class Baggage(object):
SENTRY_PREFIX = "sentry-"
SENTRY_PREFIX_REGEX = re.compile("^sentry-")

# DynamicSamplingContext
DSC_KEYS = [
"trace_id",
"public_key",
"sample_rate",
"release",
"environment",
"transaction",
"user_id",
"user_segment",
]

def __init__(
self,
sentry_items, # type: Dict[str, str]
Expand Down Expand Up @@ -318,10 +306,8 @@ def dynamic_sampling_context(self):
# type: () -> Dict[str, str]
header = {}

for key in Baggage.DSC_KEYS:
item = self.sentry_items.get(key)
if item:
header[key] = item
for key, item in iteritems(self.sentry_items):
header[key] = item

return header

Expand Down
9 changes: 6 additions & 3 deletions tests/tracing/test_baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_mixed_baggage():
header = (
"other-vendor-value-1=foo;bar;baz, sentry-trace_id=771a43a4192642f0b136d5159a501700, "
"sentry-public_key=49d0f7386ad645858ae85020e393bef3, sentry-sample_rate=0.01337, "
"sentry-user_id=Am%C3%A9lie, other-vendor-value-2=foo;bar;"
"sentry-user_id=Am%C3%A9lie, sentry-foo=bar, other-vendor-value-2=foo;bar;"
)

baggage = Baggage.from_incoming_header(header)
Expand All @@ -35,6 +35,7 @@ def test_mixed_baggage():
"trace_id": "771a43a4192642f0b136d5159a501700",
"user_id": "Amélie",
"sample_rate": "0.01337",
"foo": "bar",
}

assert (
Expand All @@ -47,21 +48,23 @@ def test_mixed_baggage():
"trace_id": "771a43a4192642f0b136d5159a501700",
"user_id": "Amélie",
"sample_rate": "0.01337",
"foo": "bar",
}

assert sorted(baggage.serialize().split(",")) == sorted(
(
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
"sentry-sample_rate=0.01337,sentry-user_id=Am%C3%A9lie"
"sentry-sample_rate=0.01337,sentry-user_id=Am%C3%A9lie,"
"sentry-foo=bar"
).split(",")
)

assert sorted(baggage.serialize(include_third_party=True).split(",")) == sorted(
(
"sentry-trace_id=771a43a4192642f0b136d5159a501700,"
"sentry-public_key=49d0f7386ad645858ae85020e393bef3,"
"sentry-sample_rate=0.01337,sentry-user_id=Am%C3%A9lie,"
"sentry-sample_rate=0.01337,sentry-user_id=Am%C3%A9lie,sentry-foo=bar,"
"other-vendor-value-1=foo;bar;baz,other-vendor-value-2=foo;bar;"
).split(",")
)
Expand Down