Skip to content

Commit bf7a4e6

Browse files
committed
feat(boto3): Add cloud.provider attribute to boto3 spans (#7884)
### Description Add [cloud.provider](https://getsentry.github.io/sentry-conventions/attributes/cloud/#cloud-provider) (always set `aws`) to boto3 spans; supplied at span creation time. Already in sentry semcon.
1 parent 3705d0b commit bf7a4e6

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎sentry_sdk/consts.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ class SPANDATA:
429429
Example: "10.1.2.80"
430430
"""
431431

432+
CLOUD_PROVIDER = "cloud.provider"
433+
"""
434+
Name of the cloud provider.
435+
436+
Example: "aws"
437+
"""
438+
432439
CLOUD_REGION = "cloud.region"
433440
"""
434441
The geographical region the resource is running.

‎sentry_sdk/integrations/boto3/_instrumentation.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sentry_sdk.integrations import DidNotEnable
77
from sentry_sdk.integrations.boto3.consts import (
88
AWS_RPC_SYSTEM_NAME,
9+
CLOUD_PROVIDER,
910
DEFAULT_PORTS,
1011
IDENTIFIER,
1112
ORIGIN,
@@ -156,6 +157,7 @@ def _start_client_span(
156157
service_name = ctx.service_id or "unknown"
157158
span_name = f"{service_name}.{ctx.operation_name}"
158159
attributes: "Attributes" = {
160+
SPANDATA.CLOUD_PROVIDER: CLOUD_PROVIDER,
159161
SPANDATA.RPC_METHOD: ctx.operation_name,
160162
SPANDATA.RPC_SYSTEM_NAME: AWS_RPC_SYSTEM_NAME,
161163
# all client call spans are by default "client" spans.

‎sentry_sdk/integrations/boto3/consts.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
IDENTIFIER = "boto3"
22
ORIGIN = f"auto.http.{IDENTIFIER}"
3+
CLOUD_PROVIDER = "aws"
34

45
# value is used by `rpc.system` (deprecated in OTel, but we still support it for now) and `rpc.system.name`
56
# https://opentelemetry.io/docs/specs/semconv/cloud-providers/aws-sdk/#aws-sdk-spans

‎tests/integrations/boto3/test_client.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from sentry_sdk.integrations.boto3 import Boto3Integration
1515
from sentry_sdk.integrations.boto3._services.base import _ServiceExtension
1616
from sentry_sdk.integrations.boto3._services.registry import _SERVICE_EXTENSIONS
17-
from sentry_sdk.integrations.boto3.consts import AWS_RPC_SYSTEM_NAME, ORIGIN
17+
from sentry_sdk.integrations.boto3.consts import (
18+
AWS_RPC_SYSTEM_NAME,
19+
CLOUD_PROVIDER,
20+
ORIGIN,
21+
)
1822
from sentry_sdk.integrations.stdlib import StdlibIntegration
1923
from sentry_sdk.traces import Span
2024
from tests.integrations.boto3.aws_mock import Body, MockResponse
@@ -442,6 +446,7 @@ def test_client_call_has_common_attributes(
442446
assert attributes[SPANDATA.RPC_SYSTEM_NAME] == AWS_RPC_SYSTEM_NAME
443447
assert attributes[SPANDATA.SENTRY_KIND] == "client"
444448
assert attributes[SPANDATA.CLOUD_REGION] == "eu-north-1"
449+
assert attributes[SPANDATA.CLOUD_PROVIDER] == CLOUD_PROVIDER
445450
assert attributes[SPANDATA.SERVER_ADDRESS] == server_address
446451
assert attributes[SPANDATA.SERVER_PORT] == server_port
447452
assert attributes[SPANDATA.HTTP_STATUS_CODE] == 200
@@ -462,6 +467,7 @@ def test_client_call_attributes_are_available_at_span_creation(
462467
ignore_spans=[
463468
{
464469
"attributes": {
470+
SPANDATA.CLOUD_PROVIDER: CLOUD_PROVIDER,
465471
SPANDATA.RPC_METHOD: "HeadObject",
466472
SPANDATA.RPC_SERVICE: "S3",
467473
SPANDATA.RPC_SYSTEM_NAME: AWS_RPC_SYSTEM_NAME,

0 commit comments

Comments
 (0)