@resonatehq/opentelemetry adds OpenTelemetry tracing to the Resonate TypeScript SDK, propagating distributed trace context across durable function invocations and resumptions.
npm install @resonatehq/opentelemetryYou will also need an OpenTelemetry SDK configured in your application. For Node.js, the @opentelemetry/sdk-node package is a good starting point.
Pass an OpenTelemetryTracer to the Resonate constructor via the tracer option:
import { Resonate, type Context } from "@resonatehq/sdk";
import { OpenTelemetryTracer } from "@resonatehq/opentelemetry";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-node";
// Initialize the OpenTelemetry SDK
const sdk = new NodeSDK({ traceExporter: new ConsoleSpanExporter() });
sdk.start();
// Wire up the Resonate tracer
const tracer = new OpenTelemetryTracer("my-resonate-app");
const resonate = new Resonate({ tracer });
resonate.register("checkout", function* checkout(ctx: Context, orderId: string): Generator {
// Each rpc and run call will be captured as a child span
yield* ctx.rpc("processPayment", orderId);
yield* ctx.rpc("fulfillOrder", orderId);
});
await resonate.run("checkout.order-123", "checkout", "order-123");OpenTelemetryTracer accepts either a tracer name (and optional version) or an existing Tracer instance from @opentelemetry/api:
// By name
const tracer = new OpenTelemetryTracer("my-service", "1.0.0");
// From an existing Tracer
import { trace } from "@opentelemetry/api";
const otelTracer = trace.getTracer("my-service");
const tracer = new OpenTelemetryTracer(otelTracer);Full documentation: docs.resonatehq.io