Skip to content

Chargebee telemetry handling - #109

Draft
cb-karthikp wants to merge 8 commits into
v4from
feat/chargebee-telemetry
Draft

Chargebee telemetry handling#109
cb-karthikp wants to merge 8 commits into
v4from
feat/chargebee-telemetry

Conversation

@cb-karthikp

@cb-karthikp cb-karthikp commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

TBA

Adds opt-in Chargebee telemetry support. Clients can request X-Chargebee-Telemetry response data through Prefer, capture response headers, and export raw and parsed values as typed OpenTelemetry span attributes. Adds RFC 9651 parsing, documentation, client configuration, and comprehensive tests.

@snyk-io

snyk-io Bot commented Jul 15, 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 Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds opt-in response telemetry capture. The client sends the telemetry preference, telemetry execution preserves response headers, and TelemetrySupport exports raw and parsed X-Chargebee-Telemetry values as span attributes. A typed RFC 9651 parser, tests, and documentation are included.

Changes

Response telemetry header

Layer / File(s) Summary
Telemetry header parser and attributes
src/main/java/com/chargebee/v4/telemetry/TelemetryAttributeKeys.java, src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java, src/test/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParserTest.java
Defines response telemetry constants and parses RFC 9651 header values into typed attributes. Tests cover features, scalar values, quoted strings, escaped delimiters, and malformed input.
Client preference and request execution
src/main/java/com/chargebee/v4/client/ChargebeeClient.java, src/main/java/com/chargebee/v4/telemetry/TelemetryExecutor.java, src/test/java/com/chargebee/v4/telemetry/TelemetryExecutorTest.java
Adds the disabled-by-default client preference. Synchronous and asynchronous telemetry requests optionally send Prefer: chargebee-telemetry=include and retain response headers for success and failure telemetry.
Response header propagation into spans
src/main/java/com/chargebee/v4/telemetry/TelemetrySupport.java, src/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java, src/test/java/com/chargebee/v4/models/BaseResponseTest.java
Stores response headers in telemetry results, performs case-insensitive lookup, extracts headers from HTTP errors, and exports raw and parsed telemetry attributes. Tests cover absent and malformed headers, preference injection, immutable requests, and null header keys.
OpenTelemetry adapter and documentation
README.md
Documents response telemetry opt-in, RFC 9651 formatting, attribute mappings, and parsing behavior. The example adapter maps Double, Boolean, and List<String> values.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ChargebeeClient
  participant TelemetryExecutor
  participant Transport
  participant TelemetrySupport
  participant ChargebeeTelemetryHeaderParser
  participant OpenTelemetrySpan
  ChargebeeClient->>TelemetryExecutor: telemetry preference
  TelemetryExecutor->>Transport: request with optional Prefer header
  Transport-->>TelemetryExecutor: response with X-Chargebee-Telemetry
  TelemetryExecutor->>TelemetrySupport: response headers
  TelemetrySupport->>ChargebeeTelemetryHeaderParser: telemetry header value
  ChargebeeTelemetryHeaderParser-->>TelemetrySupport: typed attributes
  TelemetrySupport->>OpenTelemetrySpan: raw and parsed 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: 2

🤖 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 `@README.md`:
- Around line 863-867: Update the List branch in the README example to
create/use an AttributeKey via AttributeKey.stringArrayKey for the attribute
name before calling span.setAttribute, while preserving the existing String list
conversion and suppression behavior.

In
`@src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java`:
- Around line 178-224: Update splitOnDelimiter, indexOfParameterSeparator, and
indexOfEquals to recognize escaped quotes and avoid toggling inQuotes when a
quote is preceded by an escape character. Ensure delimiters and equals signs
inside quoted values such as desc="a\"b;c" remain part of the value, while
unescaped quotes continue to change quote state.
🪄 Autofix (Beta)

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: 24b5d2f6-4f0b-4078-bbfb-3695f34701d6

📥 Commits

Reviewing files that changed from the base of the PR and between d17faaf and 2742928.

📒 Files selected for processing (8)
  • README.md
  • src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java
  • src/main/java/com/chargebee/v4/telemetry/TelemetryAttributeKeys.java
  • src/main/java/com/chargebee/v4/telemetry/TelemetryExecutor.java
  • src/main/java/com/chargebee/v4/telemetry/TelemetrySupport.java
  • src/test/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParserTest.java
  • src/test/java/com/chargebee/v4/telemetry/TelemetryExecutorTest.java
  • src/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java

Comment thread README.md

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java (2)

150-167: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject invalid SF-string escapes and quotes.

parseStringValue accepts \q and unescaped inner quotes. RFC 9651 permits only \" and \\. Throw IllegalArgumentException for all other escapes and for " before the closing delimiter.

