Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Jun 27, 2023
1 parent 2a71e1c commit bd0098a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions sentry_sdk/integrations/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,18 @@ def apply_async(*args, **kwargs):
kwarg_headers = kwargs.get("headers") or {}

existing_baggage = kwarg_headers.get(BAGGAGE_HEADER_NAME)
if existing_baggage:
sentry_baggage = headers.get(BAGGAGE_HEADER_NAME)
if sentry_baggage and existing_baggage:
combined_baggage = "{},{}".format(
existing_baggage,
headers[BAGGAGE_HEADER_NAME],
sentry_baggage,
)
else:
combined_baggage = headers[BAGGAGE_HEADER_NAME]
combined_baggage = sentry_baggage or existing_baggage

kwarg_headers.update(headers)
kwarg_headers[BAGGAGE_HEADER_NAME] = combined_baggage
if combined_baggage:
kwarg_headers[BAGGAGE_HEADER_NAME] = combined_baggage

# https://github.com/celery/celery/issues/4875
#
Expand All @@ -178,7 +180,10 @@ def apply_async(*args, **kwargs):
# workaround and we don't want to break them.
kwarg_headers.setdefault("headers", {})
kwarg_headers["headers"].update(headers)
kwarg_headers["headers"][BAGGAGE_HEADER_NAME] = combined_baggage
if combined_baggage:
kwarg_headers["headers"][
BAGGAGE_HEADER_NAME
] = combined_baggage

# Add the Sentry options potentially added in `sentry_apply_entry`
# to the headers (done when auto-instrumenting Celery Beat tasks)
Expand Down
4 changes: 3 additions & 1 deletion sentry_sdk/integrations/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def send(self, request, **kwargs):
BAGGAGE_HEADER_NAME
):
# do not overwrite any existing baggage, just append to it
request.headers[key] += "," + value
request.headers[key] = "{},{}".format(
request.headers[key], value
)
else:
request.headers[key] = value

Expand Down

0 comments on commit bd0098a

Please sign in to comment.