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 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):