-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: escape periods in attribute keys during flatten/unflatten #3800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { Attributes } from "@opentelemetry/api"; | |
|
|
||
| export const NULL_SENTINEL = "$@null(("; | ||
| export const CIRCULAR_REFERENCE_SENTINEL = "$@circular(("; | ||
| const DOT_ESCAPE = "$@dot"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Escape sequence The Affected data flow
Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| const DEFAULT_MAX_DEPTH = 128; | ||
|
|
||
|
|
@@ -200,7 +201,8 @@ class AttributeFlattener { | |
| break; | ||
| } | ||
|
|
||
| const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`; | ||
| const escapedKey = Array.isArray(obj) ? `[${key}]` : key.replace(/\./g, DOT_ESCAPE); | ||
| const newPrefix = `${prefix ? `${prefix}.` : ""}${escapedKey}`; | ||
|
Comment on lines
+204
to
+205
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Round-trip data corruption for keys naturally containing the The escape sequence Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| if (Array.isArray(value)) { | ||
| for (let i = 0; i < value.length; i++) { | ||
|
|
@@ -280,17 +282,18 @@ export function unflattenAttributes( | |
|
|
||
| const parts = key.split(".").reduce( | ||
| (acc, part) => { | ||
| if (part.startsWith("[") && part.endsWith("]")) { | ||
| const unescaped = part.split(DOT_ESCAPE).join("."); | ||
| if (unescaped.startsWith("[") && unescaped.endsWith("]")) { | ||
| // Handle array indices more precisely | ||
| const match = part.match(/^\[(\d+)\]$/); | ||
| const match = unescaped.match(/^\[(\d+)\]$/); | ||
| if (match && match[1]) { | ||
| acc.push(parseInt(match[1])); | ||
| } else { | ||
| // Remove brackets for non-numeric array keys | ||
| acc.push(part.slice(1, -1)); | ||
| acc.push(unescaped.slice(1, -1)); | ||
| } | ||
| } else { | ||
| acc.push(part); | ||
| acc.push(unescaped); | ||
| } | ||
| return acc; | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 Map keys with dots are not escaped (pre-existing inconsistency)
At line 121, Map string keys are interpolated directly into the prefix without dot escaping:
this.#processValue(value, \${prefix || "map"}.${keyStr}`, depth). This is inconsistent with the new escaping for regular object keys at line 204 (key.replace(/./g, DOT_ESCAPE)). If a Map has a key like"a.b"`, the dot won't be escaped, leading to incorrect unflattening. However, this is a pre-existing issue — Map key handling was already inconsistent before this PR, and Maps are a relatively niche case for OTEL attributes. Not filing as a bug since it's pre-existing, but worth noting for completeness.(Refers to lines 120-121)
Was this helpful? React with 👍 or 👎 to provide feedback.