@torquedev/ext-otel
v0.1.0
Published
OpenTelemetry observability extension for Torque — spans, structured logging, request tracing
Maintainers
Readme
@torquedev/ext-otel
OpenTelemetry observability extension for Torque — spans, structured logging, and request tracing.
Installation
npm install @torquedev/ext-otelPeer dependencies (install as needed):
@torquedev/core— Torque runtime@opentelemetry/api— optional, required for span tracing
Handlers
spanOnInterfaceCall
Wraps Torque interface method calls with OpenTelemetry spans.
import { spanOnInterfaceCall } from '@torquedev/ext-otel';
// With a real tracer
const handler = spanOnInterfaceCall.create({ tracer });
// Lifecycle hooks
handler.beforeCall(ctx); // starts span
handler.afterCall(ctx); // ends span with OK status
handler.errorCall(ctx); // ends span with ERROR status
// Static no-ops (default passthrough)
spanOnInterfaceCall.beforeCall(ctx);
spanOnInterfaceCall.afterCall(ctx);Span attributes set:
torque.bundle— bundle nametorque.interface— method nametorque.duration_ms— elapsed time (afterCall)error.message/error.type— error details (errorCall)
structuredAccessLog
Produces JSON-formatted HTTP access log entries.
import { structuredAccessLog } from '@torquedev/ext-otel';
const handler = structuredAccessLog({ logger: console });
handler({
method: 'GET',
path: '/api/users',
statusCode: 200,
durationMs: 42,
requestId: 'req-abc',
userId: 'user-123',
});
// => {"ts":"...","method":"GET","path":"/api/users","status":200,"duration_ms":42,"request_id":"req-abc","user_id":"user-123"}requestTracing
Ensures every request carries a trace ID. Reads x-request-id from request headers or generates a UUID. Sets X-Request-Id and X-Trace-Id response headers.
import { requestTracing } from '@torquedev/ext-otel';
const handler = requestTracing();
// In middleware / Torque hook
handler({ req, res });Running Tests
node --test test/otel.test.jsLicense
MIT
