From f9ee7652659c606668e04cc2adc67bed84c92a92 Mon Sep 17 00:00:00 2001 From: alliasgher Date: Tue, 14 Apr 2026 22:19:41 +0500 Subject: [PATCH 1/2] fix(celery): coerce non-string values to str in CeleryGetter.get() Celery's Context object copies all message properties as instance attrs, including numeric fields like timelimit. CeleryGetter.get() wrapped these in a tuple but didn't convert to str, causing TextMapPropagators to crash with "TypeError: expected string or bytes-like object, got 'int'" when calling re.split() in TraceState.from_header(). Coerce non-string, non-iterable values to str before wrapping in a tuple. Fixes #4359 Signed-off-by: alliasgher --- .../opentelemetry/instrumentation/celery/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 3d6691f382..2946edbac3 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -104,8 +104,14 @@ def get(self, carrier, key): value = getattr(carrier, key, None) if value is None: return None - if isinstance(value, str) or not isinstance(value, Iterable): - value = (value,) + if isinstance(value, str): + return (value,) + if not isinstance(value, Iterable): + # Coerce non-string, non-iterable values (e.g. int from Celery + # task attributes like timelimit) to str so that propagators + # such as TraceContext don't crash with a TypeError when calling + # re.split() on the value. + return (str(value),) return value def keys(self, carrier): From c433dd21be928b524b21aad22bc6175835342039 Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 16 Apr 2026 01:20:46 +0500 Subject: [PATCH 2/2] chore: add CHANGELOG entry for #4434 Signed-off-by: Ali --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8818f8b070..3013117e8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `pylint` to `4.0.5` ([#4244](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4244)) +### Fixed + +- `opentelemetry-instrumentation-celery`: Coerce non-string header values to `str` in `CeleryGetter.get()` so context propagation does not fail when downstream libraries set non-string headers + ([#4434](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4434)) + ### Breaking changes - Drop Python 3.9 support