Conversation
This uses the string passed into `getSentryResource` as a fallback, preferring instead to use the value in `env.OTEL_SERVICE_NAME` if set, or the `service.name` field in the comma-delimited key=value pairs in `env.OTEL_RESOURCE_ATTRIBUTES` pairs. Additional `env.OTEL_RESOURCE_ATTRIBUTES` are also attached to the resource attributes. fix: js-2280 fix: #20502
| for (const pair of raw.split(',')) { | ||
| const eq = pair.trim().indexOf('='); | ||
| if (eq === -1) { | ||
| continue; | ||
| } | ||
| const key = pair.substring(0, eq).trim(); | ||
| const value = pair.substring(eq + 1).trim(); |
There was a problem hiding this comment.
Bug: The code calculates an index on a trimmed string but applies it to the untrimmed string, causing incorrect parsing of resource attributes with leading spaces.
Severity: HIGH
Suggested Fix
Trim the pair string first and store it in a variable. Use this new trimmed variable for both finding the index of the = separator and for the subsequent substring calls to extract the key and value.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/opentelemetry/src/resource.ts#L51-L57
Potential issue: In `parseOtelResourceAttributes`, the index of the `=` separator is
calculated on a trimmed string (`pair.trim().indexOf('=')`) but is then applied to the
original, untrimmed `pair` string for substring operations. If an attribute pair has
leading whitespace, such as from an input like `"key1=value1, key2=value2"`, the
resulting pair `" key2=value2"` will be parsed incorrectly. The key will be truncated
(e.g., to `"key"`) and the value will be malformed (e.g., to `"=value2"`), causing
silent corruption of telemetry attributes.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 65f6897. Configure here.
| continue; | ||
| } | ||
| const key = pair.substring(0, eq).trim(); | ||
| const value = pair.substring(eq + 1).trim(); |
There was a problem hiding this comment.
Leading whitespace corrupts parsed key/value pairs
High Severity
In parseOtelResourceAttributes, the index for splitting key=value pairs is calculated on a trimmed string but applied to the untrimmed input. This causes leading whitespace to corrupt resource attribute keys and values, silently affecting attributes like service.name when parsing OTEL_RESOURCE_ATTRIBUTES.
Reviewed by Cursor Bugbot for commit 65f6897. Configure here.
size-limit report 📦
|


This uses the string passed into
getSentryResourceas a fallback, preferring instead to use the value inenv.OTEL_SERVICE_NAMEif set, or theservice.namefield in the comma-delimited key=value pairs inenv.OTEL_RESOURCE_ATTRIBUTESpairs.Additional
env.OTEL_RESOURCE_ATTRIBUTESare also attached to the resource attributes.fix: js-2280
fix: #20502
yarn lint) & (yarn test).Closes #20502