@temporalio/interceptors-opentelemetry-v2 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/lib/client/index.d.ts +26 -0
  4. package/lib/client/index.js +185 -0
  5. package/lib/client/index.js.map +1 -0
  6. package/lib/index.d.ts +13 -0
  7. package/lib/index.js +32 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/instrumentation.d.ts +58 -0
  10. package/lib/instrumentation.js +152 -0
  11. package/lib/instrumentation.js.map +1 -0
  12. package/lib/plugin.d.ts +31 -0
  13. package/lib/plugin.js +66 -0
  14. package/lib/plugin.js.map +1 -0
  15. package/lib/worker/index.d.ts +69 -0
  16. package/lib/worker/index.js +222 -0
  17. package/lib/worker/index.js.map +1 -0
  18. package/lib/workflow/context-manager.d.ts +10 -0
  19. package/lib/workflow/context-manager.js +67 -0
  20. package/lib/workflow/context-manager.js.map +1 -0
  21. package/lib/workflow/definitions.d.ts +127 -0
  22. package/lib/workflow/definitions.js +92 -0
  23. package/lib/workflow/definitions.js.map +1 -0
  24. package/lib/workflow/id-generator.d.ts +8 -0
  25. package/lib/workflow/id-generator.js +30 -0
  26. package/lib/workflow/id-generator.js.map +1 -0
  27. package/lib/workflow/index.d.ts +51 -0
  28. package/lib/workflow/index.js +252 -0
  29. package/lib/workflow/index.js.map +1 -0
  30. package/lib/workflow/performance-polyfill.d.ts +16 -0
  31. package/lib/workflow/performance-polyfill.js +29 -0
  32. package/lib/workflow/performance-polyfill.js.map +1 -0
  33. package/lib/workflow/runtime.d.ts +1 -0
  34. package/lib/workflow/runtime.js +14 -0
  35. package/lib/workflow/runtime.js.map +1 -0
  36. package/lib/workflow/span-exporter.d.ts +9 -0
  37. package/lib/workflow/span-exporter.js +56 -0
  38. package/lib/workflow/span-exporter.js.map +1 -0
  39. package/lib/workflow/workflow-imports-impl.d.ts +7 -0
  40. package/lib/workflow/workflow-imports-impl.js +17 -0
  41. package/lib/workflow/workflow-imports-impl.js.map +1 -0
  42. package/lib/workflow/workflow-imports.d.ts +16 -0
  43. package/lib/workflow/workflow-imports.js +25 -0
  44. package/lib/workflow/workflow-imports.js.map +1 -0
  45. package/lib/workflow-interceptors.d.ts +3 -0
  46. package/lib/workflow-interceptors.js +12 -0
  47. package/lib/workflow-interceptors.js.map +1 -0
  48. package/package.json +78 -0
  49. package/src/client/index.ts +220 -0
  50. package/src/index.ts +14 -0
  51. package/src/instrumentation.ts +159 -0
  52. package/src/plugin.ts +86 -0
  53. package/src/worker/index.ts +264 -0
  54. package/src/workflow/context-manager.ts +53 -0
  55. package/src/workflow/definitions.ts +145 -0
  56. package/src/workflow/id-generator.ts +30 -0
  57. package/src/workflow/index.ts +312 -0
  58. package/src/workflow/performance-polyfill.ts +31 -0
  59. package/src/workflow/runtime.ts +12 -0
  60. package/src/workflow/span-exporter.ts +60 -0
  61. package/src/workflow/workflow-imports-impl.ts +14 -0
  62. package/src/workflow/workflow-imports.ts +39 -0
  63. package/src/workflow-interceptors.ts +14 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2021-2025 Temporal Technologies Inc. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # `@temporalio/interceptors-opentelemetry-v2` (Experimental)
