Skip to content

Chargebee telemetry handling#109

Draft
cb-karthikp wants to merge 1 commit into
v4from
feat/chargebee-telemetry
Draft

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

Conversation

@cb-karthikp

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

Copy link
Copy Markdown
Collaborator

TBA

Adds Chargebee telemetry response-header handling for synchronous and asynchronous requests, including RFC 9651 parsing into typed OpenTelemetry span attributes. Captures headers on successful and failed responses, adds telemetry constants and documentation, and introduces comprehensive parser and integration tests covering valid, absent, and malformed headers.

@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

Walkthrough

Adds RFC 9651 X-Chargebee-Telemetry response-header parsing, propagates raw and typed telemetry attributes into spans for successful and failed requests, tests the behavior, and updates OpenTelemetry documentation and adapter handling.

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 telemetry attribute keys and parses RFC 9651 header values into typed attributes and feature lists, with coverage for scalar values, escaping, examples, and invalid input.
Response header propagation into spans
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/TelemetryExecutorTest.java, src/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java
Carries response headers through successful and failed telemetry results, emits raw and parsed telemetry span attributes, and tests absent and unparseable headers.
OpenTelemetry adapter and documentation
README.md
Documents response-header behavior and extends the example adapter for Double, Boolean, and List<String> attribute values.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Transport
  participant TelemetryExecutor
  participant TelemetrySupport
  participant ChargebeeTelemetryHeaderParser
  participant Span
  Transport->>TelemetryExecutor: Return response with telemetry header
  TelemetryExecutor->>TelemetrySupport: Pass response headers
  TelemetrySupport->>ChargebeeTelemetryHeaderParser: Parse telemetry header
  ChargebeeTelemetryHeaderParser-->>TelemetrySupport: Return typed attributes
  TelemetrySupport->>Span: Add 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
Comment on lines +863 to 867
} else if (v instanceof List) {
@SuppressWarnings("unchecked")
List<String> values = (List<String>) v;
span.setAttribute(k, values);
}

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

🌐 Web query:

OpenTelemetry Java Span setAttribute overloads AttributeKey string array List<String> compile

💡 Result:

In OpenTelemetry Java, the Span interface uses a generic setAttribute method when working with AttributeKey instances [1][2]. To set a string array (or any list-based attribute), you must use an AttributeKey defined for a List type, such as one created via AttributeKey.stringArrayKey(String) [3][4]. The Span.setAttribute method signature is defined as: Span setAttribute(AttributeKey key, T value); When using this with a string array, the value must be a List, not a raw array [3][5]. Example compilation snippet: import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; import java.util.List; // Define the key for a List of Strings AttributeKey<List> MY_ARRAY_KEY = AttributeKey.stringArrayKey("my.string.array"); // Use the key with the span Span span = Span.current; span.setAttribute(MY_ARRAY_KEY, List.of("value1", "value2")); While there are convenience methods on AttributesBuilder that support varargs (e.g., put(String key, String... values)) [6], the primary Span.setAttribute method using AttributeKey requires the value to match the generic type T exactly—in this case, a List [3][1]. If you have a raw array, you must convert it to a List (e.g., via Arrays.asList or List.of) to satisfy the compiler [7].

Citations:


🏁 Script executed:

python3 - <<'PY'
import sys, textwrap, json, os, subprocess, pathlib
print("Need web search results.")
PY

Repository: chargebee/chargebee-java

Length of output: 187


Use AttributeKey.stringArrayKey for list attributes

Span.setAttribute only accepts AttributeKey<T> for non-scalar values, so span.setAttribute(k, values) with a String key and List<String> value has no matching overload. Use a string-array key here:

Fix
-                span.setAttribute(k, values);
+                span.setAttribute(AttributeKey.stringArrayKey(k), values);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (v instanceof List) {
@SuppressWarnings("unchecked")
List<String> values = (List<String>) v;
span.setAttribute(k, values);
}
} else if (v instanceof List) {
`@SuppressWarnings`("unchecked")
List<String> values = (List<String>) v;
span.setAttribute(AttributeKey.stringArrayKey(k), values);
}
🤖 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 `@README.md` around lines 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.

Comment on lines +178 to +224
private static List<String> splitOnDelimiter(String input, char delimiter) {
List<String> parts = new ArrayList<>();
StringBuilder current = new StringBuilder();
boolean inQuotes = false;

for (int i = 0; i < input.length(); i++) {
char currentChar = input.charAt(i);
if (currentChar == '"') {
inQuotes = !inQuotes;
current.append(currentChar);
} else if (currentChar == delimiter && !inQuotes) {
addIfNotBlank(parts, current);
current = new StringBuilder();
} else {
current.append(currentChar);
}
}

addIfNotBlank(parts, current);
return parts;
}

private static int indexOfParameterSeparator(String item) {
boolean inQuotes = false;
for (int i = 0; i < item.length(); i++) {
char current = item.charAt(i);
if (current == '"') {
inQuotes = !inQuotes;
} else if (current == ';' && !inQuotes) {
return i;
}
}
return -1;
}

private static int indexOfEquals(String parameter) {
boolean inQuotes = false;
for (int i = 0; i < parameter.length(); i++) {
char current = parameter.charAt(i);
if (current == '"') {
inQuotes = !inQuotes;
} else if (current == '=' && !inQuotes) {
return i;
}
}
return -1;
}

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 -euo pipefail

file='src/main/java/com/chargebee/v4/telemetry/ChargebeeTelemetryHeaderParser.java'
wc -l "$file"
echo '--- outline ---'
ast-grep outline "$file" --view expanded || true
echo '--- relevant lines ---'
sed -n '1,260p' "$file" | cat -n

Repository: chargebee/chargebee-java

Length of output: 10501


Skip escaped quotes while scanning for delimiters. splitOnDelimiter, indexOfParameterSeparator, and indexOfEquals toggle quote state on every "; a value like desc="a\"b;c" can be split at the ;, and parseToSpanAttributes will drop the whole header on the resulting parse error.

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

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