QA Engineering

Testing OpenTelemetry Instrumentation in 2026: How to Validate Distributed Traces, Metrics, and Spans in CI/CD Pipelines

Testing OpenTelemetry Instrumentation in 2026: How to Validate Distributed Traces, Metrics, and Spans in CI/CD Pipelines

Testing OpenTelemetry instrumentation is not the same as writing application tests. When a team adds OpenTelemetry to a service to emit traces, metrics, and logs, those signals flow to a collector, then to a backend (Jaeger, Prometheus, Grafana, Datadog). The question for QA is whether the instrumentation is correct: are spans named consistently, do traces propagate across service boundaries, do metrics have the right labels, do errors produce the right status codes on spans. These are testable claims, but they require a different approach from functional API or UI testing because the assertions target telemetry data rather than user-visible application behavior.

This guide covers how to validate OpenTelemetry instrumentation in CI/CD pipelines without a full observability stack, including trace propagation testing, metric collection validation, span attribute assertions, and integration with the OTel collector's test mode. The goal is to give QA teams a practical framework for including OTel validation in the same CI pipeline that runs functional tests, so that instrumentation regressions are caught before deployment rather than discovered when a trace is missing in production.

For background on the broader context of testing modern distributed applications, the software testing complete guide covers how observability testing fits into a complete QA strategy. Teams building out CI/CD test pipelines can review Astaqc test automation services for support with distributed systems testing coverage.

What OpenTelemetry Covers and What Testing Must Validate

OpenTelemetry is an open standard for telemetry data collection: traces, metrics, and logs. Each signal type serves a different observability purpose and requires different validation approaches.

Traces: A trace represents a single request or operation across one or more services. It is composed of spans, each representing a unit of work in a single service. Spans carry a trace ID, a span ID, a parent span ID (linking child spans to their parent), a name, a start time, a duration, a status (OK, ERROR, UNSET), and attributes (key-value pairs describing the work). Distributed traces require W3C traceparent header propagation to link spans across service boundaries. Testing traces means validating that the right spans are emitted with the right names, attributes, and parent-child relationships.

Metrics: OpenTelemetry metrics are numeric measurements: counters (cumulative counts of events), histograms (distributions of values like latency), and gauges (point-in-time measurements like memory usage). Metrics carry instrument names (following the OTel semantic conventions), units, and label sets (key-value pairs). Testing metrics means validating that the right instruments are created and exported with the right labels and that their values are within expected ranges for specific workloads.

Logs: OTel-correlated logs are associated with the active trace context, linking log records to spans. Log validation is typically less structured than trace or metric validation because log content varies more by application, but testing that log records carry the correct trace and span IDs is important for correlating logs with traces in an observability backend.

OTel SignalWhat to TestTest Approach
TracesSpan names, attributes, parent-child links, error statusIn-memory exporter assertions, snapshot testing
Distributed tracesW3C traceparent propagation, trace ID continuityIntegration test with collector, header inspection
MetricsInstrument names, label sets, value rangesPrometheus scrape assertions, in-process reader
LogsTrace/span ID correlation, severity levelsLog capture in tests, context propagation check

Testing Trace Propagation and Context Carryover

Distributed trace propagation is the most common source of instrumentation bugs in services that communicate over HTTP or gRPC. The W3C traceparent header carries the trace context from one service to the next. If a service does not read the incoming traceparent header, it starts a new trace rather than continuing the caller's trace. If it does not write the traceparent header on outgoing requests, downstream services have no trace context to continue. Both failures produce disconnected traces in the observability backend — fragments that look like successful single-service traces but have no link to the broader request path.

What to test for trace propagation: For each service-to-service call in your system, test that:

  • An incoming request with a traceparent header produces spans that use the same trace ID and correctly reference the incoming span ID as their parent
  • The service's outgoing HTTP or gRPC calls include a traceparent header that continues the same trace
  • An incoming request without a traceparent header starts a fresh trace with a new trace ID
  • Error conditions (5xx responses, timeout, connection failure) produce spans with ERROR status and an appropriate status description

