Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.sessions import track_session
from sentry_sdk.traces import (
SegmentNameSource,
Span,
SpanStatus,
)
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
SENTRY_TRACE_HEADER_NAME,
SOURCE_FOR_STYLE,
SegmentNameSource,
Span,
SpanStatus,
)
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
Expand Down
22 changes: 8 additions & 14 deletions sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.sessions import track_session
from sentry_sdk.traces import (
SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE,
)
from sentry_sdk.traces import (
SOURCE_FOR_STYLE,
SegmentNameSource,
Span,
)
from sentry_sdk.tracing import (
SOURCE_FOR_STYLE,
TransactionSource,
)
from sentry_sdk.utils import (
_get_installed_modules,
capture_internal_exceptions,
Expand Down Expand Up @@ -354,9 +348,9 @@ def event_processor(
and transaction != _DEFAULT_TRANSACTION_NAME
and transaction_source
in [
TransactionSource.COMPONENT,
TransactionSource.ROUTE,
TransactionSource.CUSTOM,
SegmentNameSource.COMPONENT,
SegmentNameSource.ROUTE,
SegmentNameSource.CUSTOM,
]
)
if not already_set:
Expand Down Expand Up @@ -397,7 +391,7 @@ def _get_transaction_name_and_source(
asgi_scope=asgi_scope, root_path_in_path=self.root_path_in_path
),
)
source = TransactionSource.URL
source = SegmentNameSource.URL

elif transaction_style == "url":
# FastAPI includes the route object in the scope to let Sentry extract the
Expand All @@ -416,11 +410,11 @@ def _get_transaction_name_and_source(
asgi_scope=asgi_scope, root_path_in_path=self.root_path_in_path
),
)
source = TransactionSource.URL
source = SegmentNameSource.URL

if name is None:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE
source = SegmentNameSource.ROUTE
return name, source

return name, source
Expand All @@ -429,7 +423,7 @@ def _get_segment_name_and_source(
self: "SentryAsgiMiddleware", segment_style: str, asgi_scope: "Any"
) -> "Tuple[str, str]":
name = None
source = SEGMENT_SOURCE_FOR_STYLE[segment_style].value
source = SOURCE_FOR_STYLE[segment_style].value
ty = asgi_scope.get("type")

