Skip to content

Commit 9996734

Browse files
Lms24ericapisani
andauthored
feat(tracing): Send sentry.segment.name.source instead of sentry.span.source attribute (#6835)
Following the [deprecation](https://getsentry.github.io/sentry-conventions/attributes/sentry/#sentry-span-source) of `sentry.span.source`, this PR renames the attribute from `sentry.span.source` to [`sentry.segment.name.source`](https://getsentry.github.io/sentry-conventions/attributes/sentry/#sentry-segment-name-source). --------- Co-authored-by: Erica Pisani <hey@ericapisani.dev>
1 parent 00224f7 commit 9996734

42 files changed

Lines changed: 122 additions & 103 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sentry_sdk/integrations/aiohttp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from sentry_sdk.traces import (
2525
NoOpStreamedSpan,
26-
SegmentSource,
26+
SegmentNameSource,
2727
SpanStatus,
2828
StreamedSpan,
2929
)
@@ -185,7 +185,7 @@ async def sentry_app_handle(
185185
attributes={
186186
"sentry.op": OP.HTTP_SERVER,
187187
"sentry.origin": AioHttpIntegration.origin,
188-
"sentry.span.source": SegmentSource.ROUTE.value,
188+
"sentry.segment.name.source": SegmentNameSource.ROUTE.value,
189189
"http.request.method": request.method,
190190
**url_attributes,
191191
**client_address_attributes,
@@ -302,7 +302,7 @@ async def sentry_urldispatcher_resolve(
302302
):
303303
current_span._segment.name = name
304304
current_span._segment.set_attribute(
305-
"sentry.span.source",
305+
"sentry.segment.name.source",
306306
SEGMENT_SOURCE_FOR_STYLE[integration.transaction_style].value,
307307
)
308308
else:

sentry_sdk/integrations/arq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
66
from sentry_sdk.integrations.logging import ignore_logger
77
from sentry_sdk.scope import should_send_default_pii
8-
from sentry_sdk.traces import SegmentSource
8+
from sentry_sdk.traces import SegmentNameSource
99
from sentry_sdk.tracing import Transaction, TransactionSource
1010
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1111
from sentry_sdk.utils import (
@@ -118,7 +118,7 @@ async def _sentry_run_job(self: "Worker", job_id: str, score: int) -> None:
118118
attributes={
119119
"sentry.op": OP.QUEUE_TASK_ARQ,
120120
"sentry.origin": ArqIntegration.origin,
121-
"sentry.span.source": SegmentSource.TASK,
121+
"sentry.segment.name.source": SegmentNameSource.TASK,
122122
SPANDATA.MESSAGING_MESSAGE_ID: job_id,
123123
},
124124
parent_span=None,

sentry_sdk/integrations/asgi.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE,
3232
)
3333
from sentry_sdk.traces import (
34-
SegmentSource,
34+
SegmentNameSource,
3535
StreamedSpan,
3636
)
3737
from sentry_sdk.tracing import (
@@ -246,7 +246,7 @@ async def _run_app(
246246
if span_streaming:
247247
segment: "Optional[StreamedSpan]" = None
248248
attributes: "Attributes" = {
249-
"sentry.span.source": getattr(
249+
"sentry.segment.name.source": getattr(
250250
transaction_source, "value", transaction_source
251251
),
252252
"sentry.origin": self.span_origin,
@@ -384,11 +384,13 @@ async def _sentry_wrapped_send(
384384
already_set = (
385385
span is not None
386386
and span.name != _DEFAULT_TRANSACTION_NAME
387-
and span.get_attributes().get("sentry.span.source")
387+
and span.get_attributes().get(
388+
"sentry.segment.name.source"
389+
)
388390
in [
389-
SegmentSource.COMPONENT.value,
390-
SegmentSource.ROUTE.value,
391-
SegmentSource.CUSTOM.value,
391+
SegmentNameSource.COMPONENT.value,
392+
SegmentNameSource.ROUTE.value,
393+
SegmentNameSource.CUSTOM.value,
392394
]
393395
)
394396
with capture_internal_exceptions():
@@ -399,7 +401,9 @@ async def _sentry_wrapped_send(
399401
)
400402
)
401403
span.name = name
402-
span.set_attribute("sentry.span.source", source)
404+
span.set_attribute(
405+
"sentry.segment.name.source", source
406+
)
403407
finally:
404408
_asgi_middleware_applied.set(False)
405409

@@ -514,7 +518,7 @@ def _get_segment_name_and_source(
514518
asgi_scope=asgi_scope, root_path_in_path=self.root_path_in_path
515519
),
516520
)
517-
source = SegmentSource.URL.value
521+
source = SegmentNameSource.URL.value
518522

519523
elif segment_style == "url":
520524
# FastAPI includes the route object in the scope to let Sentry extract the
@@ -533,11 +537,11 @@ def _get_segment_name_and_source(
533537
asgi_scope=asgi_scope, root_path_in_path=self.root_path_in_path
534538
),
535539
)
536-
source = SegmentSource.URL.value
540+
source = SegmentNameSource.URL.value
537541

538542
if name is None:
539543
name = _DEFAULT_TRANSACTION_NAME
540-
source = SegmentSource.ROUTE.value
544+
source = SegmentNameSource.ROUTE.value
541545
return name, source
542546

543547
return name, source

sentry_sdk/integrations/aws_lambda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
CLOUD_PROVIDER,
1919
)
2020
from sentry_sdk.scope import Scope, should_send_default_pii
21-
from sentry_sdk.traces import SegmentSource
21+
from sentry_sdk.traces import SegmentNameSource
2222
from sentry_sdk.tracing import TransactionSource
2323
from sentry_sdk.tracing_utils import has_span_streaming_enabled
2424
from sentry_sdk.utils import (
@@ -185,7 +185,7 @@ def sentry_handler(
185185
attributes={
186186
"sentry.op": OP.FUNCTION_AWS,
187187
"sentry.origin": AwsLambdaIntegration.origin,
188-
"sentry.span.source": SegmentSource.COMPONENT,
188+
"sentry.segment.name.source": SegmentNameSource.COMPONENT,
189189
"cloud.region": aws_region,
190190
"cloud.resource_id": aws_context.invoked_function_arn,
191191
"cloud.platform": CLOUD_PLATFORM.AWS_LAMBDA,

sentry_sdk/integrations/celery/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
1717
from sentry_sdk.integrations.logging import ignore_logger
1818
from sentry_sdk.scope import Scope, should_send_default_pii
19-
from sentry_sdk.traces import StreamedSpan, get_current_span
19+
from sentry_sdk.traces import SegmentNameSource, StreamedSpan, get_current_span
2020
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span, TransactionSource
2121
from sentry_sdk.tracing_utils import Baggage, has_span_streaming_enabled
2222
from sentry_sdk.utils import (
@@ -361,7 +361,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
361361
parent_span=None, # make this a segment
362362
attributes={
363363
"sentry.origin": CeleryIntegration.origin,
364-
"sentry.span.source": TransactionSource.TASK.value,
364+
"sentry.segment.name.source": SegmentNameSource.TASK.value,
365365
"sentry.op": OP.QUEUE_TASK_CELERY,
366366
},
367367
)

sentry_sdk/integrations/dramatiq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
77
from sentry_sdk.integrations import DidNotEnable, Integration
88
from sentry_sdk.integrations._wsgi_common import request_body_within_bounds
9-
from sentry_sdk.traces import SegmentSource
9+
from sentry_sdk.traces import SegmentNameSource
1010
from sentry_sdk.tracing import (
1111
BAGGAGE_HEADER_NAME,
1212
SENTRY_TRACE_HEADER_NAME,
@@ -139,7 +139,7 @@ def before_process_message(self, broker: "Broker", message: "Message[R]") -> Non
139139
attributes={
140140
"sentry.op": OP.QUEUE_TASK_DRAMATIQ,
141141
"sentry.origin": DramatiqIntegration.origin,
142-
"sentry.span.source": SegmentSource.TASK.value,
142+
"sentry.segment.name.source": SegmentNameSource.TASK.value,
143143
SPANDATA.MESSAGING_DESTINATION_NAME: message.queue_name,
144144
},
145145
parent_span=None,

sentry_sdk/integrations/gcp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sentry_sdk.integrations._wsgi_common import _filter_headers
1313
from sentry_sdk.integrations.cloud_resource_context import CLOUD_PROVIDER
1414
from sentry_sdk.scope import Scope, should_send_default_pii
15-
from sentry_sdk.traces import SegmentSource
15+
from sentry_sdk.traces import SegmentNameSource
1616
from sentry_sdk.tracing import TransactionSource
1717
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1818
from sentry_sdk.utils import (
@@ -138,7 +138,7 @@ def sentry_func(
138138
attributes={
139139
"sentry.op": OP.FUNCTION_GCP,
140140
"sentry.origin": GcpIntegration.origin,
141-
"sentry.span.source": SegmentSource.COMPONENT,
141+
"sentry.segment.name.source": SegmentNameSource.COMPONENT,
142142
"cloud.provider": CLOUD_PROVIDER.GCP,
143143
"faas.name": function_name,
144144
**header_attributes,

sentry_sdk/integrations/grpc/aio/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry_sdk.consts import OP
55
from sentry_sdk.integrations import DidNotEnable
66
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN
7-
from sentry_sdk.traces import SegmentSource
7+
from sentry_sdk.traces import SegmentNameSource
88
from sentry_sdk.tracing import TransactionSource
99
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1010
from sentry_sdk.utils import event_from_exception
@@ -67,7 +67,7 @@ async def wrapped(request: "Any", context: "ServicerContext") -> "Any":
6767
name=name,
6868
attributes={
6969
"sentry.op": OP.GRPC_SERVER,
70-
"sentry.span.source": SegmentSource.CUSTOM.value,
70+
"sentry.segment.name.source": SegmentNameSource.CUSTOM.value,
7171
"sentry.origin": SPAN_ORIGIN,
7272
},
7373
parent_span=None,

sentry_sdk/integrations/grpc/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from sentry_sdk.consts import OP
55
from sentry_sdk.integrations import DidNotEnable
66
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN
7-
from sentry_sdk.traces import SegmentSource
7+
from sentry_sdk.traces import SegmentNameSource
88
from sentry_sdk.tracing import TransactionSource
99
from sentry_sdk.tracing_utils import has_span_streaming_enabled
1010

@@ -58,7 +58,7 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message":
5858
name=name,
5959
attributes={
6060
"sentry.op": OP.GRPC_SERVER,
61-
"sentry.span.source": SegmentSource.CUSTOM.value,
61+
"sentry.segment.name.source": SegmentNameSource.CUSTOM.value,
6262
"sentry.origin": SPAN_ORIGIN,
6363
},
6464
parent_span=None,

sentry_sdk/integrations/huey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
88
from sentry_sdk.integrations import DidNotEnable, Integration
99
from sentry_sdk.scope import should_send_default_pii
10-
from sentry_sdk.traces import SegmentSource, SpanStatus, StreamedSpan
10+
from sentry_sdk.traces import SegmentNameSource, SpanStatus, StreamedSpan
1111
from sentry_sdk.tracing import (
1212
BAGGAGE_HEADER_NAME,
1313
SENTRY_TRACE_HEADER_NAME,
@@ -220,7 +220,7 @@ def _sentry_execute(
220220
attributes={
221221
"sentry.op": OP.QUEUE_TASK_HUEY,
222222
"sentry.origin": HueyIntegration.origin,
223-
"sentry.span.source": SegmentSource.TASK,
223+
"sentry.segment.name.source": SegmentNameSource.TASK,
224224
SPANDATA.MESSAGING_DESTINATION_NAME: self.name,
225225
"messaging.message.id": task.id,
226226
"messaging.message.system": "huey",

0 commit comments

Comments
 (0)