Skip to content

fix(celery): coerce non-string values in CeleryGetter.get()#4360

Open
DrMeers wants to merge 3 commits intoopen-telemetry:mainfrom
DrMeers:fix/celery-getter-non-string-values
Open

fix(celery): coerce non-string values in CeleryGetter.get()#4360
DrMeers wants to merge 3 commits intoopen-telemetry:mainfrom
DrMeers:fix/celery-getter-non-string-values

Conversation

@DrMeers
Copy link
Copy Markdown

@DrMeers DrMeers commented Mar 26, 2026

Description

CeleryGetter.get() can return non-string values (e.g. int) from Celery task request attributes, which causes TraceState.from_header() to crash with TypeError: expected string or bytes-like object, got 'int'.

Celery's Context copies all message properties as instance attributes via __dict__.update(), including non-string values like timelimit (tuple of ints) and priority (int). The TextMapPropagator contract requires string values from Getter.get(), but CeleryGetter returned these non-string values as-is.

This patch coerces all non-string values to strings before returning them.

Fixes #4359

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added unit tests for int values, iterables with non-string elements, and mixed-type iterables
  • Updated existing test_get_iter assertion (now returns tuple, consistent with coercion)
  • Verified fix resolves the TypeError in a production Celery worker with OTel tracing

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Celery's Context copies all message properties as instance attributes
via __dict__.update(), including non-string values like timelimit
(tuple of ints) and priority (int). The TextMapPropagator contract
requires string values from Getter.get(), but CeleryGetter returned
these non-string values as-is, causing TraceState.from_header() to
crash with TypeError when calling re.split() on an int.

Coerce all non-string values to strings before returning them.

See open-telemetry#4359
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 26, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@DrMeers DrMeers requested a review from a team as a code owner March 26, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

CeleryGetter.get() returns non-string values, crashes TraceContext propagator

2 participants