Skip to content

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

Merged
xrmx merged 4 commits intoopen-telemetry:mainfrom
DrMeers:fix/celery-getter-non-string-values
Apr 20, 2026
Merged

fix(celery): coerce non-string values in CeleryGetter.get()#4360
xrmx merged 4 commits intoopen-telemetry:mainfrom
DrMeers:fix/celery-getter-non-string-values

Conversation

@DrMeers
Copy link
Copy Markdown
Contributor

@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
@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions bot added the Stale label Apr 11, 2026
@DrMeers
Copy link
Copy Markdown
Contributor Author

DrMeers commented Apr 11, 2026

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment. If you're still working on this, please add a comment or push new commits.

Just waiting on it getting merged!

@github-actions github-actions bot removed the Stale label Apr 12, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team April 14, 2026 00:40
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Approved PRs in Python PR digest Apr 14, 2026
@xrmx xrmx enabled auto-merge (squash) April 20, 2026 13:33
@xrmx xrmx merged commit 51b5753 into open-telemetry:main Apr 20, 2026
750 of 751 checks passed
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Python PR digest Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

4 participants