Skip to content

Commit 3737b3c

Browse files
committed
more tests
1 parent a53a1c2 commit 3737b3c

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

sentry_sdk/traces.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def __str__(self) -> str:
9797
- maybe: use getters/setter OR properties but not both
9898
- add size-based flushing to buffer(s)
9999
- migrate transaction sample_rand logic
100-
- remove deprecated profiler impl
101100
- custom_sampling_context?
102101
- store on scope/propagation context instead?
103102
- function to set on propagation context

tests/tracing/test_span_streaming.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,32 @@ def traces_sampler(sampling_context):
198198
assert span["attributes"]["my_attribute"] == "my_value"
199199

200200

201+
def test_sampling_context(sentry_init, capture_envelopes):
202+
def traces_sampler(sampling_context):
203+
assert "transaction_context" in sampling_context
204+
assert "trace_id" in sampling_context["transaction_context"]
205+
assert "span_id" in sampling_context["transaction_context"]
206+
assert "parent_span_id" in sampling_context["transaction_context"]
207+
assert "parent_sampled" in sampling_context
208+
assert "attributes" in sampling_context
209+
return 1.0
210+
211+
sentry_init(
212+
traces_sampler=traces_sampler,
213+
_experiments={"trace_lifecycle": "stream"},
214+
)
215+
216+
events = capture_envelopes()
217+
218+
with sentry_sdk.traces.start_span(name="span"):
219+
...
220+
221+
sentry_sdk.get_client().flush()
222+
spans = envelopes_to_spans(events)
223+
224+
assert len(spans) == 1
225+
226+
201227
def test_span_attributes(sentry_init, capture_envelopes):
202228
sentry_init(
203229
traces_sample_rate=1.0,
@@ -608,6 +634,28 @@ def test_set_span_source(sentry_init, capture_envelopes):
608634
assert span["attributes"]["sentry.span.source"] == SegmentSource.TASK.value
609635

610636

637+
def test_set_span_origin(sentry_init, capture_envelopes):
638+
sentry_init(
639+
traces_sample_rate=1.0,
640+
_experiments={"trace_lifecycle": "stream"},
641+
)
642+
643+
events = capture_envelopes()
644+
645+
with sentry_sdk.traces.start_span(name="span") as span:
646+
span.set_origin("redis")
647+
assert span.get_attributes()["sentry.origin"] == "redis"
648+
649+
sentry_sdk.get_client().flush()
650+
spans = envelopes_to_spans(events)
651+
652+
assert len(spans) == 1
653+
(span,) = spans
654+
655+
assert span["name"] == "span"
656+
assert span["attributes"]["sentry.origin"] == "redis"
657+
658+
611659
def test_transport_format(sentry_init, capture_envelopes):
612660
sentry_init(
613661
server_name="test-server",

0 commit comments

Comments
 (0)