From harness-claude
Propagates trace context across service boundaries using W3C TraceContext headers and baggage. Useful for linking microservice traces and passing metadata without modifying APIs.
How this skill is triggered — by the user, by Claude, or both
Slash command
/harness-claude:otel-context-propagationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Propagate trace context across service boundaries using W3C TraceContext headers and baggage
Propagate trace context across service boundaries using W3C TraceContext headers and baggage
// SDK setup — configure propagators
import { W3CTraceContextPropagator } from '@opentelemetry/core';
import { W3CBaggagePropagator } from '@opentelemetry/core';
import { CompositePropagator } from '@opentelemetry/core';
const sdk = new NodeSDK({
textMapPropagator: new CompositePropagator({
propagators: [
new W3CTraceContextPropagator(), // traceparent + tracestate headers
new W3CBaggagePropagator(), // baggage header
],
}),
// ... rest of config
});
// Manual propagation for message queues
import { context, propagation, trace } from '@opentelemetry/api';
// Producer — inject context into message headers
function publishMessage(queue: string, payload: object): void {
const headers: Record<string, string> = {};
propagation.inject(context.active(), headers);
messageQueue.publish(queue, {
body: payload,
headers, // Contains traceparent, tracestate, baggage
});
}
// Consumer — extract context from message headers
async function consumeMessage(message: QueueMessage): Promise<void> {
const parentContext = propagation.extract(context.active(), message.headers);
const tracer = trace.getTracer('consumer');
await context.with(parentContext, async () => {
await tracer.startActiveSpan(
'process.message',
{
kind: SpanKind.CONSUMER,
attributes: { 'messaging.system': 'rabbitmq', 'messaging.destination': message.queue },
},
async (span) => {
try {
await processMessage(message.body);
} finally {
span.end();
}
}
);
});
}
// Baggage — pass metadata across services
import { propagation, context, BaggageEntry } from '@opentelemetry/api';
// Set baggage in the upstream service
function setTenantContext(tenantId: string) {
const baggage = propagation.createBaggage({
'tenant.id': { value: tenantId },
'request.priority': { value: 'high' },
});
return propagation.setBaggage(context.active(), baggage);
}
// Read baggage in the downstream service
function getTenantId(): string | undefined {
const baggage = propagation.getBaggage(context.active());
return baggage?.getEntry('tenant.id')?.value;
}
W3C TraceContext headers:
traceparent: 00-<traceId>-<spanId>-<flags> — the core propagation headertracestate: vendor1=value1,vendor2=value2 — vendor-specific trace informationbaggage: tenant.id=abc,priority=high — application-level key-value pairsAuto-propagation: The HTTP instrumentation automatically injects traceparent on outgoing requests and extracts it on incoming requests. You typically do NOT need manual propagation for HTTP.
When you need manual propagation:
B3 compatibility: If some services use Zipkin B3 headers, add the B3 propagator:
import { B3Propagator } from '@opentelemetry/propagator-b3';
new CompositePropagator({
propagators: [
new W3CTraceContextPropagator(),
new B3Propagator(), // Also understands X-B3-TraceId headers
],
});
Debugging broken traces: If traces are disconnected across services:
traceparent headerscontext.with()https://opentelemetry.io/docs/concepts/context-propagation/
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudePropagates trace context and emits spans across microservices using OpenTelemetry. Helps debug latency, intermittent failures, and request-level performance.
Sets up distributed tracing for microservices with OpenTelemetry, Jaeger, or Zipkin, handling instrumentation, context propagation, spans, and trace collection for request visibility.
Instruments applications with OpenTelemetry for distributed tracing: auto/manual instrumentation, context propagation, sampling, integration with Jaeger or Tempo. Debug latency in distributed systems.