Test infrastructure for propagation testing: Use an in-memory OTLP exporter in your test environment instead of a real collector. All major OpenTelemetry SDK implementations (Node.js, Python, Go, Java) support an in-process or in-memory exporter that captures spans to a local list rather than sending them over the network. After making a test request, query the in-memory exporter to assert on the spans that were produced. This avoids the operational overhead of running a real OTel collector in every CI environment and makes span assertions synchronous — the spans are available immediately after the request completes.

W3C traceparent format validation: The traceparent header format is 00-{trace-id}-{parent-id}-{flags}, where trace-id is a 32-character hex string, parent-id is a 16-character hex string, and flags is two hex digits indicating sampling state. Validating that your service emits a correctly formatted traceparent header is a simple regex assertion on the outgoing HTTP request headers captured in test. The sampled flag (01 vs 00) also matters: a service that emits traceparent headers with the sampled bit off will cause downstream collectors to drop those spans, which looks identical to missing propagation from the user's perspective.

Baggage propagation: W3C baggage is a companion to traceparent for carrying user-defined key-value pairs across service boundaries (tenant ID, feature flag state, request origin). If your services use baggage for context propagation, test that baggage values are correctly read from incoming requests, carried through the service's internal processing, and written to outgoing requests. Baggage is easy to omit from instrumentation and hard to notice as missing until a downstream service needs a value that was not propagated.

Validating Metrics Collection and Aggregation

OpenTelemetry metrics validation is structurally different from trace validation because metrics are aggregated over time rather than produced per request. A counter that increments on each request does not emit a data point immediately — it accumulates in the SDK's metric reader and flushes at the configured interval (typically 60 seconds for Prometheus) or when explicitly forced. Testing metrics requires either forcing a flush or using a synchronous metric reader that provides immediate access to the metric state.

Using an in-process metric reader for test assertions: The OpenTelemetry SDK's metric API supports a synchronous in-process reader that collects the current metric state on demand. In a test, you can call the reader's collect method immediately after the code under test executes to get the current state of all metrics. This eliminates the timing dependency on the metric flush interval and makes metric assertions synchronous.

What to assert on metrics:

  • Instrument name: The name follows OTel semantic conventions (e.g., http.server.request.duration, db.client.operation.duration). Name typos are a common instrumentation mistake and produce metrics that do not aggregate with other services using the correct name.
  • Unit: The unit string should follow the OTel semantic convention for the instrument type (e.g., ms for milliseconds, By for bytes, {requests} for request counts). Incorrect units cause metric calculations in the backend to produce wrong values when unit-based aggregations are applied.
  • Label set (attributes): Each metric should carry the correct label set. For HTTP server metrics, the minimum labels are http.request.method, http.response.status_code, and the route (or URL template). Missing labels cause metrics to be aggregated without the expected dimensions, making them useless for breakdowns by endpoint or status code.
  • Value range: For counters, assert that the count has incremented by the expected amount after a known number of operations. For histograms, assert that the sum and count are consistent with the operations performed.
Metric TypeWhat to AssertCommon Mistake
CounterIncrement count per operation, label completenessCounter not reset between tests, asserting absolute value
HistogramSum/count consistency, bucket boundariesDefault histogram boundaries not matching SLO thresholds
GaugeLast-recorded value correctnessGauge not updated when observable callback runs
UpDownCounterPositive and negative increment correctnessIncorrect sign on decrement (using Counter instead)

Cardinality control testing: High-cardinality labels (user IDs, request IDs, unparameterized URL paths) cause metric storage to grow unboundedly. If your instrumentation uses a URL template incorrectly and captures the full URL path including path parameters (e.g., /users/12345 instead of /users/{id}), each unique user ID produces a separate metric series. Test that the route label contains the parameterized template, not the actual URL. This is a correctness assertion on the label value, not on the metric value itself.

Testing Span Attributes, Events, and Status Codes

Span attributes are the key-value pairs attached to a span that give it meaning in the observability backend. Without correct attributes, spans are hard to query, filter, and aggregate. The OpenTelemetry semantic conventions define the standard attribute names for common operations (HTTP, database, messaging, RPC), and testing that your instrumentation uses these conventions correctly is a form of contract testing between your services and the observability backend.

HTTP span attribute testing: For spans representing HTTP server operations, the OTel semantic conventions require specific attributes. The critical ones are:

  • http.request.method: the HTTP method (GET, POST, PUT, etc.) in uppercase
  • http.response.status_code: the numeric response status (200, 404, 500)
  • http.route: the matched route template, not the actual URL (e.g., /users/{id} not /users/123)
  • server.address: the server host name or IP address
  • url.scheme: http or https

