Skip to content

Commit acd7cf2

Browse files
feat(tracing): Remove instrumenter option
Remove `instrumenter` parameter from all functions that accept it (details below), and modify tests to not pass the `instrumenter` parameter to any functions that used to take it. Also, delete `tests/tracing/test_noop_span.py`, which tests functionality removed in this commit. BREAKING CHANGE: - Remove `sentry_sdk.init`'s `instrumenter` kwarg. - Delete `sentry_sdk.contsts.INSTRUMENTER` class. - Remove `sentry_sdk.hub.Hub.start_span`'s `instrumenter` parameter. - Remove `sentry_sdk.hub.Hub.start_transaction`'s `instrumenter` parameter. - Remove `sentry_sdk.scope.Scope.start_transaction`'s `instrumenter` parameter. - Remove `sentry_sdk.scope.Scope.start_span`'s `instrumenter` parameter. - Remove `sentry_sdk.tracing.Span.start_child`'s `instrumenter` parameter. - Remove `sentry_sdk.tracing.NoOpSpan.start_child`'s `instrumenter` parameter. Closes: #3321
1 parent 4428ee9 commit acd7cf2

File tree

9 files changed

+23
-142
lines changed

9 files changed

+23
-142
lines changed

sentry_sdk/api.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from sentry_sdk import tracing_utils, Client
55
from sentry_sdk._types import TYPE_CHECKING
6-
from sentry_sdk.consts import INSTRUMENTER
76
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
87
from sentry_sdk.tracing import NoOpSpan, Transaction
98

