Skip to content
Merged
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
45 changes: 2 additions & 43 deletions sentry_sdk/integrations/boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.data_collection import (
_apply_data_collection_filtering_to_query_string,
)
from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, Span
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_sentry_baggage_to_headers,
get_url_attributes,
has_span_streaming_enabled,
should_propagate_trace,
)
from sentry_sdk.utils import (
capture_internal_exceptions,
has_data_collection_enabled,
parse_url,
parse_version,
)
Expand All @@ -28,9 +24,6 @@

from botocore.model import ServiceId

from sentry_sdk._types import Attributes
from sentry_sdk.client import BaseClient as SentryClient
from sentry_sdk.utils import ParsedUrl

try:
from botocore import __version__ as BOTOCORE_VERSION
Expand Down Expand Up @@ -70,40 +63,6 @@ def sentry_patched_init(
BaseClient.__init__ = sentry_patched_init # type: ignore


def _get_url_attributes(
client: "SentryClient", parsed_url: "Optional[ParsedUrl]"
) -> "Attributes":
attributes: "Attributes" = {}
if parsed_url is None:
return attributes

query: "Optional[str]"
if has_data_collection_enabled(client.options):
query = None
if parsed_url.query:
query = _apply_data_collection_filtering_to_query_string(
query_string=parsed_url.query,
behaviour=client.options["data_collection"]["url_query_params"],
)
elif should_send_default_pii():
query = parsed_url.query
else:
return attributes

url_full = parsed_url.url
if query:
attributes[SPANDATA.URL_QUERY] = query
url_full += "?" + query

if parsed_url.fragment:
attributes[SPANDATA.URL_FRAGMENT] = parsed_url.fragment
url_full += "#" + parsed_url.fragment

attributes[SPANDATA.URL_FULL] = url_full

return attributes


def _sentry_request_created(
service_id: "ServiceId", request: "AWSRequest", operation_name: str, **kwargs: "Any"
) -> None:
Expand All @@ -123,7 +82,7 @@ def _sentry_request_created(
is_span_streaming_enabled = has_span_streaming_enabled(client.options)
span: "Union[Span, StreamedSpan, None]" = None
if is_span_streaming_enabled:
url_attributes = _get_url_attributes(client, parsed_url)
url_attributes = get_url_attributes(client, parsed_url)
breadcrumb.update(url_attributes)

if request.method is not None:
Expand Down
53 changes: 4 additions & 49 deletions sentry_sdk/integrations/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.data_collection import (
_apply_data_collection_filtering_to_query_string,
)
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_http_request_source,
get_url_attributes,
has_span_streaming_enabled,
propagate_trace_headers,
)
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
capture_internal_exceptions,
ensure_integration_enabled,
has_data_collection_enabled,
parse_url,
)

if TYPE_CHECKING:
from typing import Any, Optional
from typing import Any

from sentry_sdk._types import Attributes
from sentry_sdk.client import BaseClient
from sentry_sdk.utils import ParsedUrl


try:
Expand All @@ -51,45 +45,6 @@ def setup_once() -> None:
_install_httpx_async_client()


def _get_url_attributes(
client: "BaseClient", parsed_url: "Optional[ParsedUrl]"
) -> "Attributes":
attributes: "Attributes" = {}
if parsed_url is None:
return attributes

url_full = parsed_url.url

if has_data_collection_enabled(client.options):
if parsed_url.query:
filtered_query = _apply_data_collection_filtering_to_query_string(
query_string=parsed_url.query,
behaviour=client.options["data_collection"]["url_query_params"],
)
if filtered_query:
attributes["url.query"] = filtered_query
url_full += "?" + filtered_query

if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment
url_full += "#" + parsed_url.fragment

attributes["url.full"] = url_full

elif should_send_default_pii():
if parsed_url.query:
attributes["url.query"] = parsed_url.query
url_full += "?" + parsed_url.query

if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment
url_full += "#" + parsed_url.fragment

attributes["url.full"] = url_full

return attributes


def _install_httpx_client() -> None:
real_send = Client.send

Expand All @@ -109,7 +64,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
propagate_trace_headers(client, request)
return real_send(self, request, **kwargs)

url_attributes = _get_url_attributes(client, parsed_url)
url_attributes = get_url_attributes(client, parsed_url)