if segment_style == "endpoint":
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.traces import Span
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
from sentry_sdk.traces import BAGGAGE_HEADER_NAME, Span
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_sentry_baggage_to_headers,
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import Scope, should_send_default_pii
from sentry_sdk.traces import SegmentNameSource, Span
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
from sentry_sdk.traces import BAGGAGE_HEADER_NAME, SegmentNameSource, Span
from sentry_sdk.tracing_utils import Baggage
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import add_global_event_processor, should_send_default_pii
from sentry_sdk.serializer import add_global_repr_processor, add_repr_sequence_type
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.traces import SOURCE_FOR_STYLE, SegmentNameSource
from sentry_sdk.tracing_utils import (
add_query_source,
record_sql_queries,
Expand Down Expand Up @@ -405,7 +405,7 @@ def _set_transaction_name_and_source(

if transaction_name is None:
transaction_name = request.path_info
source = TransactionSource.URL
source = SegmentNameSource.URL
else:
source = SOURCE_FOR_STYLE[transaction_style]

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/dramatiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations._wsgi_common import request_body_within_bounds
from sentry_sdk.traces import SegmentNameSource
from sentry_sdk.tracing import (
from sentry_sdk.traces import (
BAGGAGE_HEADER_NAME,
SENTRY_TRACE_HEADER_NAME,
SegmentNameSource,
)
from sentry_sdk.utils import (
AnnotatedValue,
Expand Down
10 changes: 7 additions & 3 deletions sentry_sdk/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import sentry_sdk
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations import DidNotEnable, _check_minimum_version
from sentry_sdk.traces import Span, get_current_span
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.traces import (
SOURCE_FOR_STYLE,
SegmentNameSource,
Span,
get_current_span,
)
from sentry_sdk.utils import (
has_data_collection_enabled,
parse_version,
Expand Down Expand Up @@ -72,7 +76,7 @@ def _set_transaction_name_and_source(

if not name:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE
source = SegmentNameSource.ROUTE
else:
source = SOURCE_FOR_STYLE[transaction_style]

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE
from sentry_sdk.traces import SOURCE_FOR_STYLE
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down
6 changes: 4 additions & 2 deletions sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import SegmentNameSource, Span, SpanStatus
from sentry_sdk.tracing import (
from sentry_sdk.traces import (
BAGGAGE_HEADER_NAME,
SENTRY_TRACE_HEADER_NAME,
SegmentNameSource,
Span,
SpanStatus,
)
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.integrations.logging import ignore_logger_for_events
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.traces import SOURCE_FOR_STYLE, SegmentNameSource
from sentry_sdk.utils import (
ensure_integration_enabled,
event_from_exception,
Expand Down Expand Up @@ -272,7 +272,7 @@ async def handle_wrapper(

if not name:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE
source = SegmentNameSource.ROUTE

sentry_sdk.set_transaction_name(name, source)
sentry_scope.set_transaction_name(name, source)
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/openai_agents/patches/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import sentry_sdk
from sentry_sdk.consts import SPANDATA
from sentry_sdk.integrations import DidNotEnable
from sentry_sdk.traces import Span
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
from sentry_sdk.traces import BAGGAGE_HEADER_NAME, Span
from sentry_sdk.tracing_utils import (
add_sentry_baggage_to_headers,
should_propagate_trace,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/otlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sentry_sdk.consts import VERSION, EndpointType
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import register_external_propagation_context
from sentry_sdk.tracing import (
from sentry_sdk.traces import (
BAGGAGE_HEADER_NAME,
SENTRY_TRACE_HEADER_NAME,
)
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from sentry_sdk.integrations._wsgi_common import RequestExtractor, _filter_headers
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import SegmentNameSource
from sentry_sdk.tracing import TransactionSource
from sentry_sdk.utils import (
capture_internal_exceptions,
ensure_integration_enabled,
Expand Down Expand Up @@ -189,7 +188,7 @@ async def _set_transaction(request: "Request", route: "Route", **_: "Any") -> No
with capture_internal_exceptions():
scope = sentry_sdk.get_current_scope()
route_name = route.name.replace(request.app.name, "").strip(".")
scope.set_transaction_name(route_name, source=TransactionSource.COMPONENT)
scope.set_transaction_name(route_name, source=SegmentNameSource.COMPONENT)


def _sentry_error_handler_lookup(
Expand Down
30 changes: 13 additions & 17 deletions sentry_sdk/integrations/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
)
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import Span
from sentry_sdk.tracing import (
SOURCE_FOR_STYLE,
TransactionSource,
)
from sentry_sdk.traces import SOURCE_FOR_STYLE, SegmentNameSource, Span
from sentry_sdk.utils import (
AnnotatedValue,
capture_internal_exceptions,
Expand Down Expand Up @@ -162,7 +158,7 @@ async def _create_span_call(
if (
server_span is not None
and route_path is not None
and name_source == TransactionSource.ROUTE
and name_source == SegmentNameSource.ROUTE
):
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)

Expand Down Expand Up @@ -516,7 +512,7 @@ async def _wrap_async_handler(
if (
server_span is not None
and route_path is not None
and name_source == TransactionSource.ROUTE
and name_source == SegmentNameSource.ROUTE
):
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)

Expand Down Expand Up @@ -628,7 +624,7 @@ def _sentry_sync_func(*args: "Any", **kwargs: "Any") -> "Any":
if (
server_span is not None
and route_path is not None
and name_source == TransactionSource.ROUTE
and name_source == SegmentNameSource.ROUTE
):
server_span.set_attribute(SPANDATA.HTTP_ROUTE, route_path)

Expand Down Expand Up @@ -832,30 +828,30 @@ async def json(self: "StarletteRequestExtractor") -> "Optional[Dict[str, Any]]":

def _http_route_and_source_from_router(
scope: "StarletteScope",
) -> "Tuple[Optional[str], TransactionSource]":
) -> "Tuple[Optional[str], SegmentNameSource]":
router = scope.get("router")
if not router:
return None, TransactionSource.ROUTE
return None, SegmentNameSource.ROUTE

for route in router.routes:
match = route.matches(scope)
if match[0] == Match.FULL:
try:
return route.path, TransactionSource.ROUTE
return route.path, SegmentNameSource.ROUTE
except AttributeError:
# Host routes have no path template, so fall back to the
# concrete request path and classify it as a URL.
return scope.get("path"), TransactionSource.URL
return scope.get("path"), SegmentNameSource.URL

return None, TransactionSource.ROUTE
return None, SegmentNameSource.ROUTE


def _set_transaction_name_and_source(
scope: "sentry_sdk.Scope",
transaction_style: str,
endpoint: "Optional[Callable[..., Any]]",
route_path: "Optional[str]",
name_source: "TransactionSource",
name_source: "SegmentNameSource",
) -> None:
name = None
source = SOURCE_FOR_STYLE[transaction_style]
Expand All @@ -868,7 +864,7 @@ def _set_transaction_name_and_source(

if name is None:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE
source = SegmentNameSource.ROUTE

scope.set_transaction_name(name, source=source)

Expand All @@ -877,14 +873,14 @@ def _get_transaction_from_middleware(
app: "Any",
integration: "StarletteIntegration",
route_path: "Optional[str]",
name_source: "TransactionSource",
name_source: "SegmentNameSource",
) -> "Tuple[Optional[str], Optional[str]]":
name = None
source = None

if integration.transaction_style == "endpoint":
name = transaction_from_function(app.__class__)
source = TransactionSource.COMPONENT
source = SegmentNameSource.COMPONENT
elif integration.transaction_style == "url":
name, source = route_path, name_source

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/starlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing import SOURCE_FOR_STYLE, TransactionSource
from sentry_sdk.traces import SOURCE_FOR_STYLE, SegmentNameSource
from sentry_sdk.utils import (
ensure_integration_enabled,
event_from_exception,
Expand Down Expand Up @@ -247,7 +247,7 @@ async def handle_wrapper(

if not name:
name = _DEFAULT_TRANSACTION_NAME
source = TransactionSource.ROUTE
source = SegmentNameSource.ROUTE

sentry_sdk.set_transaction_name(name, source)
sentry_scope.set_transaction_name(name, source)
Expand Down
3 changes: 1 addition & 2 deletions sentry_sdk/integrations/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from sentry_sdk.consts import _SENTRY_HEADER_NAMES, OP, SPANDATA
from sentry_sdk.integrations import Integration
from sentry_sdk.scope import add_global_event_processor
from sentry_sdk.traces import Span
from sentry_sdk.tracing import SENTRY_TRACE_HEADER_NAME
from sentry_sdk.traces import SENTRY_TRACE_HEADER_NAME, Span
from sentry_sdk.tracing_utils import (
EnvironHeaders,
add_http_breadcrumb,
Expand Down
6 changes: 2 additions & 4 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
from sentry_sdk.session import Session
from sentry_sdk.traces import (
_DEFAULT_PARENT_SPAN,
NoOpSpan,
Span,
)
from sentry_sdk.tracing import (
BAGGAGE_HEADER_NAME,
SENTRY_TRACE_HEADER_NAME,
NoOpSpan,
Span,
)
from sentry_sdk.tracing_utils import (
Baggage,
Expand Down
Loading
Loading