Repository navigation
telemetry header handler - #129
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe PR adds opt-in response-header telemetry. It requests ChangesResponse Header Telemetry
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant RequestWrapper
participant ChargebeeAPI
participant TelemetryAdapter
participant RequestEndSpan
RequestWrapper->>ChargebeeAPI: send Prefer: chargebee-telemetry=include
ChargebeeAPI-->>RequestWrapper: return X-Chargebee-Telemetry
RequestWrapper->>TelemetryAdapter: pass response headers
TelemetryAdapter->>TelemetryAdapter: parse response telemetry
TelemetryAdapter->>RequestEndSpan: merge response attributes
🚥 Pre-merge checks | ✅ 1
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/telemetry/chargebeeTelemetryHeaderParser.ts`:
- Around line 188-234: Update splitOnDelimiter, indexOfParameterSeparator, and
indexOfEquals to recognize backslash-escaped quotes while scanning quoted
values, so escaped quotes do not change inQuotes state and subsequent delimiters
are detected correctly. Add an end-to-end parser test covering an escaped quote
followed by another list item.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: cdcc1b43-61e8-4d18-a788-4bf6d00f934d
📒 Files selected for processing (7)
src/RequestWrapper.tssrc/telemetry/TelemetryAdapter.tssrc/telemetry/chargebeeTelemetryHeaderParser.tssrc/telemetry/index.tssrc/telemetry/types.tstest/chargebeeTelemetryHeaderParser.test.tstest/telemetryAdapter.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@types/index.d.ts`:
- Around line 188-193: Declare the public constants
CHARGEBEE_TELEMETRY_PREFER_HEADER and CHARGEBEE_TELEMETRY_PREFER_VALUE in
types/index.d.ts with their matching literal string types, and add a type-level
import test confirming both are publicly importable from the package entry
point.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: a5d8b3e0-246f-4a30-84ea-e29f000e43db
📒 Files selected for processing (13)
README.mdsrc/RequestWrapper.tssrc/chargebee.cjs.tssrc/chargebee.esm.tssrc/telemetry/TelemetryAdapter.tssrc/telemetry/chargebeeTelemetryHeaderParser.tssrc/telemetry/index.tssrc/telemetry/types.tssrc/types.d.tstest/chargebeeTelemetryHeaderParser.test.tstest/requestWrapper.test.tstest/telemetryAdapter.test.tstypes/index.d.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- src/RequestWrapper.ts
- src/telemetry/index.ts
- src/telemetry/chargebeeTelemetryHeaderParser.ts
- test/chargebeeTelemetryHeaderParser.test.ts
- src/telemetry/types.ts
Co-authored-by: Cursor <cursoragent@cursor.com>
Bump version to 3.37.0 and add changelog and README links to the response telemetry docs.
Validate integers and dates against the RFC 9651 grammar (max 15 digits). A malformed value now skips only that parameter in both SDKs, instead of Java dropping the whole header and Node emitting NaN or a truncated/imprecise number.
RFC 9651 treats a parameter without a value (e.g. cb;cached) as boolean true. Previously it aborted parsing and dropped all telemetry attributes. Malformed parameters (empty key, bad value) and members with an empty token are now skipped individually so the rest of the header is kept, matching the spec's forward-compatibility guidance.
Existing adapters must not be affected by response telemetry. Parsed X-Chargebee-Telemetry values (and the raw header) now go in a separate responseTelemetryAttributes field (Java: getResponseTelemetryAttributes()) instead of being merged into endAttributes. - Node: endAttributes keeps its Record<string, string | number> type, so custom TypeScript adapters that narrow values still compile. The built-in OTel adapter forwards both maps. - Java: getEndAttributes() is unchanged; existing constructors are kept. - endAttributes is identical to the previous release in all scenarios.
extractResponseHeaders returned a native Headers instance as-is when a custom HTTP client threw an error carrying one (err.response.headers or err.headers). Its entries are not own properties, so the X-Chargebee-Telemetry lookup found nothing and telemetry was silently dropped on that error. Convert Headers to a plain record; plain header objects are returned unchanged.
Description
Adds opt-in support for Chargebee response telemetry.
When enabled, the SDK asks Chargebee to include an
X-Chargebee-Telemetryresponse header. The header carries server-side timing, third-party gateway timing, and the features used to serve the request. The SDK parses it and passes the values to yourtelemetryAdapteras span attributes, for both successful and failed requests.Example header:
Attributes added to
result.endAttributes:http.response.header.x-chargebee-telemetrycb;time_ms=3800chargebee.telemetry.cb.time_ms = 3800tp-stripe;pm=cardchargebee.telemetry.tp.stripe.pm = "card"ft-*itemschargebee.telemetry.features = ["consolidated_invoicing", "account_hierarchy"]Values keep their types: numbers, booleans, dates as epoch seconds, and strings. A malformed header never fails the request; only the raw value is recorded.
Changes
preferChargebeeTelemetryconfig option. When set along with atelemetryAdapter, requests includePrefer: chargebee-telemetry=include. APreferheader you set yourself is left untouched.RequestTelemetryResultnow includesresponseHeaders, andendAttributesvalues can bestring | number | boolean | string[].CHARGEBEE_TELEMETRY_PREFER_HEADER,CHARGEBEE_TELEMETRY_PREFER_VALUE.This is independent of the anonymous SDK telemetry header (
sdkTelemetryEnabled).Adds opt-in Chargebee telemetry header support. The adapter adds
Prefer: chargebee-telemetry=include, parsesX-Chargebee-Telemetryfrom successful and failed responses, and records typed request-end attributes. Adds configuration, types, exports, documentation, and tests.