From harness-claude
Propagates OpenTelemetry trace context across service boundaries using W3C TraceContext headers and baggage. Links distributed traces in microservices and passes metadata like tenant IDs.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Propagate trace context across service boundaries using W3C TraceContext headers and baggage
Configures OpenTelemetry distributed tracing in Node.js microservices to propagate trace context and emit spans across HTTP, Express, PostgreSQL, and Redis calls. Debugs latency, intermittent failures, and performance in multi-service requests.
Sets up distributed tracing for microservices with OpenTelemetry, Jaeger, or Zipkin, handling instrumentation, context propagation, spans, and trace collection for request visibility.
Instruments apps with OpenTelemetry for distributed tracing and Jaeger/Tempo integration. Debugs latency in microservices, analyzes request flows, correlates traces with logs/metrics.
Share bugs, ideas, or general feedback.
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/