Skip to content

Commit a72a791

Browse files
committed
use consts and string lookup for client.getintegration
1 parent 82258cc commit a72a791

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎sentry_sdk/integrations/boto3/_client.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sentry_sdk
55
from sentry_sdk.integrations import DidNotEnable
66
from sentry_sdk.integrations.boto3._context import AwsCallContext
7+
from sentry_sdk.integrations.boto3.consts import IDENTIFIER
78
from sentry_sdk.integrations.boto3._instrumentation import (
89
_finish_span,
910
_get_error_attributes,
@@ -68,8 +69,6 @@ def _activate_client_span(
6869

6970

7071
def _patch_botocore_client() -> None:
71-
from sentry_sdk.integrations.boto3 import Boto3Integration
72-
7372
orig_init = BaseClient.__init__
7473
orig_make_api_call = BaseClient._make_api_call # type: ignore
7574

@@ -91,7 +90,7 @@ def sentry_patched_make_api_call(
9190
https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/#rpc-client-span
9291
"""
9392
client = sentry_sdk.get_client()
94-
if client.get_integration(Boto3Integration) is None:
93+
if client.get_integration(IDENTIFIER) is None:
9594
return orig_make_api_call(self, operation_name, api_params)
9695

9796
ctx = AwsCallContext(operation_name, api_params)

‎sentry_sdk/integrations/boto3/_instrumentation.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sentry_sdk
55
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
66
from sentry_sdk.integrations import DidNotEnable
7-
from sentry_sdk.integrations.boto3.consts import ORIGIN
7+
from sentry_sdk.integrations.boto3.consts import IDENTIFIER, ORIGIN
88
from sentry_sdk.traces import NoOpStreamedSpan, StreamedSpan
99
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span
1010
from sentry_sdk.tracing_utils import (
@@ -188,7 +188,7 @@ def _start_client_span(
188188
ctx: "AwsCallContext",
189189
) -> "Optional[Union[Span, StreamedSpan]]":
190190
client = sentry_sdk.get_client()
191-
if client.get_integration("boto3") is None:
191+
if client.get_integration(IDENTIFIER) is None:
192192
return None
193193

194194
# use unknown if `service_id_hyphenized` so span name can still be created.
@@ -437,7 +437,7 @@ def _sentry_request_created(
437437
"""
438438

439439
client = sentry_sdk.get_client()
440-
if client.get_integration("boto3") is None:
440+
if client.get_integration(IDENTIFIER) is None:
441441
return
442442

443443
with capture_internal_exceptions():
@@ -465,7 +465,7 @@ def _sentry_before_sign(
465465
request: "AWSRequest", signature_version: "Any", **kwargs: "Any"
466466
) -> None:
467467
client = sentry_sdk.get_client()
468-
if client.get_integration("boto3") is None:
468+
if client.get_integration(IDENTIFIER) is None:
469469
return
470470

471471
with capture_internal_exceptions():

‎tests/integrations/boto3/test_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def test_client_call_attributes_are_available_at_span_creation(
613613
item.payload
614614
for item in items
615615
if item.payload["attributes"].get(SPANDATA.SENTRY_ORIGIN)
616-
== Boto3Integration.origin
616+
== ORIGIN
617617
]
618618
assert client_spans == []
619619

‎tests/integrations/boto3/test_s3.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sentry_sdk import capture_message
88
from sentry_sdk.consts import SPANDATA
99
from sentry_sdk.integrations.boto3 import Boto3Integration
10+
from sentry_sdk.integrations.boto3.consts import ORIGIN
1011
from tests.conftest import ApproxDict
1112
from tests.integrations.boto3 import read_fixture
1213
from tests.integrations.boto3.aws_mock import MockResponse
@@ -130,7 +131,7 @@ def test_streaming(
130131
"rpc.service": "S3",
131132
"sentry.environment": "production",
132133
"sentry.op": "http.client",
133-
"sentry.origin": "auto.http.boto3",
134+
"sentry.origin": ORIGIN,
134135
"sentry.release": mock.ANY,
135136
"sentry.sdk.name": "sentry.python",
136137
"sentry.sdk.version": mock.ANY,
@@ -292,7 +293,7 @@ def test_omit_url_data_if_parsing_fails(
292293
"rpc.service": "S3",
293294
"sentry.environment": "production",
294295
"sentry.op": "http.client",
295-
"sentry.origin": "auto.http.boto3",
296+
"sentry.origin": ORIGIN,
296297
"sentry.release": mock.ANY,
297298
"sentry.sdk.name": "sentry.python",
298299
"sentry.sdk.version": mock.ANY,
@@ -364,7 +365,7 @@ def test_span_origin(
364365
spans = [item.payload for item in items]
365366

366367
assert spans[1]["attributes"]["sentry.origin"] == "manual"
367-
assert spans[0]["attributes"]["sentry.origin"] == "auto.http.boto3"
368+
assert spans[0]["attributes"]["sentry.origin"] == ORIGIN
368369
else:
369370
events = capture_events()
370371

@@ -376,7 +377,7 @@ def test_span_origin(
376377
(event,) = events
377378

378379
assert event["contexts"]["trace"]["origin"] == "manual"
379-
assert event["spans"][0]["origin"] == "auto.http.boto3"
380+
assert event["spans"][0]["origin"] == ORIGIN
380381

381382

382383
def test_breadcrumb(sentry_init, capture_events):

0 commit comments

Comments
 (0)