Skip to content

Commit e175733

Browse files
committed
Merge branch 'ivana/span-first-15-ignore-spans' into ivana/span-first-16-thread-attrs
2 parents 7a5c168 + 5286dd0 commit e175733

3 files changed

Lines changed: 21 additions & 98 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ def _make_sampling_decision(
14221422
traces_sampler_defined = callable(client.options.get("traces_sampler"))
14231423
if traces_sampler_defined:
14241424
sampling_context = {
1425-
"span": {
1425+
"span_context": {
14261426
"name": name,
14271427
"trace_id": propagation_context.trace_id,
14281428
"parent_span_id": propagation_context.parent_span_id,
@@ -1490,7 +1490,7 @@ def is_ignored_span(name: str, attributes: "Optional[Attributes]") -> bool:
14901490
def _matches(rule: "Any", value: "Any") -> bool:
14911491
if isinstance(rule, Pattern):
14921492
if isinstance(value, str):
1493-
return bool(rule.match(value))
1493+
return bool(rule.fullmatch(value))
14941494
else:
14951495
return False
14961496

@@ -1501,7 +1501,7 @@ def _matches(rule: "Any", value: "Any") -> bool:
15011501
if _matches(rule, name):
15021502
return True
15031503

1504-
elif isinstance(rule, dict) and rule:
1504+
elif isinstance(rule, dict) and ("name" in rule or "attributes" in rule):
15051505
name_matches = True
15061506
attributes_match = True
15071507

tests/tracing/test_span_streaming.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_span_sampled_when_created(sentry_init, capture_envelopes):
121121
# at start_span() time
122122

123123
def traces_sampler(sampling_context):
124-
assert "delayed_attribute" not in sampling_context["span"]["attributes"]
124+
assert "delayed_attribute" not in sampling_context["span_context"]["attributes"]
125125
return 1.0
126126

127127
sentry_init(
@@ -170,9 +170,11 @@ def test_start_span_attributes(sentry_init, capture_envelopes):
170170

171171
def test_start_span_attributes_in_traces_sampler(sentry_init, capture_envelopes):
172172
def traces_sampler(sampling_context):
173-
assert "attributes" in sampling_context["span"]
174-
assert "my_attribute" in sampling_context["span"]["attributes"]
175-
assert sampling_context["span"]["attributes"]["my_attribute"] == "my_value"
173+
assert "attributes" in sampling_context["span_context"]
174+
assert "my_attribute" in sampling_context["span_context"]["attributes"]
175+
assert (
176+
sampling_context["span_context"]["attributes"]["my_attribute"] == "my_value"
177+
)
176178
return 1.0
177179

178180
sentry_init(
@@ -203,16 +205,16 @@ def test_sampling_context(sentry_init, capture_envelopes):
203205
def traces_sampler(sampling_context):
204206
nonlocal received_trace_id
205207

206-
assert "trace_id" in sampling_context["span"]
207-
received_trace_id = sampling_context["span"]["trace_id"]
208+
assert "trace_id" in sampling_context["span_context"]
209+
received_trace_id = sampling_context["span_context"]["trace_id"]
208210

209-
assert "parent_span_id" in sampling_context["span"]
210-
assert sampling_context["span"]["parent_span_id"] is None
211+
assert "parent_span_id" in sampling_context["span_context"]
212+
assert sampling_context["span_context"]["parent_span_id"] is None
211213

212-
assert "parent_sampled" in sampling_context["span"]
213-
assert sampling_context["span"]["parent_sampled"] is None
214+
assert "parent_sampled" in sampling_context["span_context"]
215+
assert sampling_context["span_context"]["parent_sampled"] is None
214216

215-
assert "attributes" in sampling_context["span"]
217+
assert "attributes" in sampling_context["span_context"]
216218

217219
return 1.0
218220

@@ -264,7 +266,7 @@ def traces_sampler(sampling_context):
264266

265267
def test_custom_sampling_context_update_to_context_value_persists(sentry_init):
266268
def traces_sampler(sampling_context):
267-
if sampling_context["span"]["attributes"]["first"] is True:
269+
if sampling_context["span_context"]["attributes"]["first"] is True:
268270
assert sampling_context["custom_value"] == 1
269271
else:
270272
assert sampling_context["custom_value"] == 2
@@ -362,10 +364,10 @@ class Class:
362364

363365
def test_traces_sampler_drops_span(sentry_init, capture_envelopes):
364366
def traces_sampler(sampling_context):
365-
assert "attributes" in sampling_context["span"]
366-
assert "drop" in sampling_context["span"]["attributes"]
367+
assert "attributes" in sampling_context["span_context"]
368+
assert "drop" in sampling_context["span_context"]["attributes"]
367369

368-
if sampling_context["span"]["attributes"]["drop"] is True:
370+
if sampling_context["span_context"]["attributes"]["drop"] is True:
369371
return 0.0
370372

371373
return 1.0
@@ -399,7 +401,7 @@ def test_traces_sampler_called_once_per_segment(sentry_init):
399401
def traces_sampler(sampling_context):
400402
nonlocal traces_sampler_called, span_name_in_traces_sampler
401403
traces_sampler_called += 1
402-
span_name_in_traces_sampler = sampling_context["span"]["name"]
404+
span_name_in_traces_sampler = sampling_context["span_context"]["name"]
403405
return 1.0
404406

405407
sentry_init(

0 commit comments

Comments
 (0)