fix(otel-patch): convert incompatible types - #724
Conversation
PR Summary by QodoFix OTEL patch: coerce non-primitive span attributes to strings
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
Context used✅ Compliance rules (platform):
7 rules 1. Sanitization happens too late
|
| + if not isinstance(value, _OTEL_TYPES) and not ( | ||
| + isinstance(value, (list, tuple)) and all(isinstance(v, _OTEL_TYPES) for v in value) | ||
| + ): | ||
| + value = str(value) |
There was a problem hiding this comment.
2. Sequence attributes lose structure 🐞 Bug ⚙ Maintainability
If an attribute value is a list/tuple containing any non-OTEL-primitive element, the new logic converts the entire sequence to a single string via str(value) rather than preserving an OTEL array shape. This collapses potentially structured attribute arrays into one string and reduces queryability/consistency of telemetry attributes.
Agent Prompt
## Issue description
The new sanitizer treats lists/tuples as acceptable only if *all* elements are already OTEL primitives; otherwise it stringifies the entire sequence. This discards list structure even though OTEL supports arrays of primitive values.
## Issue Context
This behavior is introduced by the new `_OTEL_TYPES` check in `_end_otel_span`.
## Fix Focus Areas
- openinference-streaming.patch[82-88]
### Concrete fix approach
Update the sequence handling so that when `value` is a `list`/`tuple`, you sanitize element-by-element and keep the result as a list/tuple of OTEL primitives (commonly `list[str]` when coercion is needed) instead of converting the whole container to a single string.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Quite frequent warning from the Sentry logs:
Invalid type OpenInferenceSpanKindValues for attribute 'openinference.span.kind' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types
Therefore adjust the patch to convert incompatible types via `str`.
Fixes PACKIT-5261
Assisted-by: Claude Opus 4.6
Signed-off-by: Matej Focko <mfocko@packit.dev>
a9b3dc2 to
7689538
Compare
|
Rebasing and merging. |
Quite frequent warning from the Sentry logs:
Therefore adjust the patch to convert incompatible types via
str.Assisted-by: Claude Opus 4.6
Fixes PACKIT-5261