Skip to content

Commit 92b7e6d

Browse files
committed
Logs tied to transactions/spans
1 parent bad1974 commit 92b7e6d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_sentry_logs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import random
22
from unittest import mock
33

4+
import sentry_sdk
45
from sentry_sdk import _experimental_logger as sentry_logger
56

67

@@ -189,3 +190,32 @@ def test_logs_message_python_logging(sentry_init, capture_envelopes):
189190
assert str(ex) == "capture_log() takes 3 positional arguments but 4 were given"
190191

191192
assert len(envelopes) == 0
193+
194+
195+
def test_logs_tied_to_transactions(sentry_init, capture_envelopes):
196+
"""
197+
Log messages are also tied to transactions.
198+
"""
199+
sentry_init(enable_sentry_logs=True)
200+
envelopes = capture_envelopes()
201+
202+
with sentry_sdk.start_transaction(name="test-transaction") as trx:
203+
sentry_logger.warn("This is a log tied to a transaction")
204+
205+
log_entry = envelopes[0].items[0].payload.json
206+
assert log_entry["attributes"][-1] =={'key': 'sentry.trace.parent_span_id', 'value': {'stringValue': trx.span_id}}
207+
208+
209+
def test_logs_tied_to_spans(sentry_init, capture_envelopes):
210+
"""
211+
Log messages are also tied to spans.
212+
"""
213+
sentry_init(enable_sentry_logs=True)
214+
envelopes = capture_envelopes()
215+
216+
with sentry_sdk.start_transaction(name="test-transaction") as trx:
217+
with sentry_sdk.start_span(description="test-span") as span:
218+
sentry_logger.warn("This is a log tied to a span")
219+
220+
log_entry = envelopes[0].items[0].payload.json
221+
assert log_entry["attributes"][-1] =={'key': 'sentry.trace.parent_span_id', 'value': {'stringValue': span.span_id}}

0 commit comments

Comments
 (0)