2
+
3
+ [![NPM](https://img.shields.io/npm/v/@temporalio/interceptors-opentelemetry-v2?style=for-the-badge)](https://www.npmjs.com/package/@temporalio/interceptors-opentelemetry-v2)
4
+
5
+ [Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/typescript/introduction) interceptors for tracing Workflow and Activity executions with [OpenTelemetry](https://opentelemetry.io/) v2.
6
+
7
+ This package targets OpenTelemetry JS SDK v2. For OpenTelemetry JS SDK v1, use [`@temporalio/interceptors-opentelemetry`](https://www.npmjs.com/package/@temporalio/interceptors-opentelemetry).
8
+
9
+ **Warning** This package produces incompatible histories from `@temporalio/interceptors-opentelemetry`. Attempting to replay a workflow that was initially run with the original package can trigger a non-determinism error.
10
+
11
+ - [Interceptors docs](https://docs.temporal.io/typescript/interceptors)
12
+ - [OpenTelemetry Interceptor example setup](https://github.com/temporalio/samples-typescript/tree/main/interceptors-opentelemetry)
@@ -0,0 +1,26 @@
1
+ import * as otel from '@opentelemetry/api';
2
+ import type { Next, WorkflowSignalInput, WorkflowSignalWithStartInput, WorkflowStartInput, WorkflowStartOutput, WorkflowStartUpdateInput, WorkflowStartUpdateOutput, WorkflowStartUpdateWithStartInput, WorkflowStartUpdateWithStartOutput, WorkflowQueryInput, WorkflowTerminateInput, WorkflowCancelInput, WorkflowDescribeInput, WorkflowClientInterceptor, TerminateWorkflowExecutionResponse, RequestCancelWorkflowExecutionResponse, DescribeWorkflowExecutionResponse } from '@temporalio/client';
3
+ export interface InterceptorOptions {
4
+ readonly tracer?: otel.Tracer;
5
+ }
6
+ /**
7
+ * Intercepts calls to start a Workflow.
8
+ *
9
+ * Wraps the operation in an opentelemetry Span and passes it to the Workflow via headers.
10
+ *
11
+ * @experimental This interceptor is experimental and APIs may change without notice.
12
+ */
13
+ export declare class OpenTelemetryWorkflowClientInterceptor implements WorkflowClientInterceptor {
14
+ protected readonly tracer: otel.Tracer;
15
+ constructor(options?: InterceptorOptions);
16
+ start(input: WorkflowStartInput, next: Next<WorkflowClientInterceptor, 'start'>): Promise<string>;
17
+ signal(input: WorkflowSignalInput, next: Next<WorkflowClientInterceptor, 'signal'>): Promise<void>;
18
+ startWithDetails(input: WorkflowStartInput, next: Next<WorkflowClientInterceptor, 'startWithDetails'>): Promise<WorkflowStartOutput>;
19
+ startUpdate(input: WorkflowStartUpdateInput, next: Next<WorkflowClientInterceptor, 'startUpdate'>): Promise<WorkflowStartUpdateOutput>;
20
+ startUpdateWithStart(input: WorkflowStartUpdateWithStartInput, next: Next<WorkflowClientInterceptor, 'startUpdateWithStart'>): Promise<WorkflowStartUpdateWithStartOutput>;
21
+ signalWithStart(input: WorkflowSignalWithStartInput, next: Next<WorkflowClientInterceptor, 'signalWithStart'>): Promise<string>;
22
+ query(input: WorkflowQueryInput, next: Next<WorkflowClientInterceptor, 'query'>): Promise<unknown>;
23
+ terminate(input: WorkflowTerminateInput, next: Next<WorkflowClientInterceptor, 'terminate'>): Promise<TerminateWorkflowExecutionResponse>;
24
+ cancel(input: WorkflowCancelInput, next: Next<WorkflowClientInterceptor, 'cancel'>): Promise<RequestCancelWorkflowExecutionResponse>;
25
+ describe(input: WorkflowDescribeInput, next: Next<WorkflowClientInterceptor, 'describe'>): Promise<DescribeWorkflowExecutionResponse>;
26
+ }
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.OpenTelemetryWorkflowClientInterceptor = void 0;
27
+ const otel = __importStar(require("@opentelemetry/api"));
28
+ const instrumentation_1 = require("../instrumentation");
29
+ const definitions_1 = require("../workflow/definitions");
30
+ /**
31
+ * Intercepts calls to start a Workflow.
32
+ *
33
+ * Wraps the operation in an opentelemetry Span and passes it to the Workflow via headers.
34
+ *
35
+ * @experimental This interceptor is experimental and APIs may change without notice.
36
+ */
37
+ class OpenTelemetryWorkflowClientInterceptor {
38
+ tracer;
39
+ constructor(options) {
40
+ this.tracer = options?.tracer ?? otel.trace.getTracer('@temporalio/interceptor-client');
41
+ }
42
+ async start(input, next) {
43
+ return await (0, instrumentation_1.instrument)({
44
+ tracer: this.tracer,
45
+ spanName: `${definitions_1.SpanName.WORKFLOW_START}${definitions_1.SPAN_DELIMITER}${input.workflowType}`,
46
+ fn: async (span) => {
47
+ const headers = (0, instrumentation_1.headersWithContext)(input.headers);
48
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.options.workflowId);
49
+ const runId = await next({ ...input, headers });
50
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, runId);
51
+ return runId;
52
+ },
53
+ });
54
+ }
55
+ async signal(input, next) {
56
+ return await (0, instrumentation_1.instrument)({
57
+ tracer: this.tracer,
58
+ spanName: `${definitions_1.SpanName.WORKFLOW_SIGNAL}${definitions_1.SPAN_DELIMITER}${input.signalName}`,
59
+ fn: async (span) => {
60
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
61
+ const headers = (0, instrumentation_1.headersWithContext)(input.headers);
62
+ await next({ ...input, headers });
63
+ },
64
+ });
65
+ }
66
+ async startWithDetails(input, next) {
67
+ return await (0, instrumentation_1.instrument)({
68
+ tracer: this.tracer,
69
+ spanName: `${definitions_1.SpanName.WORKFLOW_START}${definitions_1.SPAN_DELIMITER}${input.workflowType}`,
70
+ fn: async (span) => {
71
+ const headers = (0, instrumentation_1.headersWithContext)(input.headers);
72
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.options.workflowId);
73
+ const output = await next({ ...input, headers });
74
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, output.runId);
75
+ return output;
76
+ },
77
+ });
78
+ }
79
+ async startUpdate(input, next) {
80
+ return await (0, instrumentation_1.instrument)({
81
+ tracer: this.tracer,
82
+ spanName: `${definitions_1.SpanName.WORKFLOW_START_UPDATE}${definitions_1.SPAN_DELIMITER}${input.updateName}`,
83
+ fn: async (span) => {
84
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
85
+ if (input.options.updateId) {
86
+ span.setAttribute(instrumentation_1.UPDATE_ID_ATTR_KEY, input.options.updateId);
87
+ }
88
+ const headers = (0, instrumentation_1.headersWithContext)(input.headers);
89
+ const output = await next({ ...input, headers });
90
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, output.workflowRunId);
91
+ return output;
92
+ },
93
+ });
94
+ }
95
+ async startUpdateWithStart(input, next) {
96
+ return await (0, instrumentation_1.instrument)({
97
+ tracer: this.tracer,
98
+ spanName: `${definitions_1.SpanName.WORKFLOW_UPDATE_WITH_START}${definitions_1.SPAN_DELIMITER}${input.updateName}`,
99
+ fn: async (span) => {
100
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowStartOptions.workflowId);
101
+ if (input.updateOptions.updateId) {
102
+ span.setAttribute(instrumentation_1.UPDATE_ID_ATTR_KEY, input.updateOptions.updateId);
103
+ }
104
+ const workflowStartHeaders = (0, instrumentation_1.headersWithContext)(input.workflowStartHeaders);
105
+ const updateHeaders = (0, instrumentation_1.headersWithContext)(input.updateHeaders);
106
+ const output = await next({ ...input, workflowStartHeaders, updateHeaders });
107
+ if (output.workflowExecution.runId) {
108
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, output.workflowExecution.runId);
109
+ }
110
+ return output;
111
+ },
112
+ });
113
+ }
114
+ async signalWithStart(input, next) {
115
+ return await (0, instrumentation_1.instrument)({
116
+ tracer: this.tracer,
117
+ spanName: `${definitions_1.SpanName.WORKFLOW_SIGNAL_WITH_START}${definitions_1.SPAN_DELIMITER}${input.workflowType}`,
118
+ fn: async (span) => {
119
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.options.workflowId);
120
+ const headers = (0, instrumentation_1.headersWithContext)(input.headers);
121
+ const runId = await next({ ...input, headers });
122
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, runId);
123
+ return runId;
124
+ },
125
+ });
126
+ }
127
+ async query(input, next) {
128
+ return await (0, instrumentation_1.instrument)({
129
+ tracer: this.tracer,
130
+ spanName: `${definitions_1.SpanName.WORKFLOW_QUERY}${definitions_1.SPAN_DELIMITER}${input.queryType}`,
131
+ fn: async (span) => {
132
+ const headers = (0, instrumentation_1.headersWithContext)(input.headers);
133
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
134
+ if (input.workflowExecution.runId) {
135
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, input.workflowExecution.runId);
136
+ }
137
+ return await next({ ...input, headers });
138
+ },
139
+ });
140
+ }
141
+ async terminate(input, next) {
142
+ return await (0, instrumentation_1.instrument)({
143
+ tracer: this.tracer,
144
+ spanName: definitions_1.SpanName.WORKFLOW_TERMINATE,
145
+ fn: async (span) => {
146
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
147
+ if (input.workflowExecution.runId) {
148
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, input.workflowExecution.runId);
149
+ }
150
+ if (input.reason) {
151
+ span.setAttribute(instrumentation_1.TERMINATE_REASON_ATTR_KEY, input.reason);
152
+ }
153
+ return await next(input);
154
+ },
155
+ });
156
+ }
157
+ async cancel(input, next) {
158
+ return await (0, instrumentation_1.instrument)({
159
+ tracer: this.tracer,
160
+ spanName: definitions_1.SpanName.WORKFLOW_CANCEL,
161
+ fn: async (span) => {
162
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
163
+ if (input.workflowExecution.runId) {
164
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, input.workflowExecution.runId);
165
+ }
166
+ return await next(input);
167
+ },
168
+ });
169
+ }
170
+ async describe(input, next) {
171
+ return await (0, instrumentation_1.instrument)({
172
+ tracer: this.tracer,
173
+ spanName: definitions_1.SpanName.WORKFLOW_DESCRIBE,
174
+ fn: async (span) => {
175
+ span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
176
+ if (input.workflowExecution.runId) {
177
+ span.setAttribute(instrumentation_1.RUN_ID_ATTR_KEY, input.workflowExecution.runId);
178
+ }
179
+ return await next(input);
180
+ },
181
+ });
182
+ }
183
+ }
184
+ exports.OpenTelemetryWorkflowClientInterceptor = OpenTelemetryWorkflowClientInterceptor;
185
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","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,sBAAQ,CAAC,eAAe;YAClC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBACjB,IAAI,CAAC,YAAY,CAAC,sCAAoB,EAAE,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;gBAC5E,IAAI,KAAK,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;oBAClC,IAAI,CAAC,YAAY,CAAC,iCAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBACpE,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CACZ,KAA4B,EAC5B,IAAiD;QAEjD,OAAO,MAAM,IAAA,4BAAU,EAAC;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,sBAAQ,CAAC,iBAAiB;YACpC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBACjB,IAAI,CAAC,YAAY,CAAC,sCAAoB,EAAE,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;gBAC5E,IAAI,KAAK,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;oBAClC,IAAI,CAAC,YAAY,CAAC,iCAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBACpE,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAlLD,wFAkLC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `npm i @temporalio/interceptors-opentelemetry-v2`
3
+ *
4
+ * Interceptors that add OpenTelemetry tracing.
5
+ *
6
+ * [Documentation](https://docs.temporal.io/typescript/logging#opentelemetry-tracing)
7
+ *
8
+ * @module
9
+ */
10
+ export * from './plugin';
11
+ export * from './workflow';
12
+ export * from './worker';
13
+ export { OpenTelemetryWorkflowClientInterceptor } from './client';
package/lib/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /**
3
+ * `npm i @temporalio/interceptors-opentelemetry-v2`
4
+ *
5
+ * Interceptors that add OpenTelemetry tracing.
6
+ *
7
+ * [Documentation](https://docs.temporal.io/typescript/logging#opentelemetry-tracing)
8
+ *
9
+ * @module
10
+ */
11
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
+ desc = { enumerable: true, get: function() { return m[k]; } };
16
+ }
17
+ Object.defineProperty(o, k2, desc);
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
23
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.OpenTelemetryWorkflowClientInterceptor = void 0;
27
+ __exportStar(require("./plugin"), exports);
28
+ __exportStar(require("./workflow"), exports);
29
+ __exportStar(require("./worker"), exports);
30
+ var client_1 = require("./client");
31
+ Object.defineProperty(exports, "OpenTelemetryWorkflowClientInterceptor", { enumerable: true, get: function () { return client_1.OpenTelemetryWorkflowClientInterceptor; } });
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,6CAA2B;AAC3B,2CAAyB;AACzB,mCAAkE;AAAzD,gIAAA,sCAAsC,OAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * opentelemetry instrumentation helper functions
3
+ * @module
4
+ */
5
+ import * as otel from '@opentelemetry/api';
6
+ import { type Headers } from '@temporalio/common';
7
+ /** Default trace header for opentelemetry interceptors */
8
+ export declare const TRACE_HEADER = "_tracer-data";
9
+ /** As in workflow run id */
10
+ export declare const RUN_ID_ATTR_KEY = "run_id";
11
+ /** As in workflow id */
12
+ export declare const WORKFLOW_ID_ATTR_KEY = "temporalWorkflowId";
13
+ /** As in activity id */
14
+ export declare const ACTIVITY_ID_ATTR_KEY = "temporalActivityId";
15
+ /** As in update id */
16
+ export declare const UPDATE_ID_ATTR_KEY = "temporalUpdateId";
17
+ /** As in termination reason */
18
+ export declare const TERMINATE_REASON_ATTR_KEY = "temporalTerminateReason";
19
+ /** As in Nexus service */
20
+ export declare const NEXUS_SERVICE_ATTR_KEY = "temporalNexusService";
21
+ /** As in Nexus operation */
22
+ export declare const NEXUS_OPERATION_ATTR_KEY = "temporalNexusOperation";
23
+ /** As in Nexus endpoint */
24
+ export declare const NEXUS_ENDPOINT_ATTR_KEY = "temporalNexusEndpoint";
25
+ /**
26
+ * If found, return an otel Context deserialized from the provided headers
27
+ */
28
+ export declare function extractContextFromHeaders(headers: Headers): otel.Context | undefined;
29
+ /**
30
+ * If found, return an otel Context deserialized from the provided Nexus headers.
31
+ *
32
+ * Nexus headers are plain `Record<string, string>`, so we extract the context
33
+ * directly from the string map.
34
+ */
35
+ export declare function extractContextFromNexusHeaders(headers: Record<string, string>): otel.Context | undefined;
36
+ /**
37
+ * Given headers, return new headers with the current otel context inserted
38
+ */
39
+ export declare function headersWithContext(headers: Headers): Headers;
40
+ /**
41
+ * Given Nexus headers, return new headers with the current otel context injected directly
42
+ */
43
+ export declare function nexusHeadersWithContext(headers: Record<string, string>): Record<string, string>;
44
+ export interface InstrumentOptions<T> {
45
+ tracer: otel.Tracer;
46
+ spanName: string;
47
+ fn: (span: otel.Span) => Promise<T>;
48
+ context?: otel.Context;
49
+ acceptableErrors?: (err: unknown) => boolean;
50
+ }
51
+ export type InstrumentOptionsSync<T> = Omit<InstrumentOptions<T>, 'fn'> & {
52
+ fn: (span: otel.Span) => T;
53
+ };
54
+ /**
55
+ * Wraps `fn` in a span which ends when function returns or throws
56
+ */
57
+ export declare function instrument<T>({ tracer, spanName, fn, context, acceptableErrors, }: InstrumentOptions<T>): Promise<T>;
58
+ export declare function instrumentSync<T>({ tracer, spanName, fn, context, acceptableErrors }: InstrumentOptionsSync<T>): T;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.NEXUS_ENDPOINT_ATTR_KEY = exports.NEXUS_OPERATION_ATTR_KEY = exports.NEXUS_SERVICE_ATTR_KEY = exports.TERMINATE_REASON_ATTR_KEY = exports.UPDATE_ID_ATTR_KEY = exports.ACTIVITY_ID_ATTR_KEY = exports.WORKFLOW_ID_ATTR_KEY = exports.RUN_ID_ATTR_KEY = exports.TRACE_HEADER = void 0;
27
+ exports.extractContextFromHeaders = extractContextFromHeaders;
28
+ exports.extractContextFromNexusHeaders = extractContextFromNexusHeaders;
29
+ exports.headersWithContext = headersWithContext;
30
+ exports.nexusHeadersWithContext = nexusHeadersWithContext;
31
+ exports.instrument = instrument;
32
+ exports.instrumentSync = instrumentSync;
33
+ /**
34
+ * opentelemetry instrumentation helper functions
35
+ * @module
36
+ */
37
+ const otel = __importStar(require("@opentelemetry/api"));
38
+ const common_1 = require("@temporalio/common");
39
+ /** Default trace header for opentelemetry interceptors */
40
+ exports.TRACE_HEADER = '_tracer-data';
41
+ /** As in workflow run id */
42
+ exports.RUN_ID_ATTR_KEY = 'run_id';
43
+ /** As in workflow id */
44
+ exports.WORKFLOW_ID_ATTR_KEY = 'temporalWorkflowId';
45
+ /** As in activity id */
46
+ exports.ACTIVITY_ID_ATTR_KEY = 'temporalActivityId';
47
+ /** As in update id */
48
+ exports.UPDATE_ID_ATTR_KEY = 'temporalUpdateId';
49
+ /** As in termination reason */
50
+ exports.TERMINATE_REASON_ATTR_KEY = 'temporalTerminateReason';
51
+ /** As in Nexus service */
52
+ exports.NEXUS_SERVICE_ATTR_KEY = 'temporalNexusService';
53
+ /** As in Nexus operation */
54
+ exports.NEXUS_OPERATION_ATTR_KEY = 'temporalNexusOperation';
55
+ /** As in Nexus endpoint */
56
+ exports.NEXUS_ENDPOINT_ATTR_KEY = 'temporalNexusEndpoint';
57
+ const payloadConverter = common_1.defaultPayloadConverter;
58
+ /**
59
+ * If found, return an otel Context deserialized from the provided headers
60
+ */
61
+ function extractContextFromHeaders(headers) {
62
+ const encodedSpanContext = headers[exports.TRACE_HEADER];
63
+ if (encodedSpanContext === undefined) {
64
+ return undefined;
65
+ }
66
+ const textMap = payloadConverter.fromPayload(encodedSpanContext);
67
+ return otel.propagation.extract(otel.context.active(), textMap, otel.defaultTextMapGetter);
68
+ }
69
+ /**
70
+ * If found, return an otel Context deserialized from the provided Nexus headers.
71
+ *
72
+ * Nexus headers are plain `Record<string, string>`, so we extract the context
73
+ * directly from the string map.
74
+ */
75
+ function extractContextFromNexusHeaders(headers) {
76
+ if (Object.keys(headers).length === 0) {
77
+ return undefined;
78
+ }
79
+ return otel.propagation.extract(otel.context.active(), headers, otel.defaultTextMapGetter);
80
+ }
81
+ /**
82
+ * Given headers, return new headers with the current otel context inserted
83
+ */
84
+ function headersWithContext(headers) {
85
+ const carrier = {};
86
+ otel.propagation.inject(otel.context.active(), carrier, otel.defaultTextMapSetter);
87
+ return { ...headers, [exports.TRACE_HEADER]: payloadConverter.toPayload(carrier) };
88
+ }
89
+ /**
90
+ * Given Nexus headers, return new headers with the current otel context injected directly
91
+ */
92
+ function nexusHeadersWithContext(headers) {
93
+ const carrier = {};
94
+ otel.propagation.inject(otel.context.active(), carrier, otel.defaultTextMapSetter);
95
+ return { ...headers, ...carrier };
96
+ }
97
+ async function wrapWithSpan(span, fn, acceptableErrors) {
98
+ try {
99
+ const ret = await fn(span);
100
+ span.setStatus({ code: otel.SpanStatusCode.OK });
101
+ return ret;
102
+ }
103
+ catch (err) {
104
+ maybeAddErrorToSpan(err, span, acceptableErrors);
105
+ throw err;
106
+ }
107
+ finally {
108
+ span.end();
109
+ }
110
+ }
111
+ function wrapWithSpanSync(span, fn, acceptableErrors) {
112
+ try {
113
+ const ret = fn(span);
114
+ span.setStatus({ code: otel.SpanStatusCode.OK });
115
+ return ret;
116
+ }
117
+ catch (err) {
118
+ maybeAddErrorToSpan(err, span, acceptableErrors);
119
+ throw err;
120
+ }
121
+ finally {
122
+ span.end();
123
+ }
124
+ }
125
+ function maybeAddErrorToSpan(err, span, acceptableErrors) {
126
+ const isBenignErr = err instanceof common_1.ApplicationFailure && err.category === common_1.ApplicationFailureCategory.BENIGN;
127
+ if (acceptableErrors === undefined || !acceptableErrors(err)) {
128
+ const statusCode = isBenignErr ? otel.SpanStatusCode.UNSET : otel.SpanStatusCode.ERROR;
129
+ const message = err != null && typeof err.message === 'string' ? err.message : String(err);
130
+ span.setStatus({ code: statusCode, message });
131
+ span.recordException(err);
132
+ }
133
+ else {
134
+ span.setStatus({ code: otel.SpanStatusCode.OK });
135
+ }
136
+ }
137
+ /**
138
+ * Wraps `fn` in a span which ends when function returns or throws
139
+ */
140
+ async function instrument({ tracer, spanName, fn, context, acceptableErrors, }) {
141
+ if (context) {
142
+ return await tracer.startActiveSpan(spanName, {}, context, async (span) => await wrapWithSpan(span, fn, acceptableErrors));
143
+ }
144
+ return await tracer.startActiveSpan(spanName, async (span) => await wrapWithSpan(span, fn, acceptableErrors));
145
+ }
146
+ function instrumentSync({ tracer, spanName, fn, context, acceptableErrors }) {
147
+ if (context) {
148
+ return tracer.startActiveSpan(spanName, {}, context, (span) => wrapWithSpanSync(span, fn, acceptableErrors));
149
+ }
150
+ return tracer.startActiveSpan(spanName, (span) => wrapWithSpanSync(span, fn, acceptableErrors));
151
+ }
152
+ //# sourceMappingURL=instrumentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,8DAOC;AAQD,wEAKC;AAKD,gDAIC;AAKD,0DAIC;AA6DD,gCAgBC;AAED,wCAKC;AA9JD;;;GAGG;AACH,yDAA2C;AAC3C,+CAK4B;AAE5B,0DAA0D;AAC7C,QAAA,YAAY,GAAG,cAAc,CAAC;AAC3C,4BAA4B;AACf,QAAA,eAAe,GAAG,QAAQ,CAAC;AACxC,wBAAwB;AACX,QAAA,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,wBAAwB;AACX,QAAA,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,sBAAsB;AACT,QAAA,kBAAkB,GAAG,kBAAkB,CAAC;AACrD,+BAA+B;AAClB,QAAA,yBAAyB,GAAG,yBAAyB,CAAC;AACnE,0BAA0B;AACb,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAC7D,4BAA4B;AACf,QAAA,wBAAwB,GAAG,wBAAwB,CAAC;AACjE,2BAA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,SAAgB,cAAc,CAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAA4B;IAC7G,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAClG,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
2
+ import type { Resource } from '@opentelemetry/resources';
3
+ import { SimplePlugin } from '@temporalio/plugin';
4
+ import type { ReplayWorkerOptions, WorkerOptions } from '@temporalio/worker';
5
+ import type { InterceptorOptions } from './client';
6
+ /**
7
+ * Configuration options for {@link OpenTelemetryPlugin}.
8
+ *
9
+ * @experimental Plugins is an experimental feature; APIs may change without notice.
10
+ */
11
+ export interface OpenTelemetryPluginOptions extends InterceptorOptions {
12
+ /** OpenTelemetry resource attributes to attach to exported spans */
13
+ readonly resource: Resource;
14
+ /** Exporter used to send spans to a tracing backend */
15
+ readonly spanProcessor: SpanProcessor;
16
+ }
17
+ /**
18
+ * A plugin that adds OpenTelemetry tracing.
19
+ *
20
+ * Configures Client, Activity, and Workflow interceptors for trace propagation and injects
21
+ * a span exporter sink for Workflow spans.
22
+ *
23
+ * @experimental Plugins is an experimental feature; APIs may change without notice.
24
+ */
25
+ export declare class OpenTelemetryPlugin extends SimplePlugin {
26
+ readonly otelOptions: OpenTelemetryPluginOptions;
27
+ constructor(otelOptions: OpenTelemetryPluginOptions);
28
+ configureWorker(options: WorkerOptions): WorkerOptions;
29
+ configureReplayWorker(options: ReplayWorkerOptions): ReplayWorkerOptions;
30
+ private injectSinks;
31
+ }
package/lib/plugin.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenTelemetryPlugin = void 0;
4
+ const plugin_1 = require("@temporalio/plugin");
5
+ const client_1 = require("./client");
6
+ const worker_1 = require("./worker");
7
+ /**
8
+ * A plugin that adds OpenTelemetry tracing.
9
+ *
10
+ * Configures Client, Activity, and Workflow interceptors for trace propagation and injects
11
+ * a span exporter sink for Workflow spans.
12
+ *
13
+ * @experimental Plugins is an experimental feature; APIs may change without notice.
14
+ */
15
+ class OpenTelemetryPlugin extends plugin_1.SimplePlugin {
16
+ otelOptions;
17
+ constructor(otelOptions) {
18
+ const workflowInterceptorsPath = require.resolve('./workflow-interceptors');
19
+ const interceptorOptions = otelOptions.tracer ? { tracer: otelOptions.tracer } : {};
20
+ super({
21
+ name: 'OpenTelemetryPlugin',
22
+ clientInterceptors: {
23
+ workflow: [new client_1.OpenTelemetryWorkflowClientInterceptor(interceptorOptions)],
24
+ },
25
+ workerInterceptors: {
26
+ client: {
27
+ workflow: [new client_1.OpenTelemetryWorkflowClientInterceptor(interceptorOptions)],
28
+ },
29
+ workflowModules: [workflowInterceptorsPath],
30
+ activity: [
31
+ (ctx) => ({
32
+ inbound: new worker_1.OpenTelemetryActivityInboundInterceptor(ctx, interceptorOptions),
33
+ outbound: new worker_1.OpenTelemetryActivityOutboundInterceptor(ctx),
34
+ }),
35
+ ],
36
+ nexus: [
37
+ (ctx) => ({
38
+ inbound: new worker_1.OpenTelemetryNexusInboundInterceptor(ctx, interceptorOptions),
39
+ outbound: new worker_1.OpenTelemetryNexusOutboundInterceptor(ctx),
40
+ }),
41
+ ],
42
+ },
43
+ });
44
+ this.otelOptions = otelOptions;
45
+ }
46
+ configureWorker(options) {
47
+ return super.configureWorker(this.injectSinks(options));
48
+ }
49
+ configureReplayWorker(options) {
50
+ return super.configureReplayWorker(this.injectSinks(options));
51
+ }
52
+ injectSinks(options) {
53
+ const sinks = {
54
+ exporter: (0, worker_1.makeWorkflowExporter)(this.otelOptions.spanProcessor, this.otelOptions.resource),
55
+ };
56
+ return {
57
+ ...options,
58
+ sinks: {
59
+ ...options.sinks,
60
+ ...sinks,
61
+ },
62
+ };
63
+ }
64
+ }
65
+ exports.OpenTelemetryPlugin = OpenTelemetryPlugin;
66
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AAEA,+CAAkD;AAGlD,qCAAkE;AAClE,qCAMkB;AAelB;;;;;;;GAOG;AACH,MAAa,mBAAoB,SAAQ,qBAAY;IAC9B;IAArB,YAAqB,WAAuC;QAC1D,MAAM,wBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAC5E,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpF,KAAK,CAAC;YACJ,IAAI,EAAE,qBAAqB;YAC3B,kBAAkB,EAAE;gBAClB,QAAQ,EAAE,CAAC,IAAI,+CAAsC,CAAC,kBAAkB,CAAC,CAAC;aAC3E;YACD,kBAAkB,EAAE;gBAClB,MAAM,EAAE;oBACN,QAAQ,EAAE,CAAC,IAAI,+CAAsC,CAAC,kBAAkB,CAAC,CAAC;iBAC3E;gBACD,eAAe,EAAE,CAAC,wBAAwB,CAAC;gBAC3C,QAAQ,EAAE;oBACR,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;wBACR,OAAO,EAAE,IAAI,gDAAuC,CAAC,GAAG,EAAE,kBAAkB,CAAC;wBAC7E,QAAQ,EAAE,IAAI,iDAAwC,CAAC,GAAG,CAAC;qBAC5D,CAAC;iBACH;gBACD,KAAK,EAAE;oBACL,CAAC,GAAG,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