Skip to content
Merged
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
52 changes: 52 additions & 0 deletions tests/tracing/test_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

import sentry_sdk
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.tracing import Transaction
from sentry_sdk.tracing_utils import extract_sentrytrace_data

Expand All @@ -26,6 +28,35 @@ def test_to_traceparent(sampled):
assert parts[2] == "1" if sampled is True else "0" # sampled


@pytest.mark.parametrize("traces_sample_rate", [1.0, 0.0, None])
def test_to_traceparent_span_streaming(sentry_init, traces_sample_rate):
sentry_init(
traces_sample_rate=traces_sample_rate,
_experiments={
"trace_lifecycle": "stream",
},
)

with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span:
traceparent = sentry_sdk.get_traceparent()

parts = traceparent.split("-")
if traces_sample_rate is None:
propagation_context = (
sentry_sdk.get_current_scope().get_active_propagation_context()
)
assert parts[0] == propagation_context.trace_id # trace_id
assert parts[1] == propagation_context.span_id # parent_span_id
assert len(parts) == 2
else:
assert parts[0] == span.trace_id # trace_id
assert parts[1] == span.span_id # parent_span_id
if traces_sample_rate == 1.0:
assert parts[2] == "1"
else:
assert parts[2] == "0"

Comment thread
sentrivana marked this conversation as resolved.

@pytest.mark.parametrize("sampling_decision", [True, False])
def test_sentrytrace_extraction(sampling_decision):
sentrytrace_header = "12312012123120121231201212312012-0415201309082013-{}".format(
Expand Down Expand Up @@ -75,3 +106,24 @@ def test_iter_headers(monkeypatch):
assert (
headers["sentry-trace"] == "12312012123120121231201212312012-0415201309082013-0"
)

Comment thread
sentry-warden[bot] marked this conversation as resolved.

def test_iter_headers_span_streaming(sentry_init, monkeypatch):
sentry_init(
traces_sample_rate=0.0,
_experiments={
"trace_lifecycle": "stream",
},
)
monkeypatch.setattr(
StreamedSpan,
"_to_traceparent",
mock.Mock(return_value="12312012123120121231201212312012-0415201309082013-0"),
)

with sentry_sdk.traces.start_span(name="/interactions/other-dogs/new-dog") as span:
headers = dict(span._iter_headers())
assert (
headers["sentry-trace"]
== "12312012123120121231201212312012-0415201309082013-0"
)
Loading