Skip to content

Commit 482b3bb

Browse files
.
2 parents 7b6c5a2 + 5ce5d1a commit 482b3bb

11 files changed

Lines changed: 91 additions & 74 deletions

File tree

.github/workflows/flaky-test-detector.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
name: Detect flaky tests and open summary issue
4848
runs-on: ubuntu-latest
4949
timeout-minutes: 30
50+
# ANTHROPIC_API_KEY is not a repo-level secret; it lives in this environment
51+
environment: AI Integrations Tests
5052

5153
steps:
5254
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

.github/workflows/update-tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Update test matrix
1212
if: github.ref == 'refs/heads/master'
1313
runs-on: ubuntu-latest
14-
timeout-minutes: 10
14+
timeout-minutes: 20
1515

1616
permissions:
1717
contents: write

sentry_sdk/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from sentry_sdk.consts import INSTRUMENTER
99
from sentry_sdk.crons import monitor
1010
from sentry_sdk.scope import Scope, _ScopeManager, isolation_scope, new_scope
11-
from sentry_sdk.traces import StreamedSpan, _get_current_streamed_span
11+
from sentry_sdk.traces import StreamedSpan
12+
from sentry_sdk.traces import get_current_span as _get_current_streamed_span
1213
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
1314

1415
if TYPE_CHECKING:

sentry_sdk/feature_flags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def add_feature_flag(flag: str, result: bool) -> None:
6565
flags.set(flag, result)
6666

6767
if has_span_streaming_enabled(client.options):
68-
span = sentry_sdk.traces._get_current_streamed_span()
68+
span = sentry_sdk.traces.get_current_span()
6969
if span and isinstance(span, sentry_sdk.traces.StreamedSpan):
7070
span.set_attribute(f"flag.evaluation.{flag}", result)
7171

