diff --git a/tests/test_logs.py b/tests/test_logs.py index 82b5072a01..17abb08076 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -304,6 +304,24 @@ def test_logs_tied_to_transactions(sentry_init, capture_items): assert logs[0]["span_id"] == trx.span_id +@minimum_python_37 +def test_logs_tied_to_segments(sentry_init, capture_items): + """ + Log messages are also tied to segments. + """ + sentry_init(enable_logs=True, traces_sample_rate=1.0, trace_lifecycle="stream") + items = capture_items("log") + + with sentry_sdk.traces.start_span(name="test-segment") as sgmt: + sentry_sdk.logger.warning("This is a log tied to a segment") + + sentry_sdk.flush() + logs = [item.payload for item in items] + + assert "span_id" in logs[0] + assert logs[0]["span_id"] == sgmt.span_id + + @minimum_python_37 def test_logs_no_span_id_without_active_span(sentry_init, capture_items): """ @@ -339,6 +357,23 @@ def test_logs_tied_to_spans(sentry_init, capture_items): assert logs[0]["span_id"] == span.span_id +@minimum_python_37 +def test_logs_tied_to_spans_span_streaming(sentry_init, capture_items): + """ + Log messages are also tied to spans. + """ + sentry_init(enable_logs=True, traces_sample_rate=1.0, trace_lifecycle="stream") + items = capture_items("log") + + with sentry_sdk.traces.start_span(name="test-transaction"): + with sentry_sdk.traces.start_span(name="test-span") as span: + sentry_sdk.logger.warning("This is a log tied to a span") + + sentry_sdk.flush() + logs = [item.payload for item in items] + assert logs[0]["span_id"] == span.span_id + + @minimum_python_37 def test_auto_flush_logs_after_100(sentry_init, capture_envelopes): """