Skip to content
Open
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
35 changes: 35 additions & 0 deletions tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe be called test-segment?

Suggested change
with sentry_sdk.traces.start_span(name="test-transaction"):
with sentry_sdk.traces.start_span(name="test-segment"):

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):
"""
Expand Down
Loading