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
14 changes: 14 additions & 0 deletions sentry_sdk/integrations/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
TransactionSource,
)
from sentry_sdk.tracing_utils import (
Baggage,
add_http_breadcrumb,
add_http_request_source,
has_span_streaming_enabled,
Expand Down Expand Up @@ -488,6 +489,19 @@ async def on_request_start(
if SENTRY_TRACE_HEADER_NAME in params.headers:
headers_to_skip.add(SENTRY_TRACE_HEADER_NAME)

# `baggage` with Sentry members (e.g. merged by the boto3 integration
# before signing): skip so Sentry members are not duplicated.
with capture_internal_exceptions():
baggage = params.headers.get(BAGGAGE_HEADER_NAME)
if baggage:
if isinstance(baggage, bytes):
baggage = baggage.decode("latin-1")
if any(
Baggage.SENTRY_PREFIX_REGEX.match(item.strip())
for item in baggage.split(",")
):
headers_to_skip.add(BAGGAGE_HEADER_NAME)

with capture_internal_exceptions():
authorization = params.headers.get("Authorization")
if authorization:
Expand Down
26 changes: 19 additions & 7 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,21 @@ async def handler(request):


@pytest.mark.asyncio
async def test_outgoing_trace_headers_preserves_signed_propagation_headers(
sentry_init, aiohttp_raw_server, aiohttp_client
@pytest.mark.parametrize(
"signed_headers,baggage",
[
# both propagation headers are named in `SignedHeaders`.
("baggage;host;sentry-trace", "vendor=value"),
# botocore 1.43.115+ never signs `baggage`; Sentry members were merged by
# the boto3 integration before signing.
(
"host;sentry-trace",
"vendor=value,sentry-trace_id=existing,sentry-sampled=true",
),
],
)
async def test_outgoing_trace_headers_preserves_existing_propagation_headers(
sentry_init, aiohttp_raw_server, aiohttp_client, signed_headers, baggage
):
sentry_init(
integrations=[AioHttpIntegration()],
Expand All @@ -951,11 +964,10 @@ async def handler(request):
return web.Response(text="OK")

raw_server = await aiohttp_raw_server(handler)
# both propagation headers are named in `SignedHeaders`.
authorization = (
"AWS4-HMAC-SHA256 "
"Credential=test/20260804/eu-west-1/secretsmanager/aws4_request, "
"SignedHeaders=baggage;host;sentry-trace, "
f"SignedHeaders={signed_headers}, "
"Signature=sixtyseven"
)

Expand All @@ -964,15 +976,15 @@ async def handler(request):
resp = await client.get(
"/",
headers={
"baggage": "vendor=value",
"baggage": baggage,
"sentry-trace": "existing-trace",
"Authorization": authorization,
},
)

headers = resp.request_info.headers
# signed `baggage`: leave as-is.
assert headers["baggage"] == "vendor=value"
# signed `baggage` or `baggage` with Sentry members: leave as-is.
assert headers["baggage"] == baggage
# signed `sentry-trace`: leave as-is.
assert headers["sentry-trace"] == "existing-trace"

Expand Down
Loading