Skip to content

Feat/cb response header - #108

Open
cb-karthikp wants to merge 3 commits into
mainfrom
feat/cb-response-header
Open

Feat/cb response header#108
cb-karthikp wants to merge 3 commits into
mainfrom
feat/cb-response-header

Conversation

@cb-karthikp

@cb-karthikp cb-karthikp commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

TBA

Added Chargebee response telemetry support for Java and Node SDK generators. The changes add telemetry header parsing, response-header span attributes, opt-in Prefer headers, expanded telemetry types, public exports, and preferChargebeeTelemetry configuration. Updated tests verify generated files, header handling, parsing, and TypeScript typings.

@snyk-io

snyk-io Bot commented Aug 12, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues
Secrets 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The 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.

Changes

Response telemetry

Layer / File(s) Summary
Telemetry contracts and header parsers
src/main/resources/templates/java/telemetry/*, src/main/resources/templates/node/telemetry/chargebeeTelemetryHeaderParser.ts.hbs, src/main/resources/templates/node/telemetry/types.ts.hbs, src/main/resources/templates/ts/typings/v3/index.d.ts.hbs
Telemetry constants and result types now include response headers. Java and Node parsers convert structured telemetry headers into typed attributes.
Java response telemetry integration
src/main/resources/templates/java/telemetry/TelemetrySupport.java.hbs, src/main/java/com/chargebee/sdk/java/v4/JavaV4.java
Java telemetry stores response headers, applies the telemetry Prefer header, extracts response headers, and merges parsed attributes into request-end spans.
Node response telemetry integration
src/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbs, src/main/resources/templates/node/telemetry/index.ts.hbs, src/main/resources/templates/node/telemetry/otel.ts.hbs, src/main/resources/templates/node/chargebee_*.ts.hbs, src/main/java/com/chargebee/sdk/node/NodeV3.java
Node telemetry adds response-header handling, parser exports, preference constants, error extraction, and generated parser output.
Generated output validation
src/test/java/com/chargebee/sdk/java/v4/*, src/test/java/com/chargebee/sdk/node/NodeV3Tests.java, src/test/java/com/chargebee/sdk/ts/typings/TypeScriptTypingV3Tests.java
Tests validate generated files, response-header behavior, parser behavior, exports, and updated TypeScript declarations.

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
Loading
🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e335505 and 16bb9ed.

📒 Files selected for processing (17)
  • src/main/java/com/chargebee/sdk/java/v4/JavaV4.java
  • src/main/java/com/chargebee/sdk/node/NodeV3.java
  • src/main/resources/templates/java/telemetry/ChargebeeTelemetryHeaderParser.java.hbs
  • src/main/resources/templates/java/telemetry/TelemetryAttributeKeys.java.hbs
  • src/main/resources/templates/java/telemetry/TelemetrySupport.java.hbs
  • src/main/resources/templates/node/chargebee_cjs.ts.hbs
  • src/main/resources/templates/node/chargebee_esm.ts.hbs
  • src/main/resources/templates/node/telemetry/TelemetryAdapter.ts.hbs
  • src/main/resources/templates/node/telemetry/chargebeeTelemetryHeaderParser.ts.hbs
  • src/main/resources/templates/node/telemetry/index.ts.hbs
  • src/main/resources/templates/node/telemetry/otel.ts.hbs
  • src/main/resources/templates/node/telemetry/types.ts.hbs
  • src/main/resources/templates/ts/typings/v3/index.d.ts.hbs
  • src/test/java/com/chargebee/sdk/java/v4/JavaV4BaseResponseTest.java
  • src/test/java/com/chargebee/sdk/java/v4/JavaV4TelemetryTest.java
  • src/test/java/com/chargebee/sdk/node/NodeV3Tests.java
  • src/test/java/com/chargebee/sdk/ts/typings/TypeScriptTypingV3Tests.java

Comment on lines +297 to +308
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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/node

Repository: 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()],
}));
JS

Repository: 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 500

Repository: 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 120

Repository: 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 80

Repository: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant