Skip to content

Commit 2dbb4e8

Browse files
committed
testcase
1 parent 82c8b6e commit 2dbb4e8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def on_start(self, span, parent_context=None):
6767
return
6868

6969
self._add_root_span(span, get_current_span(parent_context))
70-
self._start_profile(span, parent_context)
70+
self._start_profile(span)
7171

7272
def on_end(self, span):
7373
# type: (ReadableSpan) -> None
@@ -106,7 +106,7 @@ def _add_root_span(self, span, parent_span):
106106
# root span points to itself
107107
set_sentry_meta(span, "root_span", span)
108108

109-
def _start_profile(self, span, parent_context):
109+
def _start_profile(self, span):
110110
# type: (Span, Optional[Context]) -> None
111111
try_autostart_continuous_profiler()
112112
profiler_id = get_profiler_id()
@@ -128,7 +128,7 @@ def _start_profile(self, span, parent_context):
128128
# setting it to 0 means the profiler will internally measure time on start
129129
profile = Profile(sampled, 0)
130130
sampling_context = create_sampling_context(
131-
span.name, span.attributes, parent_context, span.context.trace_id
131+
span.name, span.attributes, span.parent, span.context.trace_id
132132
)
133133
profile._set_initial_sampling_decision(sampling_context)
134134
profile.__enter__()

tests/tracing/test_sampling.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,25 @@ def test_records_lost_event_only_if_traces_sampler_enabled(
307307

308308
# Use Counter because order of calls does not matter
309309
assert Counter(record_lost_event_calls) == Counter(expected_record_lost_event_calls)
310+
311+
312+
@pytest.mark.parametrize("parent_sampling_decision", [True, False])
313+
def test_profiles_sampler_gets_sampling_context(sentry_init, parent_sampling_decision):
314+
def dummy_profiles_sampler(sampling_context):
315+
assert sampling_context["transaction_context"] == {
316+
"name": "dogpark",
317+
"op": "op",
318+
"source": "custom",
319+
}
320+
assert sampling_context["parent_sampled"] == parent_sampling_decision
321+
return 1.0
322+
323+
sentry_init(traces_sample_rate=1.0, profiles_sampler=dummy_profiles_sampler)
324+
325+
with sentry_sdk.continue_trace(
326+
{
327+
"sentry-trace": f"12312012123120121231201212312012-1121201211212012-{int(parent_sampling_decision)}"
328+
}
329+
):
330+
with sentry_sdk.start_span(name="dogpark", op="op"):
331+
pass

0 commit comments

Comments
 (0)