Skip to content

(Partially) fix POTel CI #4307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,22 @@ def __init__(
only_if_parent=False, # type: bool
parent_span=None, # type: Optional[Span]
otel_span=None, # type: Optional[OtelSpan]
span=None, # type: Optional[Span]
):
# type: (...) -> None
"""
If otel_span is passed explicitly, just acts as a proxy.

If span is passed explicitly, use it. The only purpose of this param
if backwards compatibility with start_transaction(transaction=...).

If only_if_parent is True, just return an INVALID_SPAN
and avoid instrumentation if there's no active parent span.
"""
if otel_span is not None:
self._otel_span = otel_span
elif span is not None:
self._otel_span = span._otel_span
else:
skip_span = False
if only_if_parent and parent_span is None:
Expand Down
10 changes: 8 additions & 2 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ def test_ignore_logger_wildcard(sentry_init, capture_events):

def test_logging_dictionary_interpolation(sentry_init, capture_events):
"""Here we test an entire dictionary being interpolated into the log message."""
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
sentry_init(
integrations=[LoggingIntegration(event_level=logging.ERROR)],
default_integrations=False,
)
events = capture_events()

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

def test_logging_dictionary_args(sentry_init, capture_events):
"""Here we test items from a dictionary being interpolated into the log message."""
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
sentry_init(
integrations=[LoggingIntegration(event_level=logging.ERROR)],
default_integrations=False,
)
events = capture_events()

logger.error(
Expand Down
3 changes: 1 addition & 2 deletions tests/integrations/threading/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def double(number):
assert len(event["spans"]) == 0


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

Expand Down Expand Up @@ -232,7 +231,7 @@ def do_some_work(number):

threads = []

with sentry_sdk.start_transaction(op="outer-trx"):
with sentry_sdk.start_span(op="outer-trx"):
for number in range(5):
with sentry_sdk.start_span(
op=f"outer-submit-{number}", name="Thread: main"
Expand Down
45 changes: 45 additions & 0 deletions tests/opentelemetry/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sentry_sdk
from sentry_sdk.tracing import Transaction


def test_transaction_name_span_description_compat(
Expand Down Expand Up @@ -52,3 +53,47 @@ def test_transaction_name_span_description_compat(
assert span["op"] == "span-op"
assert span["data"]["sentry.op"] == "span-op"
assert span["data"]["sentry.description"] == "span-desc"


def test_start_transaction_compat(
sentry_init,
capture_events,
):
sentry_init(traces_sample_rate=1.0)

events = capture_events()

with sentry_sdk.start_transaction(
name="trx-name",
op="trx-op",
):
...

transaction = events[0]
assert transaction["transaction"] == "trx-name"
assert transaction["contexts"]["trace"]["op"] == "trx-op"
assert transaction["contexts"]["trace"]["data"]["sentry.op"] == "trx-op"
assert transaction["contexts"]["trace"]["data"]["sentry.name"] == "trx-name"
assert "sentry.description" not in transaction["contexts"]["trace"]["data"]


def test_start_transaction_with_explicit_transaction_compat(
sentry_init,
capture_events,
):
"""It should still be possible to provide a ready-made Transaction to start_transaction."""
sentry_init(traces_sample_rate=1.0)

events = capture_events()

transaction = Transaction(name="trx-name", op="trx-op")

with sentry_sdk.start_transaction(transaction=transaction):
pass

transaction = events[0]
assert transaction["transaction"] == "trx-name"
assert transaction["contexts"]["trace"]["op"] == "trx-op"
assert transaction["contexts"]["trace"]["data"]["sentry.op"] == "trx-op"
assert transaction["contexts"]["trace"]["data"]["sentry.name"] == "trx-name"
assert "sentry.description" not in transaction["contexts"]["trace"]["data"]
Loading