Skip to content

Commit

Permalink
feat(tracing): Remove instrumenter option
Browse files Browse the repository at this point in the history
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
  • Loading branch information
szokeasaurusrex committed Jul 23, 2024
1 parent 4428ee9 commit acd7cf2
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 142 deletions.
6 changes: 1 addition & 5 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from sentry_sdk import tracing_utils, Client
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.consts import INSTRUMENTER
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
from sentry_sdk.tracing import NoOpSpan, Transaction

Expand Down Expand Up @@ -293,7 +292,6 @@ def start_span(
@scopemethod
def start_transaction(
transaction=None, # type: Optional[Transaction]
instrumenter=INSTRUMENTER.SENTRY, # type: str
custom_sampling_context=None, # type: Optional[SamplingContext]
**kwargs, # type: Unpack[TransactionKwargs]
):
Expand Down Expand Up @@ -322,15 +320,13 @@ def start_transaction(
:param transaction: The transaction to start. If omitted, we create and
start a new transaction.
:param instrumenter: This parameter is meant for internal use only. It
will be removed in the next major version.
:param custom_sampling_context: The transaction's custom sampling context.
:param kwargs: Optional keyword arguments to be passed to the Transaction
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
available arguments.
"""
return Scope.get_current_scope().start_transaction(
transaction, instrumenter, custom_sampling_context, **kwargs
transaction, custom_sampling_context, **kwargs
)


Expand Down
5 changes: 0 additions & 5 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from sentry_sdk.consts import (
DEFAULT_MAX_VALUE_LENGTH,
DEFAULT_OPTIONS,
INSTRUMENTER,
VERSION,
ClientConstructor,
)
Expand Down Expand Up @@ -113,9 +112,6 @@ def _get_options(*args, **kwargs):
if rv["server_name"] is None and hasattr(socket, "gethostname"):
rv["server_name"] = socket.gethostname()

if rv["instrumenter"] is None:
rv["instrumenter"] = INSTRUMENTER.SENTRY

if rv["project_root"] is None:
try:
project_root = os.getcwd()
Expand Down Expand Up @@ -357,7 +353,6 @@ def _capture_envelope(envelope):
logger.debug(
"[OTel] Enabling experimental OTel-powered performance monitoring."
)
self.options["instrumenter"] = INSTRUMENTER.OTEL
if (
"sentry_sdk.integrations.opentelemetry.integration.OpenTelemetryIntegration"
not in _DEFAULT_INTEGRATIONS
Expand Down
6 changes: 0 additions & 6 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ class EndpointType(Enum):
]


class INSTRUMENTER:
SENTRY = "sentry"
OTEL = "otel"


class SPANDATA:
"""
Additional information describing the type of the span.
Expand Down Expand Up @@ -518,7 +513,6 @@ def __init__(
send_client_reports=True, # type: bool
_experiments={}, # type: Experiments # noqa: B006
proxy_headers=None, # type: Optional[Dict[str, str]]
instrumenter=INSTRUMENTER.SENTRY, # type: Optional[str]
before_send_transaction=None, # type: Optional[TransactionProcessor]
project_root=None, # type: Optional[str]
enable_tracing=None, # type: Optional[bool]
Expand Down
23 changes: 10 additions & 13 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import warnings

# Importing sentry_sdk.consts here prevents a circular import, even though it's not used in this file.
import sentry_sdk.consts # noqa: F401

from contextlib import contextmanager

from sentry_sdk._compat import with_metaclass
from sentry_sdk.consts import INSTRUMENTER
from sentry_sdk.scope import Scope, _ScopeManager
from sentry_sdk.client import Client
from sentry_sdk.tracing import (
Expand Down Expand Up @@ -394,8 +397,8 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
"""
Scope.get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)

def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
# type: (str, Any) -> Span
def start_span(self, **kwargs):
# type: (Any) -> Span
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Expand All @@ -416,16 +419,12 @@ def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`.
"""
scope = Scope.get_current_scope()
return scope.start_span(instrumenter=instrumenter, **kwargs)
return scope.start_span(**kwargs)

def start_transaction(
self,
transaction=None,
instrumenter=INSTRUMENTER.SENTRY,
custom_sampling_context=None,
**kwargs
self, transaction=None, custom_sampling_context=None, **kwargs
):
# type: (Optional[Transaction], str, Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
# type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
"""
.. deprecated:: 2.0.0
This function is deprecated and will be removed in a future release.
Expand Down Expand Up @@ -461,9 +460,7 @@ def start_transaction(
# Type checking disabled for this line because deprecated keys are not allowed in the type signature.
kwargs["hub"] = scope # type: ignore

return scope.start_transaction(
transaction, instrumenter, custom_sampling_context, **kwargs
)
return scope.start_transaction(transaction, custom_sampling_context, **kwargs)

def continue_trace(self, environ_or_headers, op=None, name=None, source=None):
# type: (Dict[str, Any], Optional[str], Optional[str], Optional[str]) -> Transaction
Expand Down
17 changes: 1 addition & 16 deletions sentry_sdk/integrations/opentelemetry/span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
INVALID_TRACE_ID,
)
from sentry_sdk import get_client, start_transaction
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS
from sentry_sdk.consts import SPANSTATUS
from sentry_sdk.integrations.opentelemetry.consts import (
SENTRY_BAGGAGE_KEY,
SENTRY_TRACE_KEY,
Expand All @@ -40,11 +40,6 @@

def link_trace_context_to_error_event(event, otel_span_map):
# type: (Event, dict[str, Union[Transaction, SentrySpan]]) -> Event
client = get_client()

if client.options["instrumenter"] != INSTRUMENTER.OTEL:
return event

if hasattr(event, "type") and event["type"] == "transaction":
return event

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

if client.options["instrumenter"] != INSTRUMENTER.OTEL:
return

if not otel_span.get_span_context().is_valid:
return

Expand All @@ -145,7 +137,6 @@ def on_start(self, otel_span, parent_context=None):
span_id=trace_data["span_id"],
description=otel_span.name,
start_timestamp=start_timestamp,
instrumenter=INSTRUMENTER.OTEL,
origin=SPAN_ORIGIN,
)
else:
Expand All @@ -156,7 +147,6 @@ def on_start(self, otel_span, parent_context=None):
trace_id=trace_data["trace_id"],
baggage=trace_data["baggage"],
start_timestamp=start_timestamp,
instrumenter=INSTRUMENTER.OTEL,
origin=SPAN_ORIGIN,
)

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

def on_end(self, otel_span):
# type: (OTelSpan) -> None
client = get_client()

if client.options["instrumenter"] != INSTRUMENTER.OTEL:
return

span_context = otel_span.get_span_context()
if not span_context.is_valid:
return
Expand Down
28 changes: 5 additions & 23 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from itertools import chain

from sentry_sdk.attachments import Attachment
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS, FALSE_VALUES, INSTRUMENTER
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS, FALSE_VALUES
from sentry_sdk.profiler.continuous_profiler import try_autostart_continuous_profiler
from sentry_sdk.profiler.transaction_profiler import Profile
from sentry_sdk.session import Session
Expand Down Expand Up @@ -956,13 +956,9 @@ def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
self._breadcrumbs.popleft()

def start_transaction(
self,
transaction=None,
instrumenter=INSTRUMENTER.SENTRY,
custom_sampling_context=None,
**kwargs
self, transaction=None, custom_sampling_context=None, **kwargs
):
# type: (Optional[Transaction], str, Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
# type: (Optional[Transaction], Optional[SamplingContext], Unpack[TransactionKwargs]) -> Union[Transaction, NoOpSpan]
"""
Start and return a transaction.
Expand All @@ -987,8 +983,6 @@ def start_transaction(
:param transaction: The transaction to start. If omitted, we create and
start a new transaction.
:param instrumenter: This parameter is meant for internal use only. It
will be removed in the next major version.
:param custom_sampling_context: The transaction's custom sampling context.
:param kwargs: Optional keyword arguments to be passed to the Transaction
constructor. See :py:class:`sentry_sdk.tracing.Transaction` for
Expand All @@ -998,11 +992,6 @@ def start_transaction(

client = Scope.get_client()

configuration_instrumenter = client.options["instrumenter"]

if instrumenter != configuration_instrumenter:
return NoOpSpan()

try_autostart_continuous_profiler()

custom_sampling_context = custom_sampling_context or {}
Expand Down Expand Up @@ -1039,8 +1028,8 @@ def start_transaction(

return transaction

def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
# type: (str, Any) -> Span
def start_span(self, **kwargs):
# type: (Any) -> Span
"""
Start a span whose parent is the currently active span or transaction, if any.
Expand All @@ -1063,13 +1052,6 @@ def start_span(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
with new_scope():
kwargs.setdefault("scope", self)

client = Scope.get_client()

configuration_instrumenter = client.options["instrumenter"]

if instrumenter != configuration_instrumenter:
return NoOpSpan()

# get current span or transaction
span = self.span or Scope.get_isolation_scope().span

Expand Down
17 changes: 5 additions & 12 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime, timedelta, timezone

import sentry_sdk
from sentry_sdk.consts import INSTRUMENTER, SPANSTATUS, SPANDATA
from sentry_sdk.consts import SPANSTATUS, SPANDATA
from sentry_sdk.profiler.continuous_profiler import get_profiler_id
from sentry_sdk.utils import (
get_current_thread_meta,
Expand Down Expand Up @@ -386,8 +386,8 @@ def containing_transaction(self):
# referencing themselves)
return self._containing_transaction

def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
# type: (str, **Any) -> Span
def start_child(self, **kwargs):
# type: (**Any) -> Span
"""
Start a sub-span from the current span or transaction.
Expand All @@ -399,13 +399,6 @@ def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
be removed in the next major version. Going forward, it should only
be used by the SDK itself.
"""
configuration_instrumenter = sentry_sdk.Scope.get_client().options[
"instrumenter"
]

if instrumenter != configuration_instrumenter:
return NoOpSpan()

kwargs.setdefault("sampled", self.sampled)

child = Span(
Expand Down Expand Up @@ -1157,8 +1150,8 @@ def containing_transaction(self):
# type: () -> Optional[Transaction]
return None

def start_child(self, instrumenter=INSTRUMENTER.SENTRY, **kwargs):
# type: (str, **Any) -> NoOpSpan
def start_child(self, **kwargs):
# type: (**Any) -> NoOpSpan
return NoOpSpan()

def to_traceparent(self):
Expand Down
11 changes: 1 addition & 10 deletions tests/integrations/opentelemetry/test_span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_is_sentry_span():
assert not is_sentry_span(otel_span)

client = MagicMock()
client.options = {"instrumenter": "otel"}
client.dsn = "https://1234567890abcdef@o123456.ingest.sentry.io/123456"
Scope.get_global_scope().set_client(client)

Expand Down Expand Up @@ -305,7 +304,6 @@ def test_on_start_transaction():
fake_start_transaction = MagicMock()

fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel"}
fake_client.dsn = "https://1234567890abcdef@o123456.ingest.sentry.io/123456"
Scope.get_global_scope().set_client(fake_client)

Expand All @@ -325,7 +323,6 @@ def test_on_start_transaction():
start_timestamp=datetime.fromtimestamp(
otel_span.start_time / 1e9, timezone.utc
),
instrumenter="otel",
origin="auto.otel",
)

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

fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel"}
fake_client.dsn = "https://1234567890abcdef@o123456.ingest.sentry.io/123456"
Scope.get_global_scope().set_client(fake_client)

Expand All @@ -365,7 +361,6 @@ def test_on_start_child():
start_timestamp=datetime.fromtimestamp(
otel_span.start_time / 1e9, timezone.utc
),
instrumenter="otel",
origin="auto.otel",
)

Expand Down Expand Up @@ -415,7 +410,6 @@ def test_on_end_sentry_transaction():
otel_span.get_span_context.return_value = span_context

fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel"}
Scope.get_global_scope().set_client(fake_client)

fake_sentry_span = MagicMock(spec=Transaction)
Expand Down Expand Up @@ -451,7 +445,6 @@ def test_on_end_sentry_span():
otel_span.get_span_context.return_value = span_context

fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel"}
Scope.get_global_scope().set_client(fake_client)

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

span_id = "1234567890abcdef"
Expand Down Expand Up @@ -535,7 +527,7 @@ def test_pruning_old_spans_on_start():

parent_context = {}
fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel", "debug": False}
fake_client.options = {"debug": False}
fake_client.dsn = "https://1234567890abcdef@o123456.ingest.sentry.io/123456"
Scope.get_global_scope().set_client(fake_client)

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

fake_client = MagicMock()
fake_client.options = {"instrumenter": "otel"}
Scope.get_global_scope().set_client(fake_client)

fake_sentry_span = MagicMock(spec=Span)
Expand Down
Loading

0 comments on commit acd7cf2

Please sign in to comment.