-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(core): escape periods in attribute keys during flatten/unflatten (#1510) #3857
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. 🚩 Cross-version SDK/webapp compatibility considerations This is a Was 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); | ||
|
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 sentinel The Reproduction exampleflattenAttributes({"x$@DOty": 1}) → {"x$@DOty": 1} Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
| const newPrefix = `${prefix ? `${prefix}.` : ""}${escapedKey}`; | ||
|
|
||
| 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 — inconsistency with object key escaping
The PR escapes dots in regular object keys at line 204, but Map keys at
packages/core/src/v3/utils/flattenAttributes.ts:120-121are used directly without dot escaping:this.#processValue(value, \${prefix || "map"}.${keyStr}`, depth)`. This means Map keys containing dots will still be incorrectly split during unflattening, just as they were before this PR. While Maps can't be round-tripped anyway (they become plain objects during unflatten), this is an incomplete fix that could confuse developers who expect consistent behavior.(Refers to lines 120-121)
Was this helpful? React with 👍 or 👎 to provide feedback.