From bd0098a5c51f0cb2c72a2b667c258ad1a8f83fa2 Mon Sep 17 00:00:00 2001 From: Ivana Kellyerova Date: Tue, 27 Jun 2023 11:06:11 +0200 Subject: [PATCH] fixes --- sentry_sdk/integrations/celery.py | 15 ++++++++++----- sentry_sdk/integrations/httpx.py | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/integrations/celery.py b/sentry_sdk/integrations/celery.py index 37e4e8669b..bd11e2da8d 100644 --- a/sentry_sdk/integrations/celery.py +++ b/sentry_sdk/integrations/celery.py @@ -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 # @@ -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) diff --git a/sentry_sdk/integrations/httpx.py b/sentry_sdk/integrations/httpx.py index 04db5047b4..323e7396fa 100644 --- a/sentry_sdk/integrations/httpx.py +++ b/sentry_sdk/integrations/httpx.py @@ -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