Skip to content

Commit e1cfae1

Browse files
.
1 parent 82b6c00 commit e1cfae1

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

sentry_sdk/integrations/httpx.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from sentry_sdk.integrations import Integration, DidNotEnable
55
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME
66
from sentry_sdk.tracing_utils import (
7-
Baggage,
87
should_propagate_trace,
98
add_http_request_source,
9+
add_sentry_baggage_to_headers,
1010
)
1111
from sentry_sdk.utils import (
1212
SENSITIVE_DATA_SUBSTITUTE,
@@ -19,7 +19,6 @@
1919
from typing import TYPE_CHECKING
2020

2121
if TYPE_CHECKING:
22-
from collections.abc import MutableMapping
2322
from typing import Any
2423

2524

@@ -81,7 +80,7 @@ def send(self: "Client", request: "Request", **kwargs: "Any") -> "Response":
8180
)
8281

8382
if key == BAGGAGE_HEADER_NAME:
84-
_add_sentry_baggage_to_headers(request.headers, value)
83+
add_sentry_baggage_to_headers(request.headers, value)
8584
else:
8685
request.headers[key] = value
8786

@@ -155,22 +154,3 @@ async def send(
155154
return rv
156155

157156
AsyncClient.send = send
158-
159-
160-
def _add_sentry_baggage_to_headers(
161-
headers: "MutableMapping[str, str]", sentry_baggage: str
162-
) -> None:
163-
"""Add the Sentry baggage to the headers.
164-
165-
This function directly mutates the provided headers. The provided sentry_baggage
166-
is appended to the existing baggage. If the baggage already contains Sentry items,
167-
they are stripped out first.
168-
"""
169-
existing_baggage = headers.get(BAGGAGE_HEADER_NAME, "")
170-
stripped_existing_baggage = Baggage.strip_sentry_baggage(existing_baggage)
171-
172-
separator = "," if len(stripped_existing_baggage) > 0 else ""
173-
174-
headers[BAGGAGE_HEADER_NAME] = (
175-
stripped_existing_baggage + separator + sentry_baggage
176-
)

sentry_sdk/tracing_utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import re
66
import sys
7-
from collections.abc import Mapping
7+
from collections.abc import Mapping, MutableMapping
88
from datetime import timedelta
99
from random import Random
1010
from urllib.parse import quote, unquote
@@ -1285,6 +1285,25 @@ def _should_continue_trace(baggage: "Optional[Baggage]") -> bool:
12851285
return True
12861286

12871287

1288+
def add_sentry_baggage_to_headers(
1289+
headers: "MutableMapping[str, str]", sentry_baggage: str
1290+
) -> None:
1291+
"""Add the Sentry baggage to the headers.
1292+
1293+
This function directly mutates the provided headers. The provided sentry_baggage
1294+
is appended to the existing baggage. If the baggage already contains Sentry items,
1295+
they are stripped out first.
1296+
"""
1297+
existing_baggage = headers.get(BAGGAGE_HEADER_NAME, "")
1298+
stripped_existing_baggage = Baggage.strip_sentry_baggage(existing_baggage)
1299+
1300+
separator = "," if len(stripped_existing_baggage) > 0 else ""
1301+
1302+
headers[BAGGAGE_HEADER_NAME] = (
1303+
stripped_existing_baggage + separator + sentry_baggage
1304+
)
1305+
1306+
12881307
# Circular imports
12891308
from sentry_sdk.tracing import (
12901309
BAGGAGE_HEADER_NAME,

0 commit comments

Comments
 (0)