Skip to content

Sdk telemetry header - #114

Draft
cb-karthikp wants to merge 10 commits into
v4from
sdk-telemetry-header
Draft

Sdk telemetry header#114
cb-karthikp wants to merge 10 commits into
v4from
sdk-telemetry-header

Conversation

@cb-karthikp

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

Copy link
Copy Markdown
Collaborator

TBA

Adds opt-out SDK telemetry with one-time RFC 9651 feature headers for synchronous and asynchronous requests. Separates SDK telemetry from the existing telemetry adapter, adds client configuration and state management, documents the new option, and includes comprehensive tests.

@snyk-io

snyk-io Bot commented Aug 10, 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 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 408425af-40ae-4673-9d56-c248a18bea7d

📥 Commits

Reviewing files that changed from the base of the PR and between c3644e0 and 0267978.

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

Walkthrough

The SDK now emits configurable, anonymous feature telemetry headers once per client. It adds header encoding and emission state, preserves customer telemetry adapter behavior through a separate executor, and documents the opt-out builder setting.

Changes

SDK telemetry

Layer / File(s) Summary
Telemetry contracts and client configuration
src/main/java/com/chargebee/v4/client/ChargebeeClient.java, src/main/java/com/chargebee/v4/telemetry/SdkTelemetryState.java, src/main/java/com/chargebee/v4/telemetry/SdkTelemetryFeature.java, README.md
ChargebeeClient stores the enabled flag and per-client emission state. The builder defaults SDK telemetry to enabled and supports opt-out. Feature codes and usage documentation were added.
Structured telemetry header encoding
src/main/java/com/chargebee/v4/telemetry/SdkTelemetryHeader.java, src/main/java/com/chargebee/v4/telemetry/SdkTelemetryHeaderBuilder.java, src/test/java/com/chargebee/v4/telemetry/SdkTelemetryHeaderBuilderTest.java
The header utilities define the header name and size limit. The builder serializes non-null feature codes and rejects empty or oversized output.
SDK telemetry emission flow
src/main/java/com/chargebee/v4/telemetry/SdkTelemetryEmitter.java, src/test/java/com/chargebee/v4/telemetry/SdkTelemetryEmitterTest.java
The emitter adds feature headers to synchronous and asynchronous requests only when enabled and only once per client. Tests cover suppression, feature tokens, async execution, and client isolation.
Customer telemetry adapter composition
src/main/java/com/chargebee/v4/telemetry/TelemetryExecutor.java, src/main/java/com/chargebee/v4/telemetry/TelemetryAdapterExecutor.java, src/main/java/com/chargebee/v4/telemetry/TelemetrySupport.java, src/test/java/com/chargebee/v4/telemetry/TelemetryExecutorTest.java
TelemetryExecutor composes SDK and customer telemetry. TelemetryAdapterExecutor handles adapter lifecycle events, headers, request context, results, and failures without suppressing API outcomes.

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

Sequence Diagram(s)

sequenceDiagram
  participant ChargebeeClient
  participant TelemetryExecutor
  participant SdkTelemetryEmitter
  participant TelemetryAdapterExecutor
  participant APITransport
  ChargebeeClient->>TelemetryExecutor: execute request
  TelemetryExecutor->>SdkTelemetryEmitter: apply SDK telemetry header
  TelemetryExecutor->>TelemetryAdapterExecutor: execute customer telemetry
  TelemetryAdapterExecutor->>APITransport: send request
  APITransport-->>TelemetryAdapterExecutor: response or API exception
  TelemetryAdapterExecutor-->>TelemetryExecutor: preserve API result or exception
Loading
🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.38% 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/java/com/chargebee/v4/telemetry/SdkTelemetryHeaderBuilder.java`:
- Around line 110-141: Update appendBareParam to use the value unquoted only
when isSfToken returns true; otherwise serialize it with escapeSfString. Ensure
values containing characters outside the RFC 9651 sf-string ASCII range are
rejected, including validation in the path also covered by the related call
site, and update the test expectation so versions such as 4.14.0 are emitted as
escaped sf-strings.
🪄 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: 369497c2-82fe-419c-9cdc-afdea5fc43ea

📥 Commits

Reviewing files that changed from the base of the PR and between 26d271e and 1a0b26c.

📒 Files selected for processing (13)
  • README.md
  • src/main/java/com/chargebee/v4/client/ChargebeeClient.java
  • src/main/java/com/chargebee/v4/telemetry/SdkTelemetryEmitter.java
  • src/main/java/com/chargebee/v4/telemetry/SdkTelemetryHeader.java
  • src/main/java/com/chargebee/v4/telemetry/SdkTelemetryHeaderBuilder.java
  • src/main/java/com/chargebee/v4/telemetry/SdkTelemetrySnapshot.java
  • src/main/java/com/chargebee/v4/telemetry/SdkTelemetryState.java
  • src/main/java/com/chargebee/v4/telemetry/TelemetryAdapterExecutor.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/SdkTelemetryEmitterTest.java
  • src/test/java/com/chargebee/v4/telemetry/SdkTelemetryHeaderBuilderTest.java
  • src/test/java/com/chargebee/v4/telemetry/TelemetryExecutorTest.java

Comment on lines +110 to +141
/** Emits a bare {@code key=value}, or a quoted sf-string when the value needs escaping. */
private static boolean appendBareParam(StringBuilder segment, String key, String value) {
if (!isNotBlank(value)) {
return false;
}
if (containsInvalidSfStringChar(value)) {
return false;
}
String trimmed = value.trim();
String serialized = isBareSafe(trimmed) ? trimmed : escapeSfString(trimmed);
if (serialized == null) {
return false;
}
segment.append(';').append(key).append('=').append(serialized);
return true;
}

/** Whether {@code value} can be emitted unquoted without corrupting the sf-list. */
private static boolean isBareSafe(String value) {
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (ch == '"'
|| ch == '\\'
|| ch == ','
|| ch == ';'
|| ch == '='
|| Character.isWhitespace(ch)) {
return false;
}
}
return !value.isEmpty();
}

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 | 🔴 Critical | ⚡ Quick win

Serialize only valid structured-field values.

appendBareParam emits version=4.14.0 for normal SDK versions. This is not a valid sf-token or sf-decimal. The telemetry server can reject the complete header.

Use an sf-token only when isSfToken returns true. Otherwise, emit an escaped sf-string. Reject all characters outside the RFC 9651 sf-string ASCII range. Update the test that expects the unquoted version.

Proposed fix
-    String serialized = isBareSafe(trimmed) ? trimmed : escapeSfString(trimmed);
+    String serialized = isSfToken(trimmed) ? trimmed : escapeSfString(trimmed);
-      if (ch == '\0' || ch == '\n' || ch == '\r') {
+      if (ch < 0x20 || ch > 0x7E) {
         return true;
       }

Also applies to: 186-195

🤖 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/SdkTelemetryHeaderBuilder.java`
around lines 110 - 141, Update appendBareParam to use the value unquoted only
when isSfToken returns true; otherwise serialize it with escapeSfString. Ensure
values containing characters outside the RFC 9651 sf-string ASCII range are
rejected, including validation in the path also covered by the related call
site, and update the test expectation so versions such as 4.14.0 are emitted as
escaped sf-strings.

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