From harness-claude
Instruments code with OpenTelemetry spans for distributed tracing to visualize request flows across services, debug microservice latency, and correlate logs/errors.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Instrument distributed traces with OpenTelemetry spans to visualize request flow across services
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.
Guides implementing distributed tracing in microservices with OpenTelemetry, covering traces, spans, context propagation, and cross-service debugging.
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.
Instrument distributed traces with OpenTelemetry spans to visualize request flow across services
trace.getTracer('service-name', '1.0.0').tracer.startActiveSpan to automatically propagate context to child spans.span.setAttribute('user.id', userId).span.setStatus({ code: SpanStatusCode.ERROR, message }).finally block — unfinished spans leak memory.http.method, db.system, rpc.method).// services/order-service.ts
import { trace, SpanStatusCode, SpanKind } from '@opentelemetry/api';
const tracer = trace.getTracer('order-service', '1.0.0');
export async function createOrder(userId: string, items: OrderItem[]): Promise<Order> {
return tracer.startActiveSpan(
'createOrder',
{
kind: SpanKind.INTERNAL,
attributes: {
'user.id': userId,
'order.item_count': items.length,
},
},
async (span) => {
try {
// Child span — automatically linked to parent via active context
const inventory = await checkInventory(items);
const order = await tracer.startActiveSpan('db.insertOrder', async (dbSpan) => {
try {
dbSpan.setAttribute('db.system', 'postgresql');
dbSpan.setAttribute('db.operation', 'INSERT');
const result = await db.orders.create({ userId, items, inventory });
return result;
} finally {
dbSpan.end();
}
});
span.setAttribute('order.id', order.id);
span.setStatus({ code: SpanStatusCode.OK });
return order;
} catch (error) {
span.setStatus({
code: SpanStatusCode.ERROR,
message: error instanceof Error ? error.message : 'Unknown error',
});
span.recordException(error as Error);
throw error;
} finally {
span.end();
}
}
);
}
Span hierarchy: Traces are trees of spans. The root span represents the entire request. Child spans represent sub-operations. The span context (trace ID + span ID) propagates automatically when using startActiveSpan.
Span kinds:
SERVER — handling an incoming requestCLIENT — making an outgoing requestINTERNAL — internal operation (default)PRODUCER — sending a message to a queueCONSUMER — receiving a message from a queueSemantic conventions (use these attribute names for tool compatibility):
span.setAttribute('http.method', 'POST');
span.setAttribute('http.url', '/api/orders');
span.setAttribute('http.status_code', 201);
span.setAttribute('db.system', 'postgresql');
span.setAttribute('db.statement', 'INSERT INTO orders ...');
span.setAttribute('messaging.system', 'rabbitmq');
span.setAttribute('messaging.destination', 'order-events');
Span events: Add timestamped events within a span for notable occurrences:
span.addEvent('inventory.checked', {
'inventory.available': true,
'inventory.reserved_count': 5,
});
Common mistakes:
https://opentelemetry.io/docs/concepts/signals/traces/