Feat/cb response header - #108
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. |
WalkthroughThe generators now emit response telemetry support for Java and Node SDKs. The generated SDKs can request Chargebee telemetry headers, parse structured header values, and add parsed attributes to request-end telemetry. Generator tests cover the new files, exports, headers, and typings. ChangesResponse telemetry
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Request
participant TelemetryAdapter
participant Response
participant ChargebeeTelemetryHeaderParser
participant Span
Request->>TelemetryAdapter: Add Prefer header when absent
TelemetryAdapter->>Response: Send request
Response-->>TelemetryAdapter: Return X-Chargebee-Telemetry
TelemetryAdapter->>ChargebeeTelemetryHeaderParser: Parse header value
ChargebeeTelemetryHeaderParser-->>TelemetryAdapter: Return typed attributes
TelemetryAdapter->>Span: Add response telemetry attributes
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 warning)
Comment |
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/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbs`:
- Around line 297-308: Update the header extraction logic in the error-header
handling path to detect native Headers instances and convert them into a plain
record before returning. Apply this normalization to both nested
response.headers and top-level errorObj.headers, while preserving existing
handling for ordinary header objects.
🪄 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: 02d8e069-dc76-4610-870c-bf42797757d4
📒 Files selected for processing (17)
src/main/java/com/chargebee/sdk/java/v4/JavaV4.javasrc/main/java/com/chargebee/sdk/node/NodeV3.javasrc/main/resources/templates/java/telemetry/ChargebeeTelemetryHeaderParser.java.hbssrc/main/resources/templates/java/telemetry/TelemetryAttributeKeys.java.hbssrc/main/resources/templates/java/telemetry/TelemetrySupport.java.hbssrc/main/resources/templates/node/chargebee_cjs.ts.hbssrc/main/resources/templates/node/chargebee_esm.ts.hbssrc/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbssrc/main/resources/templates/node/telemetry/chargebeeTelemetryHeaderParser.ts.hbssrc/main/resources/templates/node/telemetry/index.ts.hbssrc/main/resources/templates/node/telemetry/otel.ts.hbssrc/main/resources/templates/node/telemetry/types.ts.hbssrc/main/resources/templates/ts/typings/v3/index.d.ts.hbssrc/test/java/com/chargebee/sdk/java/v4/JavaV4BaseResponseTest.javasrc/test/java/com/chargebee/sdk/java/v4/JavaV4TelemetryTest.javasrc/test/java/com/chargebee/sdk/node/NodeV3Tests.javasrc/test/java/com/chargebee/sdk/ts/typings/TypeScriptTypingV3Tests.java
| const errorObj = err as Record<string, unknown>; | ||
| const response = errorObj.response; | ||
| if (response != null && typeof response === 'object') { | ||
| const headers = (response as Record<string, unknown>).headers; | ||
| if (headers != null && typeof headers === 'object') { | ||
| return headers as ResponseHeadersForTelemetry; | ||
| } | ||
| } | ||
|
|
||
| const headers = errorObj.headers; | ||
| if (headers != null && typeof headers === 'object') { | ||
| return headers as ResponseHeadersForTelemetry; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
file="$(git ls-files | grep -F 'src/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbs' | head -n 1)"
printf '%s\n' "$file"
wc -l "$file"
sed -n '250,340p' "$file"
printf '\n-- related symbols --\n'
rg -n -C 4 'ResponseHeadersForTelemetry|getResponseHeaderValueIgnoreCase|extractResponseHeaders|HttpClientInterface' .Repository: chargebee/sdk-generator
Length of output: 45176
🏁 Script executed:
#!/bin/bash
set -eu
file='src/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbs'
sed -n '105,165p' "$file"
sed -n '1,105p' "$file"
printf '\n-- response and error flow --\n'
rg -n -C 6 'extractResponseHeaders|responseHeaders|makeApiRequest|throw|new .*Error|response:' src/main/resources/templates/nodeRepository: chargebee/sdk-generator
Length of output: 44815
🏁 Script executed:
#!/bin/bash
set -eu
node - <<'JS'
const headers = new Headers([['X-Chargebee-Telemetry', 'trace-id']]);
console.log(JSON.stringify({
entries: Object.entries(headers),
indexedLookup: headers['X-Chargebee-Telemetry'],
getLookup: headers.get('x-chargebee-telemetry'),
iterableEntries: [...headers.entries()],
}));
JSRepository: chargebee/sdk-generator
Length of output: 419
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '-- all call sites --'
rg -n -C 8 'extractResponseHeaders|buildRequestTelemetryResult|onRequestEnd' src/main/resources src/test
printf '%s\n' '-- client templates and generated error shapes --'
rg -n -C 10 'makeApiRequest|httpClient|response\.headers|headers' src/main/resources/templates/node src/main/resources/templates/ts | head -n 500Repository: chargebee/sdk-generator
Length of output: 50379
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '-- telemetry integration call sites --'
rg -n -C 6 'telemetryAdapter|buildRequestTelemetryResult|responseHeaders|extractResponseHeaders' src/main/resources/templates/node --glob '*.hbs'
printf '%s\n' '-- candidate Node request/client templates --'
git ls-files 'src/main/resources/templates/node/**' | grep -Ei '(client|request|resource|chargebee|telemetry)' | head -n 120Repository: chargebee/sdk-generator
Length of output: 9884
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '-- all telemetry adapter references --'
rg -n -C 5 'telemetryAdapter|extractResponseHeaders|responseHeaders' src/main/resources --glob '*.{hbs,ts,js}' | grep -vE 'TelemetryAdapter\.ts\.hbs|telemetry/index\.ts\.hbs|telemetry/types\.ts\.hbs|telemetry/otel\.ts\.hbs' | head -n 300
printf '%s\n' '-- Fetch client implementation --'
fd -i 'FetchClient' src/main/resources
fd -i 'client' src/main/resources/templates | head -n 80Repository: chargebee/sdk-generator
Length of output: 27137
Normalize native Headers before returning it.
Object.entries(new Headers(...)) is empty, so getResponseHeaderValueIgnoreCase cannot find X-Chargebee-Telemetry. Convert native Headers to a plain record in both the nested response.headers and top-level headers paths.
🤖 Prompt for 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.
In `@src/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbs` around
lines 297 - 308, Update the header extraction logic in the error-header handling
path to detect native Headers instances and convert them into a plain record
before returning. Apply this normalization to both nested response.headers and
top-level errorObj.headers, while preserving existing handling for ordinary
header objects.
TBA
Added Chargebee response telemetry support for Java and Node SDK generators. The changes add telemetry header parsing, response-header span attributes, opt-in
Preferheaders, expanded telemetry types, public exports, andpreferChargebeeTelemetryconfiguration. Updated tests verify generated files, header handling, parsing, and TypeScript typings.