Repository navigation
fix(otel): restore distributed tracing for the controller and agent runtimes - #2663
Conversation
krisztianfekete
left a comment
There was a problem hiding this comment.
This is looking very good, added some comments on potentially improving what we had before.
| // otelgrpc snapshots the global TracerProvider and propagator when its handler | ||
| // is constructed, so tracing has to be registered before any server is built. |
There was a problem hiding this comment.
Great thing to call out, thanks!
| func OtelEnvFromProcess() []corev1.EnvVar { | ||
| var envVars []corev1.EnvVar | ||
| for _, envVar := range os.Environ() { | ||
| if !strings.HasPrefix(envVar, "OTEL_") { | ||
| continue | ||
| } | ||
| name, value, found := strings.Cut(envVar, "=") | ||
| if !found { | ||
| continue | ||
| } | ||
| envVars = append(envVars, corev1.EnvVar{Name: name, Value: value}) | ||
| } | ||
| slices.SortFunc(envVars, func(a, b corev1.EnvVar) int { | ||
| return strings.Compare(a.Name, b.Name) | ||
| }) | ||
| return envVars | ||
| } |
There was a problem hiding this comment.
I know that we had a similar logic before it got removed, but wondering if we should go with an explicit allow-list for OTel env vars instead.
What I mainly want to avoid is silently adding potentially unwanted data as plaintext e.g. when someone decides to propagate OTEL_EXPORTER_OTLP_HEADERS.
There might also be a problem if someone is setting a e.g. service.name via an env var as well, as that would falsely label agents after the var is propagated.
There was a problem hiding this comment.
good idea, added the allow list.
| // "none" selects a noop exporter, so the test dials no collector. | ||
| t.Setenv("OTEL_TRACES_EXPORTER", "none") |
Signed-off-by: Cody Hartsook <[email protected]>
Signed-off-by: Cody Hartsook <[email protected]>
Signed-off-by: Cody Hartsook <[email protected]>
Signed-off-by: Cody Hartsook <[email protected]>
8a538ce to
5aad890
Compare
Signed-off-by: Cody Hartsook <[email protected]>
…v#2805) Adds correlated OpenTelemetry tracing and logging across the Kagent, Codex, and Claude harnesses. Refactors shared tracing configuration and setup code. Builds on top of previous V2 observability works like kagent-dev#2663 and kagent-dev#2786. Also closes kagent-dev#2760 and partially addresses kagent-dev#2762. ### Key Changes - Resolve and validate OTLP trace and log settings consistently across all harness compilers. - Propagate telemetry configuration, service identity, and collector egress into runtime revisions. - Configure Codex and Claude native trace and log exporters with content capture enabled. - Propagate W3C trace context through Codex JSON-RPC requests and Claude process environment. - Initialize shared Go tracing in the native harness wrappers and move common tracing code out of the ADK package. - Flush request spans before terminal and input-required events cause an Actor to pause. ### Notes - Traces and logs are independently enabled through `OTEL_TRACING_ENABLED` and `OTEL_LOGGING_ENABLED` - Invalid or missing enabled-signal endpoints and unsupported protocols now fail harness compilation. - Span attributes for Claude Code is [documented here](https://code.claude.com/docs/en/monitoring-usage#span-attributes) and available events / logs is [documented here](https://code.claude.com/docs/en/monitoring-usage#events) - Events / logs emitted by Codex is [documented here](https://learn.chatgpt.com/docs/config-file/config-advanced#what-gets-emitted). There is no official docs for Codex's span hierarchy and attributes - Codex and Claude Code force flushes traces when their process exists before the gateway Suspends the instance. The adapter process will also flush its own traces before it responds with a terminal event as per the changes in `go/adk/pkg/a2a/server/server.go`. However, during a pending HITL, since we do not quit the Codex or Claude process, it is not guaranteed that all traces are delivered immediately. - For both Codex and Claude, native spans after HITL completes remain in the original request trace because the in-flight process carries the same trace context (through env var or JSON-RPC). The resume A2A trace may contain only controller and Go wrapper spans. --------- Signed-off-by: Jet Chiang <[email protected]>
Summary
Restores distributed tracing for the v2 controller and the established kagent runtime.
OTEL_*variables into kagent runtime revisions; tracing configuration therefore participates in the revision digest.Verification
go test ./core/...make -C go lintgo test ./core/internal/telemetry ./core/v2/translator ./core/v2/translator/kagent ./core/v2/translator/claudekagent-controllerinto the actor.Deferred
Claude harness tracing needs runtime telemetry initialization and its mock E2E fixture/image from #2602. That work will be handled with the new harness rather than broaden this controller regression fix.