Skip to content

feat(kotlin): trace sandbox pool warmup with OpenTelemetry - #1524

Open
Pangjiping wants to merge 2 commits into
opensandbox-group:mainfrom
Pangjiping:feat/kotlin-pool-warmup-tracing
Open

feat(kotlin): trace sandbox pool warmup with OpenTelemetry#1524
Pangjiping wants to merge 2 commits into
opensandbox-group:mainfrom
Pangjiping:feat/kotlin-pool-warmup-tracing

Conversation

@Pangjiping

Copy link
Copy Markdown
Collaborator

Summary

Add opt-in OpenTelemetry tracing to the Kotlin SDK's client-side sandbox pool warmup path, so warmup bottlenecks can be analyzed per phase and correlated to application logs by sandbox_id.

Behavior

  • ConnectionConfig.enableTracing(true) (default false, no env var) turns tracing on.
  • Each warmup task emits one trace: a pool.warmup root span (backdated to task submission so queue-wait time is visible) with sequential sibling phase spans:
    • pool.warmup.create — create API + readiness wait
    • pool.warmup.prepare — user warmupSandboxPreparer
    • pool.warmup.renew — TTL renewal
    • pool.warmup.commit — primary-lock renew + putIdle (scheduler thread)
  • Root span attributes: pool.name, pool.owner, pool.run.generation, sandbox.id, sandbox.image, result; failures recorded via recordException.
  • trace_id / span_id are published to the SLF4J MDC while a warmup is in progress → search logs by sandbox_id, open the trace in your backend.
  • When enabled, the active trace context is injected into lifecycle requests via W3C traceparent (server-side correlation, ready for server tracing support).

Design notes

  • SDK depends only on io.opentelemetry:opentelemetry-api (implementation, no-op without an OTel SDK on the classpath); users bring their own SDK + exporter and set GlobalOpenTelemetry. BOM constraint added.
  • All span/MDC calls are best-effort and never throw.
  • Docs: new docs/guides/sdk-tracing.md (setup, span structure, MDC correlation, querying/drill-down), linked from the Kotlin SDK page and Client Pool guide; sidebar entry added.

Tests

PoolWarmupTracingTest (4 cases): full span tree + attributes + MDC correlation, failure trace (exception event, no commit span), disabled → zero spans, traceparent injection on/off. Full suite: :sandbox:test 322 tests, 0 failures; :code-interpreter:test green; spotless clean; pnpm docs:build zero errors.

Notes

  • Kotlin-only for now (other SDKs do not emit these traces).
  • Docs mention 1.0.19 as the min SDK version for this feature; current gradle.properties is 1.0.18 — bump at release time.

Add opt-in OpenTelemetry tracing (ConnectionConfig.enableTracing, default
off) for the pool warmup path. Each warmup task emits one trace rooted at a
pool.warmup span with per-phase child spans (create / prepare / renew /
commit); the root span is backdated to task submission so queue-wait time is
visible. trace_id/span_id are published to the SLF4J MDC while a warmup is in
progress so logs can be correlated back to traces by sandbox_id.

The SDK depends only on opentelemetry-api (no-op by default); users bring
their own OpenTelemetry SDK + exporter and configure the global instance.
When enabled, the active trace context is propagated to lifecycle requests
via the W3C traceparent header for server-side correlation.

Adds PoolTracer + WarmupTrace, TraceContextInterceptor in HttpClientProvider,
ConnectionConfig.enableTracing (builder + copyWithoutConnectionPool), and
tests covering span tree/attributes/MDC, failure traces, disabled no-op
behavior, and traceparent injection. Documents setup and trace querying in
docs/guides/sdk-tracing.md.
@github-actions github-actions Bot added documentation Improvements or additions to documentation sdk/java sdks size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fb65398b6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…ommits

- The warmup root span start timestamp now uses epoch wall-clock
  (System.currentTimeMillis-based) captured at submission instead of the
  monotonic System.nanoTime, so the root span is comparable with child
  spans' timestamps.
- Commits that drop the warmed sandbox (stale run, primary lock lost, or
  putIdle failure) now end the warmup trace as failure with a drop.reason
  attribute instead of marking result=success.
- Tests: assert root start is epoch wall-clock near test start; new case
  covering a warmup dropped with warmup-lock-lost.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation sdk/java sdks size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants