diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index 4a070936a4..0b88ea3274 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -336,10 +336,8 @@ def get_baggage(): return None -def continue_trace( - environ_or_headers, op=None, name=None, source=None, origin="manual" -): - # type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], str) -> Transaction +def continue_trace(environ_or_headers, op=None, name=None, source=None, origin=None): + # type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], Optional[str]) -> Transaction """ Sets the propagation context from environment or headers and returns a transaction. """ diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index b952da021d..426f7c4902 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -96,9 +96,9 @@ def __init__( unsafe_context_data=False, transaction_style="endpoint", mechanism_type="asgi", - span_origin="manual", + span_origin=None, ): - # type: (Any, bool, str, str, str) -> None + # type: (Any, bool, str, str, Optional[str]) -> None """ Instrument an ASGI application with Sentry. Provides HTTP/websocket data to sent events and basic handling for exceptions bubbling up diff --git a/sentry_sdk/integrations/opentelemetry/potel_span_processor.py b/sentry_sdk/integrations/opentelemetry/potel_span_processor.py index ebb5bbc17a..d90ac7d5e4 100644 --- a/sentry_sdk/integrations/opentelemetry/potel_span_processor.py +++ b/sentry_sdk/integrations/opentelemetry/potel_span_processor.py @@ -5,6 +5,7 @@ from opentelemetry.sdk.trace import Span, ReadableSpan, SpanProcessor from sentry_sdk import capture_event +from sentry_sdk.tracing import DEFAULT_SPAN_ORIGIN from sentry_sdk.integrations.opentelemetry.utils import ( is_sentry_span, convert_from_otel_timestamp, @@ -12,7 +13,6 @@ ) from sentry_sdk.integrations.opentelemetry.consts import ( OTEL_SENTRY_CONTEXT, - SPAN_ORIGIN, ) from sentry_sdk._types import TYPE_CHECKING @@ -121,7 +121,7 @@ def _root_span_to_transaction_event(self, span): trace_context = { "trace_id": trace_id, "span_id": span_id, - "origin": origin, + "origin": origin or DEFAULT_SPAN_ORIGIN, "op": op, "status": status, } # type: dict[str, Any] @@ -170,7 +170,7 @@ def _span_to_json(self, span): "status": status, "start_timestamp": convert_from_otel_timestamp(span.start_time), "timestamp": convert_from_otel_timestamp(span.end_time), - "origin": origin or SPAN_ORIGIN, + "origin": origin or DEFAULT_SPAN_ORIGIN, } # type: dict[str, Any] if parent_span_id: diff --git a/sentry_sdk/integrations/wsgi.py b/sentry_sdk/integrations/wsgi.py index 7a95611d78..9ea83a629c 100644 --- a/sentry_sdk/integrations/wsgi.py +++ b/sentry_sdk/integrations/wsgi.py @@ -67,8 +67,8 @@ def get_request_url(environ, use_x_forwarded_for=False): class SentryWsgiMiddleware: __slots__ = ("app", "use_x_forwarded_for", "span_origin") - def __init__(self, app, use_x_forwarded_for=False, span_origin="manual"): - # type: (Callable[[Dict[str, str], Callable[..., Any]], Any], bool, str) -> None + def __init__(self, app, use_x_forwarded_for=False, span_origin=None): + # type: (Callable[[Dict[str, str], Callable[..., Any]], Any], bool, Optional[str]) -> None self.app = app self.use_x_forwarded_for = use_x_forwarded_for self.span_origin = span_origin diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 740a7c7f4b..eceee4d391 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -1056,9 +1056,9 @@ def start_span(self, span=None, custom_sampling_context=None, **kwargs): return span def continue_trace( - self, environ_or_headers, op=None, name=None, source=None, origin="manual" + self, environ_or_headers, op=None, name=None, source=None, origin=None ): - # type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], str) -> Transaction + # type: (Dict[str, Any], Optional[str], Optional[str], Optional[str], Optional[str]) -> Transaction """ Sets the propagation context from environment or headers and returns a transaction. """ diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index ab6aeb4508..bf17daa3d0 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -153,6 +153,8 @@ class TransactionKwargs(SpanKwargs, total=False): "url": TRANSACTION_SOURCE_ROUTE, } +DEFAULT_SPAN_ORIGIN = "manual" + tracer = otel_trace.get_tracer(__name__) @@ -282,7 +284,7 @@ def __init__( containing_transaction=None, # type: Optional[Transaction] start_timestamp=None, # type: Optional[Union[datetime, float]] scope=None, # type: Optional[sentry_sdk.Scope] - origin="manual", # type: str + origin=None, # type: Optional[str] ): # type: (...) -> None self.trace_id = trace_id or uuid.uuid4().hex @@ -295,7 +297,7 @@ def __init__( self.status = status self.hub = hub # backwards compatibility self.scope = scope - self.origin = origin + self.origin = origin or DEFAULT_SPAN_ORIGIN self._measurements = {} # type: Dict[str, MeasurementValue] self._tags = {} # type: MutableMapping[str, str] self._data = {} # type: Dict[str, Any] @@ -1266,7 +1268,7 @@ def __init__( status=None, # type: Optional[str] scope=None, # type: Optional[Scope] start_timestamp=None, # type: Optional[Union[datetime, float]] - origin="manual", # type: str + origin=None, # type: Optional[str] **_, # type: dict[str, object] ): # type: (...) -> None @@ -1290,7 +1292,7 @@ def __init__( ) # XXX self._active = active - self._otel_span.set_attribute(SentrySpanAttribute.ORIGIN, origin) + self.origin = origin or DEFAULT_SPAN_ORIGIN self.op = op self.description = description if status is not None: diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index a39b5d61f4..aa34398884 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -112,7 +112,7 @@ def record_sql_queries( paramstyle, # type: Optional[str] executemany, # type: bool record_cursor_repr=False, # type: bool - span_origin="manual", # type: str + span_origin=None, # type: Optional[str] ): # type: (...) -> Generator[sentry_sdk.tracing.Span, None, None]