Skip to content

Commit

Permalink
testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Dec 3, 2024
1 parent 82c8b6e commit 2dbb4e8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def on_start(self, span, parent_context=None):
return

self._add_root_span(span, get_current_span(parent_context))
self._start_profile(span, parent_context)
self._start_profile(span)

def on_end(self, span):
# type: (ReadableSpan) -> None
Expand Down Expand Up @@ -106,7 +106,7 @@ def _add_root_span(self, span, parent_span):
# root span points to itself
set_sentry_meta(span, "root_span", span)

def _start_profile(self, span, parent_context):
def _start_profile(self, span):
# type: (Span, Optional[Context]) -> None
try_autostart_continuous_profiler()
profiler_id = get_profiler_id()
Expand All @@ -128,7 +128,7 @@ def _start_profile(self, span, parent_context):
# setting it to 0 means the profiler will internally measure time on start
profile = Profile(sampled, 0)
sampling_context = create_sampling_context(
span.name, span.attributes, parent_context, span.context.trace_id
span.name, span.attributes, span.parent, span.context.trace_id
)
profile._set_initial_sampling_decision(sampling_context)
profile.__enter__()
Expand Down
22 changes: 22 additions & 0 deletions tests/tracing/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,25 @@ def test_records_lost_event_only_if_traces_sampler_enabled(

# Use Counter because order of calls does not matter
assert Counter(record_lost_event_calls) == Counter(expected_record_lost_event_calls)


@pytest.mark.parametrize("parent_sampling_decision", [True, False])
def test_profiles_sampler_gets_sampling_context(sentry_init, parent_sampling_decision):
def dummy_profiles_sampler(sampling_context):
assert sampling_context["transaction_context"] == {
"name": "dogpark",
"op": "op",
"source": "custom",
}
assert sampling_context["parent_sampled"] == parent_sampling_decision
return 1.0

sentry_init(traces_sample_rate=1.0, profiles_sampler=dummy_profiles_sampler)

with sentry_sdk.continue_trace(
{
"sentry-trace": f"12312012123120121231201212312012-1121201211212012-{int(parent_sampling_decision)}"
}
):
with sentry_sdk.start_span(name="dogpark", op="op"):
pass

0 comments on commit 2dbb4e8

Please sign in to comment.