Skip to content

Commit

Permalink
Cleanup origin handling and defaults (#3445)
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py authored Aug 13, 2024
1 parent 5ccfb34 commit c764ebe
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
6 changes: 2 additions & 4 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/opentelemetry/potel_span_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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,
extract_span_data,
)
from sentry_sdk.integrations.opentelemetry.consts import (
OTEL_SENTRY_CONTEXT,
SPAN_ORIGIN,
)
from sentry_sdk._types import TYPE_CHECKING

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
10 changes: 6 additions & 4 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class TransactionKwargs(SpanKwargs, total=False):
"url": TRANSACTION_SOURCE_ROUTE,
}

DEFAULT_SPAN_ORIGIN = "manual"

tracer = otel_trace.get_tracer(__name__)


Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit c764ebe

Please sign in to comment.