Test each of these attributes on spans produced by requests to your service. Missing attributes are common when instrumentation libraries are configured with default settings that do not capture all semantic convention fields, or when custom attributes are added for some routes but not others.

Database span attribute testing: For spans representing database operations, the OTel semantic conventions require db.system (the database type: postgresql, mysql, redis), db.operation.name (the SQL verb or command), and optionally db.namespace (the database name) and db.collection.name (the table name). Test that your database spans include these attributes and that db.query.text — when present — contains a sanitized query without literal parameter values (which would include PII or sensitive data in traces).

Span events: OTel spans support events — timestamped annotations that record something notable during the span's execution without starting a new span. Exception events are automatically added by most OTel SDKs when an exception is thrown within an instrumented function. Test that exception events appear on spans when exceptions are thrown, that the event name is exception, and that the event attributes include exception.type, exception.message, and exception.stacktrace. Missing exception events on error spans mean that trace data does not contain the information needed to diagnose the failure.

Span status codes: OTel spans have a status field with three values: UNSET (the default, meaning no explicit status has been set), OK (the operation succeeded), and ERROR (the operation failed). The convention is to set the status to ERROR when the operation fails, and to leave it UNSET (not OK) for success in server-side instrumentation. Test that your instrumentation sets ERROR status correctly on 5xx responses, database errors, and timeout conditions. Test that it does not incorrectly set ERROR status on 4xx responses that are expected user errors (a 404 for a not-found resource should not necessarily be an error span).

For teams integrating OTel validation into broader CI coverage, Astaqc software testing services provides support for distributed systems testing strategy and implementation. The manual vs automated testing guide covers when structured manual verification of observability signals is more practical than automated assertion-based testing.

Integrating OpenTelemetry Validation into CI/CD Pipelines

OTel validation tests run best as integration tests that start the service with a test OTel configuration (in-memory exporter instead of a real collector), exercise specific code paths, and then assert on the telemetry data produced. This pattern requires the service to be runnable in a test environment, which means it needs a way to inject the in-memory exporter rather than the production OTLP exporter. Most OTel SDKs support this through environment variables or configuration objects passed at startup.

