Skip to content

PoC: OpenTelemetry traces for RSpec test executions (TE-6490) - #261

Draft
nprizal wants to merge 24 commits into
mainfrom
nprizal/te-6490-otel-ruby-spans-poc
Draft

PoC: OpenTelemetry traces for RSpec test executions (TE-6490)#261
nprizal wants to merge 24 commits into
mainfrom
nprizal/te-6490-otel-ruby-spans-poc

Conversation

@nprizal

@nprizal nprizal commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This developer-facing PoC adds opt-in OpenTelemetry export for RSpec test executions so we can dogfood test-scoped traces with Buildkite Test Engine.

Each sampled example creates an independently rooted test.execution span. Synchronous HTTP, SQL, Redis, and other instrumented work becomes its descendants. The normal Test Engine execution upload remains authoritative and independent: OpenTelemetry configuration and delivery failures warn or drop telemetry without failing tests or blocking the upload.

This is intentionally a v3 experiment. It requires Ruby 3.3+ and packages the tested OpenTelemetry SDK, OTLP exporter, and instrumentation set as core dependencies.

Implemented contracts

  • A shared opaque ID correlates each sampled root with its execution upload; it is not copied to child spans.
  • The validated raw run key is sent as both Buildkite-Test-Run-Key and buildkite.test.run.key. The authenticated receiver—not the collector—derives the canonical suite-scoped run UUID.
  • A canonical BUILDKITE_JOB_ID from the Buildkite process environment is sent consistently in the job header and resource attributes. Legacy or configured overrides cannot manufacture typed job identity.
  • Valid Agent TRACEPARENT / TRACESTATE becomes one SpanLink created with the root; it never becomes the parent.
  • Buildkite resource metadata is merged only into the Buildkite export copy. Customer provider resources and exporter data are not mutated.
  • Flush and shutdown affect only the Buildkite processor. Existing customer telemetry lifecycle remains customer-owned.
  • OTLP activation is RSpec-only and independent of the collector's legacy tracing_enabled option.

Dogfooding scope

This PR is evidence gathering, not a production support commitment. It deliberately uses broad use_all / install_all instrumentation and SDK-default batching. Static skips, production sampling and limits, an instrumentation allowlist, other test frameworks, sensitive-data policy, operating cost, and delivery guarantees remain decisions for the dogfooding exercise.

The two review documents are:

  • Architecture: implemented flow, identity contracts, metadata, ownership, and failure boundaries.
  • Dogfooding plan: scenarios, evidence, measurements, and exit criteria.

Verification

  • Full RSpec suite: 93 examples, 0 failures.
  • Cucumber suite: 1 scenario, 3 steps, 0 failures.
  • Focused coverage for root/child structure, SpanLinks, run and job correlation, sampling, provider coexistence, exporter isolation, retry/flush/shutdown, activation boundaries, and fail-open behavior.

TE-6490 PoC. Open one OTel span per test execution in the RSpec
around(:each) hook and export spans over OTLP, correlated to the
execution via a span_trace_key tag stamped on every span.

The opentelemetry-* gems are soft dependencies (lazy require): when
they are absent span export disables itself and the collector behaves
exactly as before, so the gem's Ruby >= 2.3 floor is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread lib/buildkite/test_collector/otel.rb Outdated
Comment thread lib/buildkite/test_collector/otel.rb Outdated
Comment thread lib/buildkite/test_collector/library_hooks/rspec.rb Outdated
@mattensor mattensor changed the title [PoC] Emit OpenTelemetry spans per test execution (TE-6490) PoC: Correlate RSpec executions with OpenTelemetry traces (TE-6490) Jul 28, 2026
Comment thread docs/opentelemetry-architecture-notes.md Outdated
Comment thread lib/buildkite/test_collector/otel.rb Outdated
OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(exporter)
)
# PoC shortcut: capture every available instrumentation.
c.use_all

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have intelligence around which instrumentation to include in our first release

@mattensor mattensor changed the title PoC: Correlate RSpec executions with OpenTelemetry traces (TE-6490) Experimental OpenTelemetry traces for RSpec executions (TE-6490) Jul 30, 2026
@mattensor mattensor changed the title Experimental OpenTelemetry traces for RSpec executions (TE-6490) PoC: OpenTelemetry traces for RSpec test executions (TE-6490) Jul 31, 2026
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