@@ -293,7 +292,6 @@ def start_span(
293292
@scopemethod
294293
def start_transaction(
295294
transaction=None, # type: Optional[Transaction]
296-
instrumenter=INSTRUMENTER.SENTRY, # type: str
297295
custom_sampling_context=None, # type: Optional[SamplingContext]
298296
**kwargs, # type: Unpack[TransactionKwargs]
299297
):
@@ -322,15 +320,13 @@ def start_transaction(
322320
323321
:param transaction: The transaction to start. If omitted, we create and
324322
start a new transaction.
325-
:param instrumenter: This parameter is meant for internal use only. It
326-
will be removed in the next major version.
327323
:param custom_sampling_context: The transaction's custom sampling context.
328324
:param kwargs: Optional keyword arguments to be passed to the Transaction
329325
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
330326
available arguments.
331327
"""
332328
return Scope.get_current_scope().start_transaction(
333-
transaction, instrumenter, custom_sampling_context, **kwargs
329+
transaction, custom_sampling_context, **kwargs
334330
)
335331

336332

sentry_sdk/client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from sentry_sdk.consts import (
2626
DEFAULT_MAX_VALUE_LENGTH,
2727
DEFAULT_OPTIONS,
28-
INSTRUMENTER,
2928
VERSION,
3029
ClientConstructor,
3130
)
@@ -113,9 +112,6 @@ def _get_options(*args, **kwargs):
113112
if rv["server_name"] is None and hasattr(socket, "gethostname"):
114113
rv["server_name"] = socket.gethostname()
115114

116-
if rv["instrumenter"] is None:
117-
rv["instrumenter"] = INSTRUMENTER.SENTRY
118-
119115
if rv["project_root"] is None:
120116
try:
121117
project_root = os.getcwd()
@@ -357,7 +353,6 @@ def _capture_envelope(envelope):
357353
logger.debug(
358354
"[OTel] Enabling experimental OTel-powered performance monitoring."
359355
)
360-
self.options["instrumenter"] = INSTRUMENTER.OTEL
361356
if (
362357
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration"
363358
not in _DEFAULT_INTEGRATIONS

sentry_sdk/consts.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ class EndpointType(Enum):
8585
]
8686

8787

88-
class INSTRUMENTER:
89-
SENTRY = "sentry"
90-
OTEL = "otel"
91-
92-
9388
class SPANDATA:
9489
"""
9590
Additional information describing the type of the span.
@@ -518,7 +513,6 @@ def __init__(
518513
send_client_reports=True, # type: bool
519514
_experiments={}, # type: Experiments # noqa: B006
520515
proxy_headers=None, # type: Optional[Dict[str, str]]
521-
instrumenter=INSTRUMENTER.SENTRY, # type: Optional[str]
522516
before_send_transaction=None, # type: Optional[TransactionProcessor]
523517
project_root=None, # type: Optional[str]
524518
enable_tracing=None, # type: Optional[bool]

sentry_sdk/hub.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import warnings
2+
3+
# Importing sentry_sdk.consts here prevents a circular import, even though it's not used in this file.
4+
import sentry_sdk.consts # noqa: F401
5+
26
from contextlib import contextmanager
37

48
from sentry_sdk._compat import with_metaclass
5-
from sentry_sdk.consts import INSTRUMENTER
69
from sentry_sdk.scope import Scope, _ScopeManager
710
from sentry_sdk.client import Client
811
from sentry_sdk.tracing import (
@@ -394,8 +397,8 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
394397
"""
395398
Scope.get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
396399

397-
def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
398-
# type: (str, Any) -> Span
400+
def start_span(self, **kwargs):
401+
# type: (Any) -> Span
399402
"""
400403
.. deprecated:: 2.0.0
401404
This function is deprecated and will be removed in a future release.
@@ -416,16 +419,12 @@ def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
416419
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
417420
"""
418421
scope = Scope.get_current_scope()
419-
return scope.start_span(instrumenter=instrumenter, **kwargs)
422+
return scope.start_span(**kwargs)
420423

421424
def start_transaction(
422-
self,
423-
transaction=None,
424-
instrumenter=INSTRUMENTER.SENTRY,
425-
custom_sampling_context=None,
426-
**kwargs
425+
self, transaction=None, custom_sampling_context=None, **kwargs
427426
):
428-
# type: (Optional[Transaction], str, Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
427+
# type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
429428
"""
430429
.. deprecated:: 2.0.0
431430
This function is deprecated and will be removed in a future release.
@@ -461,9 +460,7 @@ def start_transaction(
461460
# Type checking disabled for this line because deprecated keys are not allowed in the type signature.
462461
kwargs["hub"] = scope # type: ignore
463462

464-
return scope.start_transaction(
465-
transaction, instrumenter, custom_sampling_context, **kwargs
466-
)
463+
return scope.start_transaction(transaction, custom_sampling_context, **kwargs)
467464

468465
def continue_trace(self, environ_or_headers, op=None, name=None, source=None):
469466
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str]) -> Transaction

sentry_sdk/integrations/opentelemetry/span_processor.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
INVALID_TRACE_ID,
1515
)
1616
from sentry_sdk import get_client, start_transaction
17-
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS
17+
from sentry_sdk.consts import SPANSTATUS
1818
from sentry_sdk.integrations.opentelemetry.consts import (
1919
SENTRY_BAGGAGE_KEY,
2020
SENTRY_TRACE_KEY,
@@ -40,11 +40,6 @@
4040

4141
def link_trace_context_to_error_event(event, otel_span_map):
4242
# type: (Event, dict[str, Union[Transaction, SentrySpan]]) -> Event
43-
client = get_client()
44-
45-
if client.options["instrumenter"] != INSTRUMENTER.OTEL:
46-
return event
47-
4843
if hasattr(event, "type") and event["type"] == "transaction":
4944
return event
5045

@@ -117,9 +112,6 @@ def on_start(self, otel_span, parent_context=None):
117112
if not client.dsn:
118113
return
119114

120-
if client.options["instrumenter"] != INSTRUMENTER.OTEL:
121-
return
122-
123115
if not otel_span.get_span_context().is_valid:
124116
return
125117

@@ -145,7 +137,6 @@ def on_start(self, otel_span, parent_context=None):
145137
span_id=trace_data["span_id"],
146138
description=otel_span.name,
147139
start_timestamp=start_timestamp,
148-
instrumenter=INSTRUMENTER.OTEL,
149140
origin=SPAN_ORIGIN,
150141
)
151142
else:
@@ -156,7 +147,6 @@ def on_start(self, otel_span, parent_context=None):
156147
trace_id=trace_data["trace_id"],
157148
baggage=trace_data["baggage"],
158149
start_timestamp=start_timestamp,
159-
instrumenter=INSTRUMENTER.OTEL,
160150
origin=SPAN_ORIGIN,
161151
)
162152

@@ -174,11 +164,6 @@ def on_start(self, otel_span, parent_context=None):
174164

175165
def on_end(self, otel_span):
176166
# type: (OTelSpan) -> None
177-
client = get_client()
178-
179-
if client.options["instrumenter"] != INSTRUMENTER.OTEL:
180-
return
181-
182167
span_context = otel_span.get_span_context()
183168
if not span_context.is_valid:
184169
return

sentry_sdk/scope.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from itertools import chain
1010

1111
from sentry_sdk.attachments import Attachment
12-
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS, FALSE_VALUES, INSTRUMENTER
12+
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS, FALSE_VALUES
1313
from sentry_sdk.profiler.continuous_profiler import try_autostart_continuous_profiler
1414
from sentry_sdk.profiler.transaction_profiler import Profile
1515
from sentry_sdk.session import Session
@@ -956,13 +956,9 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
956956
self._breadcrumbs.popleft()
957957

958958
def start_transaction(
959-
self,
960-
transaction=None,
961-
instrumenter=INSTRUMENTER.SENTRY,
962-
custom_sampling_context=None,
963-
**kwargs
959+
self, transaction=None, custom_sampling_context=None, **kwargs
964960
):
965-
# type: (Optional[Transaction], str, Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
961+
# type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
966962
"""
967963
Start and return a transaction.
968964
@@ -987,8 +983,6 @@ def start_transaction(
987983
988984
:param transaction: The transaction to start. If omitted, we create and
989985
start a new transaction.
990-
:param instrumenter: This parameter is meant for internal use only. It
991-
will be removed in the next major version.
992986
:param custom_sampling_context: The transaction's custom sampling context.
993987
:param kwargs: Optional keyword arguments to be passed to the Transaction
994988
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
@@ -998,11 +992,6 @@ def start_transaction(
998992

999993
client = Scope.get_client()
1000994

1001-
configuration_instrumenter = client.options["instrumenter"]
1002-
1003-
if instrumenter != configuration_instrumenter:
1004-
return NoOpSpan()
1005-
1006995
try_autostart_continuous_profiler()
1007996

1008997
custom_sampling_context = custom_sampling_context or {}
@@ -1039,8 +1028,8 @@ def start_transaction(
10391028

10401029
return transaction
10411030

1042-
def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
1043-
# type: (str, Any) -> Span
1031+
def start_span(self, **kwargs):
1032+
# type: (Any) -> Span
10441033
"""
10451034
Start a span whose parent is the currently active span or transaction, if any.
10461035
@@ -1063,13 +1052,6 @@ def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
10631052
with new_scope():
10641053
kwargs.setdefault("scope", self)
10651054

1066-
client = Scope.get_client()
1067-
1068-
configuration_instrumenter = client.options["instrumenter"]
1069-
1070-
if instrumenter != configuration_instrumenter:
1071-
return NoOpSpan()
1072-
10731055
# get current span or transaction
10741056
span = self.span or Scope.get_isolation_scope().span
10751057

sentry_sdk/tracing.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import datetime, timedelta, timezone
55

66
import sentry_sdk
7-
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA
7+
from sentry_sdk.consts import SPANSTATUS, SPANDATA
88
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
99
from sentry_sdk.utils import (
1010
get_current_thread_meta,
@@ -386,8 +386,8 @@ def containing_transaction(self):
386386
# referencing themselves)
387387
return self._containing_transaction
388388

389-
def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
390-
# type: (str, **Any) -> Span
389+
def start_child(self, **kwargs):
390+
# type: (**Any) -> Span
391391
"""
392392
Start a sub-span from the current span or transaction.
393393
@@ -399,13 +399,6 @@ def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
399399
be removed in the next major version. Going forward, it should only
400400
be used by the SDK itself.
401401
"""
402-
configuration_instrumenter = sentry_sdk.Scope.get_client().options[
403-
"instrumenter"
404-
]
405-
406-
if instrumenter != configuration_instrumenter:
407-
return NoOpSpan()
408-
409402
kwargs.setdefault("sampled", self.sampled)
410403

411404
child = Span(
@@ -1157,8 +1150,8 @@ def containing_transaction(self):
11571150
# type: () -> Optional[Transaction]
11581151
return None
11591152

1160-
def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
1161-
# type: (str, **Any) -> NoOpSpan
1153+
def start_child(self, **kwargs):
1154+
# type: (**Any) -> NoOpSpan
11621155
return NoOpSpan()
11631156

11641157
def to_traceparent(self):

tests/integrations/opentelemetry/test_span_processor.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def test_is_sentry_span():
2222
assert not is_sentry_span(otel_span)
2323

2424
client = MagicMock()
25-
client.options = {"instrumenter": "otel"}
2625
client.dsn = "https://[email protected]/123456"
2726
Scope.get_global_scope().set_client(client)
2827

@@ -305,7 +304,6 @@ def test_on_start_transaction():
305304
fake_start_transaction = MagicMock()
306305

307306
fake_client = MagicMock()
308-
fake_client.options = {"instrumenter": "otel"}
309307
fake_client.dsn = "https://[email protected]/123456"
310308
Scope.get_global_scope().set_client(fake_client)
311309

@@ -325,7 +323,6 @@ def test_on_start_transaction():
325323
start_timestamp=datetime.fromtimestamp(
326324
otel_span.start_time / 1e9, timezone.utc
327325
),
328-
instrumenter="otel",
329326
origin="auto.otel",
330327
)
331328

@@ -349,7 +346,6 @@ def test_on_start_child():
349346
parent_context = {}
350347

351348
fake_client = MagicMock()
352-
fake_client.options = {"instrumenter": "otel"}
353349
fake_client.dsn = "https://[email protected]/123456"
354350
Scope.get_global_scope().set_client(fake_client)
355351

@@ -365,7 +361,6 @@ def test_on_start_child():
365361
start_timestamp=datetime.fromtimestamp(
366362
otel_span.start_time / 1e9, timezone.utc
367363
),
368-
instrumenter="otel",
369364
origin="auto.otel",
370365
)
371366

@@ -415,7 +410,6 @@ def test_on_end_sentry_transaction():
415410
otel_span.get_span_context.return_value = span_context
416411

417412
fake_client = MagicMock()
418-
fake_client.options = {"instrumenter": "otel"}
419413
Scope.get_global_scope().set_client(fake_client)
420414

421415
fake_sentry_span = MagicMock(spec=Transaction)
@@ -451,7 +445,6 @@ def test_on_end_sentry_span():
451445
otel_span.get_span_context.return_value = span_context
452446

453447
fake_client = MagicMock()
454-
fake_client.options = {"instrumenter": "otel"}
455448
Scope.get_global_scope().set_client(fake_client)
456449

457450
fake_sentry_span = MagicMock(spec=Span)
@@ -478,7 +471,6 @@ def test_link_trace_context_to_error_event():
478471
Test that the trace context is added to the error event.
479472
"""
480473
fake_client = MagicMock()
481-
fake_client.options = {"instrumenter": "otel"}
482474
Scope.get_global_scope().set_client(fake_client)
483475

484476
span_id = "1234567890abcdef"
@@ -535,7 +527,7 @@ def test_pruning_old_spans_on_start():
535527

536528
parent_context = {}
537529
fake_client = MagicMock()
538-
fake_client.options = {"instrumenter": "otel", "debug": False}
530+
fake_client.options = {"debug": False}
539531
fake_client.dsn = "https://[email protected]/123456"
540532
Scope.get_global_scope().set_client(fake_client)
541533

@@ -578,7 +570,6 @@ def test_pruning_old_spans_on_end():
578570
otel_span.parent.span_id = int("abcdef1234567890", 16)
579571

580572
fake_client = MagicMock()
581-
fake_client.options = {"instrumenter": "otel"}
582573
Scope.get_global_scope().set_client(fake_client)
583574

584575
fake_sentry_span = MagicMock(spec=Span)

0 commit comments

Comments
 (0)