Skip to content

Commit

Permalink
ref: Forward all sentry- baggage items (#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Mar 21, 2023
1 parent 5d3649d commit f9ec128
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
18 changes: 2 additions & 16 deletions sentry_sdk/tracing_utils.py
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
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

0 comments on commit f9ec128

Please sign in to comment.