@temporalio/interceptors-opentelemetry
Version:
Temporal.io SDK interceptors bundle for tracing with opentelemetry
60 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OpenTelemetryPlugin = void 0;
const plugin_1 = require("@temporalio/plugin");
const client_1 = require("./client");
const worker_1 = require("./worker");
/**
* A plugin that adds OpenTelemetry tracing.
*
* Configures Client, Activity, and Workflow interceptors for trace propagation and injects
* a span exporter sink for Workflow spans.
*
* @experimental Plugins is an experimental feature; APIs may change without notice.
*/
class OpenTelemetryPlugin extends plugin_1.SimplePlugin {
otelOptions;
constructor(otelOptions) {
const workflowInterceptorsPath = require.resolve('./workflow-interceptors');
const interceptorOptions = otelOptions.tracer ? { tracer: otelOptions.tracer } : {};
super({
name: 'OpenTelemetryPlugin',
clientInterceptors: {
workflow: [new client_1.OpenTelemetryWorkflowClientInterceptor(interceptorOptions)],
},
workerInterceptors: {
client: {
workflow: [new client_1.OpenTelemetryWorkflowClientInterceptor(interceptorOptions)],
},
workflowModules: [workflowInterceptorsPath],
activity: [
(ctx) => ({
inbound: new worker_1.OpenTelemetryActivityInboundInterceptor(ctx, interceptorOptions),
outbound: new worker_1.OpenTelemetryActivityOutboundInterceptor(ctx),
}),
],
},
});
this.otelOptions = otelOptions;
}
configureWorker(options) {
return super.configureWorker(this.injectSinks(options));
}
configureReplayWorker(options) {
return super.configureReplayWorker(this.injectSinks(options));
}
injectSinks(options) {
const sinks = {
exporter: (0, worker_1.makeWorkflowExporter)(this.otelOptions.spanProcessor, this.otelOptions.resource),
};
return {
...options,
sinks: {
...options.sinks,
...sinks,
},
};
}
}
exports.OpenTelemetryPlugin = OpenTelemetryPlugin;
//# sourceMappingURL=plugin.js.map