🤖 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/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java`
around lines 150 - 167, Update parseStringValue to accept only escaped quote and
backslash sequences, throwing IllegalArgumentException for any other escape
character. While scanning the string, also reject unescaped inner double quotes
before the final delimiter, while preserving valid decoded content and the
existing unterminated-escape validation.

21-22: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Enforce RFC 9651 numeric bounds before conversion.

The patterns accept invalid values such as ratio=1.2345 and a 16-digit integer. The @ branch also bypasses these checks. Validate integer, decimal, and date grammar before numeric conversion so invalid telemetry uses the documented raw-only fallback.

🤖 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/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java`
around lines 21 - 22, Update ChargebeeTelemetryHeaderParser’s numeric parsing to
enforce RFC 9651 bounds and grammar before conversion: restrict integers and
decimals to their documented digit and precision limits, validate date syntax
similarly, and apply the same validation in the @ branch. Route any invalid
value to the existing raw-only fallback rather than converting it.
🤖 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/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java`:
- Around line 124-131: The telemetry Prefer helper is missing and must merge,
rather than suppress, existing preferences. Add the CHARGEBEE_TELEMETRY_PREFER_*
constants and implement TelemetrySupport.applyResponseTelemetryPreferHeader so
it appends chargebee-telemetry=include to any existing Prefer value while
preserving the existing value; update TelemetrySupportTest.java lines 124-131
and TelemetryExecutorTest.java lines 494-506 to assert both preferences.

---

Outside diff comments:
In
`@src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java`:
- Around line 150-167: Update parseStringValue to accept only escaped quote and
backslash sequences, throwing IllegalArgumentException for any other escape
character. While scanning the string, also reject unescaped inner double quotes
before the final delimiter, while preserving valid decoded content and the
existing unterminated-escape validation.
- Around line 21-22: Update ChargebeeTelemetryHeaderParser’s numeric parsing to
enforce RFC 9651 bounds and grammar before conversion: restrict integers and
decimals to their documented digit and precision limits, validate date syntax
similarly, and apply the same validation in the @ branch. Route any invalid
value to the existing raw-only fallback rather than converting it.
🪄 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: 7370c852-9502-48eb-a217-222e90180b5a

📥 Commits

Reviewing files that changed from the base of the PR and between 272eb27 and e100e46.

📒 Files selected for processing (7)
  • README.md
  • src/main/java/com/chargebee/v4/client/ChargebeeClient.java
  • src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java
  • src/main/java/com/chargebee/v4/telemetry/TelemetryExecutor.java
  • src/test/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParserTest.java
  • src/test/java/com/chargebee/v4/telemetry/TelemetryExecutorTest.java
  • src/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • src/test/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParserTest.java

Comment thread src/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java

@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/java/com/chargebee/v4/telemetry/TelemetrySupport.java`:
- Around line 327-330: Update both overloads in TelemetrySupport that inspect
requestHeaders so they evaluate the Prefer header values, not just the header
name. Preserve an existing chargebee-telemetry preference, but append
chargebee-telemetry=include when other Prefer values exist without that
directive, including return=minimal.
🪄 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: 7594e20a-8e10-48cd-96c5-9d5639eca190

📥 Commits

Reviewing files that changed from the base of the PR and between e100e46 and ae99e67.

📒 Files selected for processing (2)
  • src/main/java/com/chargebee/v4/telemetry/TelemetryAttributeKeys.java
  • src/main/java/com/chargebee/v4/telemetry/TelemetrySupport.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/chargebee/v4/telemetry/TelemetryAttributeKeys.java

Comment on lines +327 to +330
for (String name : requestHeaders.keySet()) {
if (name.equalsIgnoreCase(TelemetryAttributeKeys.CHARGEBEE_TELEMETRY_PREFER_HEADER)) {
return;
}

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

Check the Prefer value, not only its header name.

Both overloads return when any Prefer header exists. For example, Prefer: return=minimal prevents adding chargebee-telemetry=include, so the server does not return X-Chargebee-Telemetry even when telemetry capture is enabled.

Inspect the existing Prefer value for the Chargebee directive. Append chargebee-telemetry=include when that directive is absent. Preserve an explicit existing Chargebee telemetry preference.

As per path instructions, this is a merge-blocking functionality issue.

Also applies to: 342-345

🤖 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/java/com/chargebee/v4/telemetry/TelemetrySupport.java` around lines
327 - 330, Update both overloads in TelemetrySupport that inspect requestHeaders
so they evaluate the Prefer header values, not just the header name. Preserve an
existing chargebee-telemetry preference, but append chargebee-telemetry=include
when other Prefer values exist without that directive, including return=minimal.

Source: Path instructions

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