Skip to content

[skip-tag:sdk] feat(sdk): additive OTel instrumentation (1/4)#74

Merged
lIang70 merged 1 commit into
mainfrom
feat/sdk-otel-additive
May 8, 2026
Merged

[skip-tag:sdk] feat(sdk): additive OTel instrumentation (1/4)#74
lIang70 merged 1 commit into
mainfrom
feat/sdk-otel-additive

Conversation

@lIang70

@lIang70 lIang70 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part 1 of 4 in the v0.2.x additive SDK batch. Tagging is suppressed on
this PR via [skip-tag:sdk]; a single sdk/v0.2.9 tag will be cut after
PR 4/4 merges.

This PR introduces additive OpenTelemetry instrumentation across sdk/telemetry,
sdk/event, and sdk/engine. No public API is removed or altered.

sdk/telemetry — OTLP exporter helpers

  • OTLPConfig (endpoint, headers, insecure, timeout, compression).
  • WithOTLPTraceExporter / WithOTLPMeterExporter / WithOTLPLogProcessor
    options that build OTLP/HTTP exporters.
  • Init{Tracer,Meter,Log} now surface option-time configuration errors via a
    new internal optErr field — option functions can't return errors directly,
    so this lets exporter construction failures bubble up through Init* instead
    of panicking later.

sdk/event — OTel span context on envelopes

  • Envelope.SpanContext() reconstructs an OTel trace.SpanContext (marked
    Remote: true) from the existing TraceID / SpanID fields.
  • Envelope.WithRemoteContext(ctx) injects that span context into a child
    context so downstream consumers can start linked spans across process
    boundaries (events bus → worker → tracer).

sdk/engine — Tracing host middleware

  • TracingMiddleware() is a HostMiddleware that decorates Host.Publish,
    AskUser, Checkpoint, ReportUsage with OTel spans.
  • Interrupts() is intentionally not traced — it is a hot, non-blocking
    channel accessor and tracing it would dominate spans.
  • Span attributes follow OTel semconv-style keys (flowcraft.run.id,
    flowcraft.event.subject, flowcraft.checkpoint.exec_id, etc.) and errors
    are recorded via span.RecordError + codes.Error.

Test plan

  • go vet ./telemetry/... ./event/... ./engine/...
  • go test ./telemetry/... ./event/... ./engine/... -count=1
  • New tests:
    • sdk/telemetry/otlp_test.go — mock OTLP/HTTP collector verifies trace
      delivery.
    • sdk/event/trace_test.go — round-trips trace/span ID through Envelope
      and confirms child-span linkage.
    • sdk/engine/middleware_otel_test.go — span creation, attribute population,
      error recording for each wrapped Host method.

Release notes

This PR is additive only; tagging is intentionally skipped. The cumulative
sdk/v0.2.9 tag will be created on the final PR (4/4) of this batch.

Made with Cursor

- sdk/telemetry: OTLPConfig + WithOTLP{Trace,Meter,Log} option helpers
  with optErr propagation through Init{Tracer,Meter,Log}.
- sdk/event: Envelope.SpanContext / WithRemoteContext for cross-process
  OTel trace correlation via existing TraceID/SpanID fields.
- sdk/engine: TracingMiddleware HostMiddleware that wraps Publish, AskUser,
  Checkpoint, ReportUsage in spans; Interrupts is intentionally not traced.

All changes are additive; no public API removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lIang70
lIang70 merged commit d13e435 into main May 8, 2026
17 checks passed
@lIang70
lIang70 deleted the feat/sdk-otel-additive branch May 8, 2026 05:46
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