Skip to content
Draft
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
20 changes: 12 additions & 8 deletions sentry_sdk/integrations/grpc/aio/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Any, AsyncIterable, Callable, Union

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP
from sentry_sdk.integrations import DidNotEnable
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN

Expand Down Expand Up @@ -58,9 +60,9 @@ async def intercept_unary_unary(
with sentry_sdk.start_span(
name="unary unary call to %s" % method.decode(),
attributes={
"sentry.op": OP.GRPC_CLIENT,
"sentry.origin": SPAN_ORIGIN,
SPANDATA.RPC_METHOD: method.decode(),
ATTRIBUTE_NAMES.SENTRY_OP: OP.GRPC_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SPAN_ORIGIN,
ATTRIBUTE_NAMES.RPC_METHOD: method.decode(),
},
) as span:
client_call_details = self._update_client_call_details_metadata_from_scope(
Expand All @@ -69,7 +71,9 @@ async def intercept_unary_unary(

response = await continuation(client_call_details, request)
status_code = await response.code()
span.set_attribute(SPANDATA.RPC_RESPONSE_STATUS_CODE, status_code.name)
span.set_attribute(
ATTRIBUTE_NAMES.RPC_RESPONSE_STATUS_CODE, status_code.name
)

return response

Expand All @@ -95,9 +99,9 @@ async def intercept_unary_stream(
with sentry_sdk.start_span(
name="unary stream call to %s" % method.decode(),
attributes={
"sentry.op": OP.GRPC_CLIENT,
"sentry.origin": SPAN_ORIGIN,
SPANDATA.RPC_METHOD: method.decode(),
ATTRIBUTE_NAMES.SENTRY_OP: OP.GRPC_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SPAN_ORIGIN,
ATTRIBUTE_NAMES.RPC_METHOD: method.decode(),
},
):
client_call_details = self._update_client_call_details_metadata_from_scope(
Expand Down
8 changes: 5 additions & 3 deletions sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TYPE_CHECKING

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP
from sentry_sdk.integrations import DidNotEnable
Expand Down Expand Up @@ -58,9 +60,9 @@ async def wrapped(request: "Any", context: "ServicerContext") -> "Any":
with sentry_sdk.start_span(
name=name,
attributes={
"sentry.op": OP.GRPC_SERVER,
"sentry.segment.name.source": SegmentNameSource.CUSTOM.value,
"sentry.origin": SPAN_ORIGIN,
ATTRIBUTE_NAMES.SENTRY_OP: OP.GRPC_SERVER,
ATTRIBUTE_NAMES.SENTRY_SEGMENT_NAME_SOURCE: SegmentNameSource.CUSTOM.value,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SPAN_ORIGIN,
},
parent_span=None,
):
Expand Down
20 changes: 12 additions & 8 deletions sentry_sdk/integrations/grpc/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import TYPE_CHECKING

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP
from sentry_sdk.integrations import DidNotEnable
from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN

Expand Down Expand Up @@ -38,17 +40,19 @@ def intercept_unary_unary(
with sentry_sdk.start_span(
name="unary unary call to %s" % method,
attributes={
"sentry.op": OP.GRPC_CLIENT,
"sentry.origin": SPAN_ORIGIN,
SPANDATA.RPC_METHOD: method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.GRPC_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SPAN_ORIGIN,
ATTRIBUTE_NAMES.RPC_METHOD: method,
},
) as span:
client_call_details = self._update_client_call_details_metadata_from_scope(
client_call_details
)

response = continuation(client_call_details, request)
span.set_attribute(SPANDATA.RPC_RESPONSE_STATUS_CODE, response.code().name)
span.set_attribute(
ATTRIBUTE_NAMES.RPC_RESPONSE_STATUS_CODE, response.code().name
)

return response

Expand All @@ -69,9 +73,9 @@ def intercept_unary_stream(
with sentry_sdk.start_span(
name="unary stream call to %s" % method,
attributes={
"sentry.op": OP.GRPC_CLIENT,
"sentry.origin": SPAN_ORIGIN,
SPANDATA.RPC_METHOD: method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.GRPC_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SPAN_ORIGIN,
ATTRIBUTE_NAMES.RPC_METHOD: method,
},
):
client_call_details = self._update_client_call_details_metadata_from_scope(
Expand Down
8 changes: 5 additions & 3 deletions sentry_sdk/integrations/grpc/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TYPE_CHECKING

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP
from sentry_sdk.integrations import DidNotEnable
Expand Down Expand Up @@ -51,9 +53,9 @@ def behavior(request: "Message", context: "ServicerContext") -> "Message":
with sentry_sdk.start_span(
name=name,
attributes={
"sentry.op": OP.GRPC_SERVER,
"sentry.segment.name.source": SegmentNameSource.CUSTOM.value,
"sentry.origin": SPAN_ORIGIN,
ATTRIBUTE_NAMES.SENTRY_OP: OP.GRPC_SERVER,
ATTRIBUTE_NAMES.SENTRY_SEGMENT_NAME_SOURCE: SegmentNameSource.CUSTOM.value,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SPAN_ORIGIN,
},
parent_span=None,
):
Expand Down
22 changes: 14 additions & 8 deletions sentry_sdk/integrations/httpx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from contextlib import nullcontext
from typing import TYPE_CHECKING

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
Expand Down Expand Up @@ -71,9 +73,9 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
),
attributes={
"sentry.op": OP.HTTP_CLIENT,
"sentry.origin": HttpxIntegration.origin,
"http.request.method": request.method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.HTTP_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: HttpxIntegration.origin,
ATTRIBUTE_NAMES.HTTP_REQUEST_METHOD: request.method,
},
)

Expand All @@ -85,7 +87,9 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":

if span is not None:
span.status = "error" if rv.status_code >= 400 else "ok"
span.set_attribute("http.response.status_code", rv.status_code)
span.set_attribute(
ATTRIBUTE_NAMES.HTTP_RESPONSE_STATUS_CODE, rv.status_code
)
finally:
if span is not None:
span.set_attributes(url_attributes)
Expand Down Expand Up @@ -142,9 +146,9 @@ async def send(
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
),
attributes={
"sentry.op": OP.HTTP_CLIENT,
"sentry.origin": HttpxIntegration.origin,
"http.request.method": request.method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.HTTP_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: HttpxIntegration.origin,
ATTRIBUTE_NAMES.HTTP_REQUEST_METHOD: request.method,
},
)

Expand All @@ -158,7 +162,9 @@ async def send(

if span is not None:
span.status = "error" if rv.status_code >= 400 else "ok"
span.set_attribute("http.response.status_code", rv.status_code)
span.set_attribute(
ATTRIBUTE_NAMES.HTTP_RESPONSE_STATUS_CODE, rv.status_code
)
finally:
if span is not None:
span.set_attributes(url_attributes)
Expand Down
22 changes: 14 additions & 8 deletions sentry_sdk/integrations/httpx2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from contextlib import nullcontext
from typing import TYPE_CHECKING

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
Expand Down Expand Up @@ -71,9 +73,9 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
),
attributes={
"sentry.op": OP.HTTP_CLIENT,
"sentry.origin": Httpx2Integration.origin,
"http.request.method": request.method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.HTTP_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: Httpx2Integration.origin,
ATTRIBUTE_NAMES.HTTP_REQUEST_METHOD: request.method,
},
)

Expand All @@ -85,7 +87,9 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":

if span is not None:
span.status = "error" if rv.status_code >= 400 else "ok"
span.set_attribute("http.response.status_code", rv.status_code)
span.set_attribute(
ATTRIBUTE_NAMES.HTTP_RESPONSE_STATUS_CODE, rv.status_code
)
finally:
if span is not None:
span.set_attributes(url_attributes)
Expand Down Expand Up @@ -142,9 +146,9 @@ async def send(
parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE,
),
attributes={
"sentry.op": OP.HTTP_CLIENT,
"sentry.origin": Httpx2Integration.origin,
"http.request.method": request.method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.HTTP_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: Httpx2Integration.origin,
ATTRIBUTE_NAMES.HTTP_REQUEST_METHOD: request.method,
},
)

Expand All @@ -158,7 +162,9 @@ async def send(

if span is not None:
span.status = "error" if rv.status_code >= 400 else "ok"
span.set_attribute("http.response.status_code", rv.status_code)
span.set_attribute(
ATTRIBUTE_NAMES.HTTP_RESPONSE_STATUS_CODE, rv.status_code
)
finally:
if span is not None:
span.set_attributes(url_attributes)
Expand Down
12 changes: 7 additions & 5 deletions sentry_sdk/integrations/pyreqwest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Generator

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
Expand Down Expand Up @@ -124,9 +126,9 @@ def _sentry_pyreqwest_span(
with sentry_sdk.start_span(
name=f"{request.method} {parsed_url.url if parsed_url else SENSITIVE_DATA_SUBSTITUTE}",
attributes={
"sentry.op": OP.HTTP_CLIENT,
"sentry.origin": PyreqwestIntegration.origin,
SPANDATA.HTTP_REQUEST_METHOD: request.method,
ATTRIBUTE_NAMES.SENTRY_OP: OP.HTTP_CLIENT,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: PyreqwestIntegration.origin,
ATTRIBUTE_NAMES.HTTP_REQUEST_METHOD: request.method,
},
) as span:
for key, value in url_attributes.items():
Expand Down Expand Up @@ -163,7 +165,7 @@ async def sentry_async_middleware(
if span is not None:
span.status = "error" if response.status >= 400 else "ok"
span.set_attribute(
SPANDATA.HTTP_STATUS_CODE,
ATTRIBUTE_NAMES.HTTP_RESPONSE_STATUS_CODE,
response.status,
)

Expand Down Expand Up @@ -201,7 +203,7 @@ def sentry_sync_middleware(
if span is not None:
span.status = "error" if response.status >= 400 else "ok"
span.set_attribute(
SPANDATA.HTTP_STATUS_CODE,
ATTRIBUTE_NAMES.HTTP_RESPONSE_STATUS_CODE,
response.status,
)

Expand Down
24 changes: 13 additions & 11 deletions sentry_sdk/integrations/socket.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import socket

from sentry_conventions.attributes import ATTRIBUTE_NAMES

import sentry_sdk
from sentry_sdk._types import MYPY
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.consts import OP
from sentry_sdk.integrations import Integration

if MYPY:
Expand Down Expand Up @@ -61,13 +63,13 @@ def create_connection(
with sentry_sdk.start_span(
name=_get_span_description(address[0], address[1]),
attributes={
"sentry.op": OP.SOCKET_CONNECTION,
"sentry.origin": SocketIntegration.origin,
ATTRIBUTE_NAMES.SENTRY_OP: OP.SOCKET_CONNECTION,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SocketIntegration.origin,
},
) as span:
if address[0] is not None:
span.set_attribute(SPANDATA.SERVER_ADDRESS, address[0])
span.set_attribute(SPANDATA.SERVER_PORT, address[1])
span.set_attribute(ATTRIBUTE_NAMES.SERVER_ADDRESS, address[0])
span.set_attribute(ATTRIBUTE_NAMES.SERVER_PORT, address[1])

return real_create_connection(
address=address, timeout=timeout, source_address=source_address
Expand Down Expand Up @@ -98,22 +100,22 @@ def getaddrinfo(
with sentry_sdk.start_span(
name=_get_span_description(host, port),
attributes={
"sentry.op": OP.SOCKET_DNS,
"sentry.origin": SocketIntegration.origin,
ATTRIBUTE_NAMES.SENTRY_OP: OP.SOCKET_DNS,
ATTRIBUTE_NAMES.SENTRY_ORIGIN: SocketIntegration.origin,
},
) as span:
if isinstance(host, str):
span.set_attribute(SPANDATA.SERVER_ADDRESS, host)
span.set_attribute(ATTRIBUTE_NAMES.SERVER_ADDRESS, host)
elif isinstance(host, bytes):
span.set_attribute(
SPANDATA.SERVER_ADDRESS, host.decode(errors="replace")
ATTRIBUTE_NAMES.SERVER_ADDRESS, host.decode(errors="replace")
)

if isinstance(port, int):
span.set_attribute(SPANDATA.SERVER_PORT, port)
span.set_attribute(ATTRIBUTE_NAMES.SERVER_PORT, port)
elif port is not None:
try:
span.set_attribute(SPANDATA.SERVER_PORT, int(port))
span.set_attribute(ATTRIBUTE_NAMES.SERVER_PORT, int(port))
except (ValueError, TypeError):
pass

Expand Down
Loading
Loading