sentry_sdk/integrations/celery/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
1717
from sentry_sdk.integrations.logging import ignore_logger
1818
from sentry_sdk.scope import Scope, should_send_default_pii
19-
from sentry_sdk.traces import StreamedSpan, _get_current_streamed_span
19+
from sentry_sdk.traces import StreamedSpan, get_current_span
2020
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource
2121
from sentry_sdk.tracing_utils import Baggage, has_span_streaming_enabled
2222
from sentry_sdk.utils import (
@@ -286,7 +286,7 @@ def apply_async(*args: "Any", **kwargs: "Any") -> "Any":
286286

287287
span_mgr: "Union[StreamedSpan, Span, NoOpMgr]" = NoOpMgr()
288288
if span_streaming:
289-
if not task_started_from_beat and _get_current_streamed_span() is not None:
289+
if not task_started_from_beat and get_current_span() is not None:
290290
span_mgr = sentry_sdk.traces.start_span(
291291
name=task_name,
292292
attributes={
@@ -567,7 +567,7 @@ def sentry_publish(self: "Producer", *args: "Any", **kwargs: "Any") -> "Any":
567567

568568
span: "Union[StreamedSpan, Span, None]" = None
569569
if span_streaming:
570-
if _get_current_streamed_span() is not None:
570+
if get_current_span() is not None:
571571
span = sentry_sdk.traces.start_span(
572572
name=task_name,
573573
attributes={

sentry_sdk/integrations/opentelemetry/integration.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
removed at any time without prior notice.
55
"""
66

7+
import warnings
8+
from typing import TYPE_CHECKING
9+
710
from sentry_sdk.integrations import DidNotEnable, Integration
811
from sentry_sdk.integrations.opentelemetry.propagator import SentryPropagator
912
from sentry_sdk.integrations.opentelemetry.span_processor import SentrySpanProcessor
13+
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1014
from sentry_sdk.utils import logger
1115

16+
if TYPE_CHECKING:
17+
from typing import Any, Dict, Optional
18+
1219
try:
1320
from opentelemetry import trace
1421
from opentelemetry.propagate import set_global_textmap
@@ -34,9 +41,24 @@ class OpenTelemetryIntegration(Integration):
3441

3542
@staticmethod
3643
def setup_once() -> None:
37-
logger.warning(
38-
"[OTel] Initializing highly experimental OpenTelemetry support. "
39-
"Use at your own risk."
44+
pass
45+
46+
def setup_once_with_options(
47+
self, options: "Optional[Dict[str, Any]]" = None
48+
) -> None:
49+
if has_span_streaming_enabled(options):
50+
logger.warning(
51+
"[OTel] OpenTelemetryIntegration is not compatible with span streaming "
52+
"(trace_lifecycle='stream') and will be disabled."
53+
)
54+
return
55+
56+
warnings.warn(
57+
"OpenTelemetryIntegration is deprecated. "
58+
"Please use OTLPIntegration instead: "
59+
"https://docs.sentry.io/platforms/python/integrations/otlp/",
60+
DeprecationWarning,
61+
stacklevel=2,
4062
)
4163

4264
_setup_sentry_tracing()

sentry_sdk/integrations/starlette.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
2424
from sentry_sdk.scope import should_send_default_pii
25-
from sentry_sdk.traces import StreamedSpan, _get_current_streamed_span
25+
from sentry_sdk.traces import StreamedSpan, get_current_span
2626
from sentry_sdk.tracing import (
2727
SOURCE_FOR_STYLE,
2828
TransactionSource,
@@ -254,7 +254,7 @@ def _default(value: "Any") -> "Any":
254254
def _set_request_body_data_on_streaming_segment(
255255
info: "Optional[Dict[str, Any]]",
256256
) -> None:
257-
current_span = _get_current_streamed_span()
257+
current_span = get_current_span()
258258
if info and "data" in info and type(current_span) is StreamedSpan:
259259
with capture_internal_exceptions():
260260
current_span._segment.set_attribute(

sentry_sdk/traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def make_db_query(sql):
827827
return decorator
828828

829829

830-
def _get_current_streamed_span(
830+
def get_current_span(
831831
scope: "Optional[sentry_sdk.Scope]" = None,
832832
) -> "Optional[StreamedSpan]":
833833
"""

tests/integrations/celery/test_celery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
from celery.bin import worker
99

1010
import sentry_sdk
11+
import sentry_sdk.traces
1112
from sentry_sdk import get_current_span, start_transaction
1213
from sentry_sdk.integrations.celery import (
1314
CeleryIntegration,
1415
_wrap_task_run,
1516
)
1617
from sentry_sdk.integrations.celery.beat import _get_headers
17-
from sentry_sdk.traces import _get_current_streamed_span
1818
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE
1919
from tests.conftest import ApproxDict
2020

@@ -667,7 +667,7 @@ def test_sentry_propagate_traces_override(span_streaming, init_celery):
667667
@celery.task(name="dummy_task", bind=True)
668668
def dummy_task(self, message):
669669
trace_id = (
670-
_get_current_streamed_span().trace_id
670+
sentry_sdk.traces.get_current_span().trace_id
671671
if span_streaming
672672
else get_current_span().trace_id
673673
)

tests/integrations/opentelemetry/test_experimental.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,56 @@
22

33
import pytest
44

5+
from sentry_sdk.integrations.opentelemetry.integration import OpenTelemetryIntegration
6+
57

68
@pytest.mark.forked
79
def test_integration_enabled_if_option_is_on(sentry_init, reset_integrations):
8-
mocked_setup_once = MagicMock()
10+
mocked_setup_sentry_tracing = MagicMock()
911

1012
with patch(
11-
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration.setup_once",
12-
mocked_setup_once,
13+
"sentry_sdk.integrations.opentelemetry.integration._setup_sentry_tracing",
14+
mocked_setup_sentry_tracing,
1315
):
14-
sentry_init(
15-
_experiments={
16-
"otel_powered_performance": True,
17-
},
18-
)
19-
mocked_setup_once.assert_called_once()
16+
with pytest.warns(DeprecationWarning):
17+
sentry_init(_experiments={"otel_powered_performance": True})
18+
mocked_setup_sentry_tracing.assert_called_once()
2019

2120

2221
@pytest.mark.forked
2322
def test_integration_not_enabled_if_option_is_off(sentry_init, reset_integrations):
24-
mocked_setup_once = MagicMock()
23+
mocked_setup_sentry_tracing = MagicMock()
2524

2625
with patch(
27-
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration.setup_once",
28-
mocked_setup_once,
26+
"sentry_sdk.integrations.opentelemetry.integration._setup_sentry_tracing",
27+
mocked_setup_sentry_tracing,
2928
):
30-
sentry_init(
31-
_experiments={
32-
"otel_powered_performance": False,
33-
},
34-
)
35-
mocked_setup_once.assert_not_called()
29+
sentry_init(_experiments={"otel_powered_performance": False})
30+
mocked_setup_sentry_tracing.assert_not_called()
3631

3732

3833
@pytest.mark.forked
3934
def test_integration_not_enabled_if_option_is_missing(sentry_init, reset_integrations):
40-
mocked_setup_once = MagicMock()
35+
mocked_setup_sentry_tracing = MagicMock()
4136

4237
with patch(
43-
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration.setup_once",
44-
mocked_setup_once,
38+
"sentry_sdk.integrations.opentelemetry.integration._setup_sentry_tracing",
39+
mocked_setup_sentry_tracing,
4540
):
4641
sentry_init()
47-
mocked_setup_once.assert_not_called()
42+
mocked_setup_sentry_tracing.assert_not_called()
43+
44+
45+
@pytest.mark.forked
46+
def test_integration_disabled_with_span_streaming(sentry_init, reset_integrations):
47+
mocked_setup_sentry_tracing = MagicMock()
48+
49+
with patch(
50+
"sentry_sdk.integrations.opentelemetry.integration._setup_sentry_tracing",
51+
mocked_setup_sentry_tracing,
52+
):
53+
sentry_init(
54+
integrations=[OpenTelemetryIntegration()],
55+
_experiments={"trace_lifecycle": "stream"},
56+
)
57+
mocked_setup_sentry_tracing.assert_not_called()

0 commit comments

Comments
 (0)