Skip to content

Commit ee15d7b

Browse files
committed
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 <alliasgher123@gmail.com>
1 parent e9fed7d commit ee15d7b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ def get(self, carrier, key):
104104
value = getattr(carrier, key, None)
105105
if value is None:
106106
return None
107-
if isinstance(value, str) or not isinstance(value, Iterable):
108-
value = (value,)
107+
if isinstance(value, str):
108+
return (value,)
109+
if not isinstance(value, Iterable):
110+
# Coerce non-string, non-iterable values (e.g. int from Celery
111+
# task attributes like timelimit) to str so that propagators
112+
# such as TraceContext don't crash with a TypeError when calling
113+
# re.split() on the value.
114+
return (str(value),)
109115
return value
110116

111117
def keys(self, carrier):

0 commit comments

Comments
 (0)