Skip to content

Commit 571ff3b

Browse files
authored
(Partially) fix POTel CI (#4307)
Porting stuff from master and other fixes * add correct `event_level` to new logging tests (on `potel-base`, we don't capture logging errors by default so this has to be set explicitly) * add compat for `start_transaction` * re-enable an old test **Note:** This still leaves one failing threading test, will address that separately
1 parent b5db56f commit 571ff3b

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

sentry_sdk/tracing.py

+6
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,22 @@ def __init__(
183183
only_if_parent=False, # type: bool
184184
parent_span=None, # type: Optional[Span]
185185
otel_span=None, # type: Optional[OtelSpan]
186+
span=None, # type: Optional[Span]
186187
):
187188
# type: (...) -> None
188189
"""
189190
If otel_span is passed explicitly, just acts as a proxy.
190191
192+
If span is passed explicitly, use it. The only purpose of this param
193+
if backwards compatibility with start_transaction(transaction=...).
194+
191195
If only_if_parent is True, just return an INVALID_SPAN
192196
and avoid instrumentation if there's no active parent span.
193197
"""
194198
if otel_span is not None:
195199
self._otel_span = otel_span
200+
elif span is not None:
201+
self._otel_span = span._otel_span
196202
else:
197203
skip_span = False
198204
if only_if_parent and parent_span is None:

tests/integrations/logging/test_logging.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ def test_ignore_logger_wildcard(sentry_init, capture_events):
296296

297297
def test_logging_dictionary_interpolation(sentry_init, capture_events):
298298
"""Here we test an entire dictionary being interpolated into the log message."""
299-
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
299+
sentry_init(
300+
integrations=[LoggingIntegration(event_level=logging.ERROR)],
301+
default_integrations=False,
302+
)
300303
events = capture_events()
301304

302305
logger.error("this is a log with a dictionary %s", {"foo": "bar"})
@@ -312,7 +315,10 @@ def test_logging_dictionary_interpolation(sentry_init, capture_events):
312315

313316
def test_logging_dictionary_args(sentry_init, capture_events):
314317
"""Here we test items from a dictionary being interpolated into the log message."""
315-
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
318+
sentry_init(
319+
integrations=[LoggingIntegration(event_level=logging.ERROR)],
320+
default_integrations=False,
321+
)
316322
events = capture_events()
317323

318324
logger.error(

tests/integrations/threading/test_threading.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def double(number):
104104
assert len(event["spans"]) == 0
105105

106106

107-
@pytest.mark.skip(reason="Temporarily disable to release SDK 2.0a1.")
108107
def test_circular_references(sentry_init, request):
109108
sentry_init(default_integrations=False, integrations=[ThreadingIntegration()])
110109

@@ -232,7 +231,7 @@ def do_some_work(number):
232231

233232
threads = []
234233

235-
with sentry_sdk.start_transaction(op="outer-trx"):
234+
with sentry_sdk.start_span(op="outer-trx"):
236235
for number in range(5):
237236
with sentry_sdk.start_span(
238237
op=f"outer-submit-{number}", name="Thread: main"

tests/opentelemetry/test_compat.py

+45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sentry_sdk
2+
from sentry_sdk.tracing import Transaction
23

34

45
def test_transaction_name_span_description_compat(
@@ -52,3 +53,47 @@ def test_transaction_name_span_description_compat(
5253
assert span["op"] == "span-op"
5354
assert span["data"]["sentry.op"] == "span-op"
5455
assert span["data"]["sentry.description"] == "span-desc"
56+
57+
58+
def test_start_transaction_compat(
59+
sentry_init,
60+
capture_events,
61+
):
62+
sentry_init(traces_sample_rate=1.0)
63+
64+
events = capture_events()
65+
66+
with sentry_sdk.start_transaction(
67+
name="trx-name",
68+
op="trx-op",
69+
):
70+
...
71+
72+
transaction = events[0]
73+
assert transaction["transaction"] == "trx-name"
74+
assert transaction["contexts"]["trace"]["op"] == "trx-op"
75+
assert transaction["contexts"]["trace"]["data"]["sentry.op"] == "trx-op"
76+
assert transaction["contexts"]["trace"]["data"]["sentry.name"] == "trx-name"
77+
assert "sentry.description" not in transaction["contexts"]["trace"]["data"]
78+
79+
80+
def test_start_transaction_with_explicit_transaction_compat(
81+
sentry_init,
82+
capture_events,
83+
):
84+
"""It should still be possible to provide a ready-made Transaction to start_transaction."""
85+
sentry_init(traces_sample_rate=1.0)
86+
87+
events = capture_events()
88+
89+
transaction = Transaction(name="trx-name", op="trx-op")
90+
91+
with sentry_sdk.start_transaction(transaction=transaction):
92+
pass
93+
94+
transaction = events[0]
95+
assert transaction["transaction"] == "trx-name"
96+
assert transaction["contexts"]["trace"]["op"] == "trx-op"
97+
assert transaction["contexts"]["trace"]["data"]["sentry.op"] == "trx-op"
98+
assert transaction["contexts"]["trace"]["data"]["sentry.name"] == "trx-name"
99+
assert "sentry.description" not in transaction["contexts"]["trace"]["data"]

0 commit comments

Comments
 (0)