Test environment configuration: Configure the OTel SDK in test mode by setting the exporter to SimpleSpanProcessor with an InMemorySpanExporter (or the equivalent in your language's SDK). This ensures spans are available synchronously after the test action without waiting for a batch export cycle. Clear the exporter's collected spans at the start of each test to avoid assertion interference between tests that share the same SDK instance.

Collector-based testing for integration suites: For more realistic integration testing, run the OTel collector in a Docker container as part of your CI environment and configure it in testbed mode (or use the collector's debug exporter to stdout). Make requests to your service, then query the collector's data output to assert on the spans and metrics it received. This approach tests the full telemetry pipeline — from SDK instrumentation through OTLP export to collector processing — and catches configuration bugs that in-memory testing cannot detect, such as batch processor settings that delay or drop spans under load.

Snapshot testing for span structure: For services where the span structure is well-established and infrequent changes, snapshot testing is an efficient way to catch instrumentation regressions. Capture the span names, attribute keys (not values, since those vary), parent-child structure, and event names for a specific test scenario and store them as a snapshot file. Compare the current test output against the snapshot. Any change — a new span added, an attribute name changed, an event removed — produces a snapshot diff that requires explicit review. This catches instrumentation regressions that would be invisible in functional tests.

What to include in a CI OTel test suite:

  • One test per service endpoint that validates the expected span structure for a successful request
  • One test per error condition (5xx, timeout, auth failure) that validates ERROR status and exception events
  • One test per service-to-service call that validates traceparent propagation
  • One metric validation test per instrumented counter and histogram
  • One cardinality control test that sends requests with varied path parameters and asserts that the route label is parameterized

For teams building comprehensive observability coverage as part of a larger test automation strategy, Astaqc test automation services provides coverage design and implementation support. The outsource QA guide covers how to structure working with an external team on specialized testing coverage like OTel validation.

Frequently Asked Questions

Do you need a running OTel collector to test instrumentation?

Not for unit-level instrumentation tests. All major OTel SDKs support in-memory exporters that capture span and metric data without a network call. Use the in-memory exporter for unit and integration tests that run in CI without infrastructure dependencies. Use a real collector (in a Docker container in CI) for end-to-end pipeline tests that need to validate OTLP export configuration, collector processing rules, and backend compatibility. The in-memory approach covers 80-90% of instrumentation correctness assertions at much lower overhead.

How do you test that OTel instrumentation does not leak PII into traces?

Assert that spans and span attributes do not contain values that match PII patterns (email addresses, credit card numbers, authentication tokens, personally identifiable values from request bodies). This is typically done with a regex-based assertion on the serialized span data. Additionally, assert that db.query.text spans do not contain literal SQL parameter values (they should use parameterized query format with placeholders, not the actual values). Include a PII leakage check in your OTel test suite as a security-relevant assertion that runs with every CI build.

What is the difference between OTel semantic conventions and custom attributes?

OTel semantic conventions are the standardized attribute names defined by the OpenTelemetry project for common operations (HTTP, database, messaging). They ensure that spans from your service can be queried and aggregated consistently with spans from other services and observability tools that use the same conventions. Custom attributes are application-specific key-value pairs you add beyond the conventions (e.g., a tenant ID or a feature flag state). Both are valid and useful, but test semantic convention attributes as a correctness requirement and test custom attributes as a documentation commitment. Changes to semantic convention attributes that do not match the spec should be treated as bugs.

How should you handle spans that are non-deterministic in test environments?

Spans with non-deterministic content — timestamps, generated IDs, duration values — should be asserted on structure rather than on specific values. Assert that the span has a trace ID (without asserting its value), that the duration is positive (without asserting a specific duration), and that timestamps are within a reasonable range of the test execution time. This keeps assertions stable across test runs while still validating that the expected data points are present and correctly typed.

How do you validate OTel sampling configuration?

OTel sampling determines which traces are recorded and exported. Test your sampling configuration by sending requests that should be sampled (based on your sampling rules) and asserting that spans appear in the in-memory exporter. Send requests that should not be sampled and assert that no spans are produced. For probability-based sampling, use a large enough request volume in the test to verify that the sampled fraction is approximately correct. Fixed-rate and decision-based sampling (always-on for certain paths, never for health checks) are easier to test with exact assertion on specific request patterns.

Can you use OTel test helpers to simplify instrumentation tests?

Yes. The OpenTelemetry project publishes test helper libraries for most languages that provide pre-configured in-memory exporters, assertion utilities for common span patterns, and fixtures for setting up trace context in test requests. Use these helpers rather than writing custom assertion logic from scratch — they handle the edge cases in OTel data format (protobuf serialization, nested attribute types, repeated span events) that custom assertion code frequently gets wrong. The OTel SDK for each language documents the available test utilities in the testing section of its API reference.

Building OTel Validation Into Your CI Pipeline

OpenTelemetry instrumentation bugs — missing spans, broken trace propagation, high-cardinality metrics, PII in trace attributes — are invisible to functional tests and only surface when engineers look for a trace in production that is not there. Including OTel validation in CI is a one-time investment that prevents instrumentation regressions from reaching production undetected.

Start with the highest-impact assertions: trace propagation on your most important service-to-service calls, ERROR status on the most common error conditions, and cardinality control on the metrics with the highest query volume in your observability backend. Add span attribute completeness checks for semantic conventions as a second wave. Snapshot testing for overall span structure can follow once the basic assertions are stable.

Contact Astaqc at contact@astaqc.com to discuss observability testing strategy, CI integration for OTel validation, or comprehensive distributed systems test coverage. Astaqc software testing services provides support for the full range of modern application testing, including distributed tracing, metrics validation, and telemetry-driven quality gates.

OpenTelemetry instrumentation bugs — missing spans, broken trace propagation, incorrectly labeled metrics — are invisible to functional tests and only surface when engineers look for a trace that is not there. CI validation of OTel signals catches these before deployment.

Astaqc Team

November 30, 2026

icon
icon
icon

Stop finding bugs after launch.

Talk to our QA team and start testing this week.

Get in touch →

Subscribe to our Newsletter

Sign up to receive and connect to our newsletter

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Ask our AI assistant…