with sentry_sdk.traces.start_span(
name="%s %s"
Expand Down Expand Up @@ -218,7 +173,7 @@ async def send(
propagate_trace_headers(client, request)
return await real_send(self, request, **kwargs)

url_attributes = _get_url_attributes(client, parsed_url)
url_attributes = get_url_attributes(client, parsed_url)

with sentry_sdk.traces.start_span(
name="%s %s"
Expand Down
53 changes: 4 additions & 49 deletions sentry_sdk/integrations/httpx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@

import sentry_sdk
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.data_collection import (
_apply_data_collection_filtering_to_query_string,
)
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_http_request_source,
get_url_attributes,
has_span_streaming_enabled,
propagate_trace_headers,
)
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
capture_internal_exceptions,
ensure_integration_enabled,
has_data_collection_enabled,
parse_url,
)

if TYPE_CHECKING:
from typing import Any, Optional
from typing import Any

from sentry_sdk._types import Attributes
from sentry_sdk.client import BaseClient
from sentry_sdk.utils import ParsedUrl


try:
Expand All @@ -51,45 +45,6 @@ def setup_once() -> None:
_install_httpx2_async_client()


def _get_url_attributes(
client: "BaseClient", parsed_url: "Optional[ParsedUrl]"
) -> "Attributes":
attributes: "Attributes" = {}
if parsed_url is None:
return attributes

url_full = parsed_url.url

if has_data_collection_enabled(client.options):
if parsed_url.query:
filtered_query = _apply_data_collection_filtering_to_query_string(
query_string=parsed_url.query,
behaviour=client.options["data_collection"]["url_query_params"],
)
if filtered_query:
attributes["url.query"] = filtered_query
url_full += "?" + filtered_query

if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment
url_full += "#" + parsed_url.fragment

attributes["url.full"] = url_full

elif should_send_default_pii():
if parsed_url.query:
attributes["url.query"] = parsed_url.query
url_full += "?" + parsed_url.query

if parsed_url.fragment:
attributes["url.fragment"] = parsed_url.fragment
url_full += "#" + parsed_url.fragment

attributes["url.full"] = url_full

return attributes


def _install_httpx2_client() -> None:
real_send = Client.send

Expand All @@ -109,7 +64,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
propagate_trace_headers(client, request)
return real_send(self, request, **kwargs)

url_attributes = _get_url_attributes(client, parsed_url)
url_attributes = get_url_attributes(client, parsed_url)

with sentry_sdk.traces.start_span(
name="%s %s"
Expand Down Expand Up @@ -218,7 +173,7 @@ async def send(
propagate_trace_headers(client, request)
return await real_send(self, request, **kwargs)

url_attributes = _get_url_attributes(client, parsed_url)
url_attributes = get_url_attributes(client, parsed_url)

with sentry_sdk.traces.start_span(
name="%s %s"
Expand Down
45 changes: 3 additions & 42 deletions sentry_sdk/integrations/pyreqwest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@
import sentry_sdk
from sentry_sdk import start_span
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.data_collection import (
_apply_data_collection_filtering_to_query_string,
)
from sentry_sdk.integrations import DidNotEnable, Integration
from sentry_sdk.scope import should_send_default_pii
from sentry_sdk.traces import StreamedSpan
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
from sentry_sdk.tracing_utils import (
add_http_breadcrumb,
add_http_request_source,
add_sentry_baggage_to_headers,
get_url_attributes,
has_span_streaming_enabled,
propagate_trace_headers,
should_propagate_trace,
)
from sentry_sdk.utils import (
SENSITIVE_DATA_SUBSTITUTE,
capture_internal_exceptions,
has_data_collection_enabled,
logger,
parse_url,
)
Expand All @@ -31,7 +27,6 @@
from typing import Optional

from sentry_sdk._types import Attributes
from sentry_sdk.client import BaseClient
from sentry_sdk.utils import ParsedUrl

try:
Expand Down Expand Up @@ -97,40 +92,6 @@ def sentry_patched_method(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
setattr(cls, method_name, sentry_patched_method)


def _get_url_attributes(
client: "BaseClient", parsed_url: "Optional[ParsedUrl]"
) -> "Attributes":
attributes: "Attributes" = {}
if parsed_url is None:
return attributes

query: "Optional[str]"
if has_data_collection_enabled(client.options):
query = None
if parsed_url.query:
query = _apply_data_collection_filtering_to_query_string(
query_string=parsed_url.query,
behaviour=client.options["data_collection"]["url_query_params"],
)
elif should_send_default_pii():
query = parsed_url.query
else:
return attributes

url_full = parsed_url.url
if query:
attributes[SPANDATA.URL_QUERY] = query
url_full += "?" + query

if parsed_url.fragment:
attributes[SPANDATA.URL_FRAGMENT] = parsed_url.fragment
url_full += "#" + parsed_url.fragment

attributes[SPANDATA.URL_FULL] = url_full

return attributes


def _get_breadcrumb_url_data(
parsed_url: "Optional[ParsedUrl]", url_attributes: "Attributes"
) -> "dict[str, Any]":
Expand Down Expand Up @@ -233,7 +194,7 @@ async def sentry_async_middleware(
# after the request has been sent
parsed_url = parse_url(str(request.url), sanitize=False)

url_attributes = _get_url_attributes(sentry_sdk.get_client(), parsed_url)
url_attributes = get_url_attributes(sentry_sdk.get_client(), parsed_url)

response = None
with _sentry_pyreqwest_span(request, url_attributes) as span:
Expand Down Expand Up @@ -273,7 +234,7 @@ def sentry_sync_middleware(
# after the request has been sent
parsed_url = parse_url(str(request.url), sanitize=False)

url_attributes = _get_url_attributes(sentry_sdk.get_client(), parsed_url)
url_attributes = get_url_attributes(sentry_sdk.get_client(), parsed_url)

response = None
with _sentry_pyreqwest_span(request, url_attributes) as span:
Expand Down
Loading
Loading