Skip to content

Commit 4562898

Browse files
committed
ref(boto3): move DEFAULT_PORTS to consts.py
1 parent bf04dfb commit 4562898

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎sentry_sdk/integrations/boto3/_instrumentation.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
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 AWS_RPC_SYSTEM_NAME, ORIGIN
7+
from sentry_sdk.integrations.boto3.consts import (
8+
AWS_RPC_SYSTEM_NAME,
9+
DEFAULT_PORTS,
10+
ORIGIN,
11+
)
812
from sentry_sdk.traces import NoOpStreamedSpan, StreamedSpan
913
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span
1014
from sentry_sdk.tracing_utils import (
@@ -47,22 +51,17 @@ def _get_server_attributes(endpoint_url: "Optional[str]") -> "Attributes":
4751
if not endpoint_url:
4852
return {}
4953

50-
default_ports = {
51-
"http": 80,
52-
"https": 443,
53-
}
54-
5554
try:
5655
parsed_url = urlsplit(endpoint_url)
57-
if parsed_url.scheme not in default_ports or not parsed_url.hostname:
56+
if parsed_url.scheme not in DEFAULT_PORTS or not parsed_url.hostname:
5857
return {}
5958

6059
# `server.port` is only defined together with `server.address`.
6160
# Infer the effective port when the configured HTTP(S) endpoint omits it.
6261
# https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/
6362
return {
6463
SPANDATA.SERVER_ADDRESS: parsed_url.hostname,
65-
SPANDATA.SERVER_PORT: parsed_url.port or default_ports[parsed_url.scheme],
64+
SPANDATA.SERVER_PORT: parsed_url.port or DEFAULT_PORTS[parsed_url.scheme],
6665
}
6766

6867
except (TypeError, UnicodeError, ValueError):

‎sentry_sdk/integrations/boto3/consts.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
# value is used by `rpc.system` (deprecated in OTel, but we still support it for now) and `rpc.system.name`
55
# https://opentelemetry.io/docs/specs/semconv/cloud-providers/aws-sdk/#aws-sdk-spans
66
AWS_RPC_SYSTEM_NAME = "aws-api"
7+
8+
# default ports for HTTP and HTTPS
9+
DEFAULT_PORTS = {
10+
"http": 80,
11+
"https": 443,
12+
}

0 commit comments

Comments
 (0)