Skip to content

Otel integrations#108

Merged
cb-alish merged 9 commits into
v4from
otel-integrations
Jul 1, 2026
Merged

Otel integrations#108
cb-alish merged 9 commits into
v4from
otel-integrations

Conversation

@cb-karthikp

@cb-karthikp cb-karthikp commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds an optional telemetryAdapter hook for tracing Chargebee API calls via OpenTelemetry (or any APM), configurable on the client (ChargebeeClient.Builder#telemetryAdapter) or per call (RequestOptions.Builder#telemetryAdapter)
  • Emits one CLIENT span per API call: chargebee.{resource}.{operation} with OTel HTTP semantic-convention + chargebee.* attributes
  • Adapter can inject W3C trace context (traceparent/tracestate) into outbound request headers for distributed tracing
  • OpenTelemetry is not bundled — customers add the OTel SDK to their app, implement TelemetryAdapter, and pass it to the client
  • Adapter is held by reference (never cloned/deep-copied) and propagated across RequestOptions copies, so class-based adapters are preserved
  • Regenerated services wire resource/operation names into each call (used for span naming); adds a convenience updateGift(String giftId) overload
  • Adds unit tests (TelemetryExecutorTest) and README docs; bumps version to 4.12.0 with a changelog entry

Introduced optional telemetryAdapter hooks (client + per-request) to emit one OpenTelemetry-compatible CLIENT span per Chargebee API call (chargebee.{resource}.{operation}) with chargebee.*/HTTP attributes and optional W3C trace-context header injection. Updated generated service wiring to pass resource/operation names, added updateGift(String) overload, plus tests/docs and a 4.12.0 version/changelog bump.

@cb-karthikp cb-karthikp marked this pull request as draft June 30, 2026 09:02
@snyk-io

snyk-io Bot commented Jun 30, 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

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

@coderabbitai

coderabbitai Bot commented Jun 30, 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: f848d42d-9ff6-4f22-ab94-ed166eef1ade

📥 Commits

Reviewing files that changed from the base of the PR and between f69935a and c3b9fe2.

📒 Files selected for processing (5)
  • 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/TelemetryExecutorTest.java
  • src/test/java/com/chargebee/v4/telemetry/TelemetrySupportTest.java
✅ Files skipped from review due to trivial changes (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/TelemetryExecutor.java

Walkthrough

Adds optional OpenTelemetry tracing (v4.12.0) via a TelemetryAdapter interface. All service classes now pass explicit (resource, operation, path, payload) to BaseService HTTP helpers instead of (path, payload), enabling TelemetryExecutor to produce named CLIENT spans. Adapters can be set at client or per-request level. Also adds GiftService.updateGift(String) no-arg overload.

Changes

OpenTelemetry Telemetry + Service Operation Identifiers

Layer / File(s) Summary
Telemetry interface and data types
src/main/java/com/chargebee/v4/telemetry/TelemetryAdapter.java, TelemetryAttributeKeys.java, RequestTelemetryContext.java, RequestTelemetryError.java, RequestTelemetryResult.java
TelemetryAdapter interface with onRequestStart/onRequestEnd hooks; TelemetryAttributeKeys constants for OTel + Chargebee span attributes; immutable context/result/error data classes with normalized attribute maps.
TelemetrySupport and TelemetryExecutor
src/main/java/com/chargebee/v4/telemetry/TelemetrySupport.java, TelemetryExecutor.java
TelemetrySupport builds span names, start/end attribute maps, and extracts RequestTelemetryError from APIException/HttpException. TelemetryExecutor wraps sync and async request execution: resolves per-request adapter override, calls onRequestStart with mutable headers, injects trace headers, calls onRequestEnd with elapsed time and HTTP status (defaults 500 on failure), logs adapter errors at WARNING without propagating them.
Request, RequestOptions, and ChargebeeClient wiring
src/main/java/com/chargebee/v4/transport/Request.java, src/main/java/com/chargebee/v4/client/request/RequestOptions.java, src/main/java/com/chargebee/v4/client/ChargebeeClient.java
Request gains telemetryResource, telemetryOperation, telemetryAdapterOverride fields with hasTelemetryMetadata(). RequestOptions gains a TelemetryAdapter field propagated through withHeader copies and Builder. ChargebeeClient stores adapter from Builder, routes sendWithRetry/sendWithRetryAsync through TelemetryExecutor, and propagates telemetry fields in addDefaultHeaders.
BaseService telemetry-aware HTTP helper overloads
src/main/java/com/chargebee/v4/services/BaseService.java
New applyTelemetry helper and protected get/post/postJson/getAsync/postAsync overloads (including subdomain variants) accepting (resource, operation, path, payload) that stamp telemetry metadata onto each outbound Request.Builder.
Service operation identifier propagation
src/main/java/com/chargebee/v4/services/*
All ~70 service classes updated to call the new (resource, operation, path, payload) overloads so each Request carries telemetryResource and telemetryOperation for span naming.
Tests, README, version
src/test/java/com/chargebee/v4/telemetry/TelemetryExecutorTest.java, src/test/java/com/chargebee/v4/services/ServiceTelemetryOptionsTest.java, README.md, CHANGELOG.md, VERSION, build.gradle.kts
TelemetryExecutorTest covers: no-adapter skip, adapter hooks called once across retries (traceparent header present on retry attempts), resilience to throwing adapters, WARNING-level logging. ServiceTelemetryOptionsTest covers per-request adapter via RequestOptions and no-adapter skip. README adds full OTel setup + OtelTelemetryAdapter example. Version bumped to 4.12.0.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


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

cb-karthikp and others added 4 commits June 30, 2026 14:32
Verifies that a TelemetryAdapter set per call through
RequestOptions/withOptions fires for that request, and that telemetry
is skipped when no adapter is configured on the call or client.

Co-authored-by: Cursor <cursoragent@cursor.com>

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

🧹 Nitpick comments (1)
src/test/java/com/chargebee/v4/services/ServiceTelemetryOptionsTest.java (1)

100-107: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

noAdapterSkips is a no-op assertion. The adapter is never attached to the client or RequestOptions, so adapter.events is guaranteed empty regardless of telemetry behavior — the test would pass even if the skip logic were broken. Drive the request through an adapter that would record, but configured with no client/per-request adapter, to actually exercise the skip path.

♻️ Suggested approach
   void noAdapterSkips() throws Exception {
-    RecordingAdapter adapter = new RecordingAdapter();
     TestService service = new TestService(clientWithoutAdapter());
 
-    service.ping();
-
-    assertTrue(adapter.events.isEmpty());
+    // No adapter on client or RequestOptions; telemetry must be skipped.
+    Response response = service.ping();
+    assertEquals(200, response.getStatusCode());
   }

A stronger variant: install a recording adapter that throws if invoked, then assert ping() still succeeds.

🤖 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/test/java/com/chargebee/v4/services/ServiceTelemetryOptionsTest.java`
around lines 100 - 107, The no-op assertion in noAdapterSkips does not exercise
the skip path because the RecordingAdapter is never wired into
clientWithoutAdapter() or RequestOptions, so its events stay empty regardless of
behavior. Update the test to route TestService.ping() through a RecordingAdapter
that would record or throw if invoked, while still configuring no
client/per-request adapter, so the request actually proves telemetry is skipped.
Keep the assertion focused on ping() succeeding and the adapter remaining
untouched, using the existing noAdapterSkips, RecordingAdapter, and
clientWithoutAdapter helpers to locate the change.
🤖 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.

Nitpick comments:
In `@src/test/java/com/chargebee/v4/services/ServiceTelemetryOptionsTest.java`:
- Around line 100-107: The no-op assertion in noAdapterSkips does not exercise
the skip path because the RecordingAdapter is never wired into
clientWithoutAdapter() or RequestOptions, so its events stay empty regardless of
behavior. Update the test to route TestService.ping() through a RecordingAdapter
that would record or throw if invoked, while still configuring no
client/per-request adapter, so the request actually proves telemetry is skipped.
Keep the assertion focused on ping() succeeding and the adapter remaining
untouched, using the existing noAdapterSkips, RecordingAdapter, and
clientWithoutAdapter helpers to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 791137b5-d4c8-4158-a12d-c0cbfca7f8ca

📥 Commits

Reviewing files that changed from the base of the PR and between 87f5d31 and f69935a.

📒 Files selected for processing (1)
  • src/test/java/com/chargebee/v4/services/ServiceTelemetryOptionsTest.java

@cb-karthikp cb-karthikp marked this pull request as ready for review July 1, 2026 08:42
@cb-alish cb-alish self-requested a review July 1, 2026 09:46
@cb-alish cb-alish merged commit d17faaf into v4 Jul 1, 2026
8 checks passed
@cb-alish cb-alish deleted the otel-integrations branch July 1, 2026 09:47
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.

2 participants