@temporalio/interceptors-opentelemetry 1.14.1 → 1.14.2
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.
- package/lib/client/index.js +11 -11
- package/lib/client/index.js.map +1 -1
- package/lib/worker/index.d.ts +1 -1
- package/lib/worker/index.js +2 -2
- package/lib/worker/index.js.map +1 -1
- package/lib/workflow/context-manager.d.ts +2 -2
- package/lib/workflow/context-manager.js +8 -2
- package/lib/workflow/context-manager.js.map +1 -1
- package/lib/workflow/definitions.d.ts +1 -1
- package/lib/workflow/index.d.ts +2 -0
- package/lib/workflow/index.js +25 -17
- package/lib/workflow/index.js.map +1 -1
- package/lib/workflow/runtime.js +3 -2
- package/lib/workflow/runtime.js.map +1 -1
- package/lib/workflow/span-exporter.d.ts +1 -1
- package/lib/workflow/span-exporter.js +6 -6
- package/lib/workflow/span-exporter.js.map +1 -1
- package/lib/workflow/workflow-module-loader.d.ts +28 -0
- package/lib/workflow/workflow-module-loader.js +56 -0
- package/lib/workflow/workflow-module-loader.js.map +1 -0
- package/package.json +10 -11
- package/src/client/index.ts +1 -1
- package/src/worker/index.ts +1 -6
- package/src/workflow/context-manager.ts +13 -6
- package/src/workflow/definitions.ts +1 -1
- package/src/workflow/index.ts +25 -14
- package/src/workflow/runtime.ts +4 -2
- package/src/workflow/span-exporter.ts +7 -6
- package/src/workflow/workflow-module-loader.ts +64 -0
- package/lib/workflow/workflow-imports-impl.d.ts +0 -9
- package/lib/workflow/workflow-imports-impl.js +0 -20
- package/lib/workflow/workflow-imports-impl.js.map +0 -1
- package/lib/workflow/workflow-imports.d.ts +0 -19
- package/lib/workflow/workflow-imports.js +0 -26
- package/lib/workflow/workflow-imports.js.map +0 -1
- package/src/workflow/workflow-imports-impl.ts +0 -9
- package/src/workflow/workflow-imports.ts +0 -42
package/lib/client/index.js
CHANGED
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.OpenTelemetryWorkflowClientInterceptor = void 0;
|
|
27
27
|
const otel = __importStar(require("@opentelemetry/api"));
|
|
28
28
|
const instrumentation_1 = require("../instrumentation");
|
|
29
|
-
const
|
|
29
|
+
const workflow_1 = require("../workflow");
|
|
30
30
|
/**
|
|
31
31
|
* Intercepts calls to start a Workflow.
|
|
32
32
|
*
|
|
@@ -40,7 +40,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
40
40
|
async start(input, next) {
|
|
41
41
|
return await (0, instrumentation_1.instrument)({
|
|
42
42
|
tracer: this.tracer,
|
|
43
|
-
spanName: `${
|
|
43
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_START}${workflow_1.SPAN_DELIMITER}${input.workflowType}`,
|
|
44
44
|
fn: async (span) => {
|
|
45
45
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
46
46
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.options.workflowId);
|
|
@@ -53,7 +53,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
53
53
|
async signal(input, next) {
|
|
54
54
|
return await (0, instrumentation_1.instrument)({
|
|
55
55
|
tracer: this.tracer,
|
|
56
|
-
spanName: `${
|
|
56
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_SIGNAL}${workflow_1.SPAN_DELIMITER}${input.signalName}`,
|
|
57
57
|
fn: async (span) => {
|
|
58
58
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
|
|
59
59
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
@@ -64,7 +64,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
64
64
|
async startWithDetails(input, next) {
|
|
65
65
|
return await (0, instrumentation_1.instrument)({
|
|
66
66
|
tracer: this.tracer,
|
|
67
|
-
spanName: `${
|
|
67
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_START}${workflow_1.SPAN_DELIMITER}${input.workflowType}`,
|
|
68
68
|
fn: async (span) => {
|
|
69
69
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
70
70
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.options.workflowId);
|
|
@@ -77,7 +77,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
77
77
|
async startUpdate(input, next) {
|
|
78
78
|
return await (0, instrumentation_1.instrument)({
|
|
79
79
|
tracer: this.tracer,
|
|
80
|
-
spanName: `${
|
|
80
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_START_UPDATE}${workflow_1.SPAN_DELIMITER}${input.updateName}`,
|
|
81
81
|
fn: async (span) => {
|
|
82
82
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
|
|
83
83
|
if (input.options.updateId) {
|
|
@@ -93,7 +93,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
93
93
|
async startUpdateWithStart(input, next) {
|
|
94
94
|
return await (0, instrumentation_1.instrument)({
|
|
95
95
|
tracer: this.tracer,
|
|
96
|
-
spanName: `${
|
|
96
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_UPDATE_WITH_START}${workflow_1.SPAN_DELIMITER}${input.updateName}`,
|
|
97
97
|
fn: async (span) => {
|
|
98
98
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowStartOptions.workflowId);
|
|
99
99
|
if (input.updateOptions.updateId) {
|
|
@@ -112,7 +112,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
112
112
|
async signalWithStart(input, next) {
|
|
113
113
|
return await (0, instrumentation_1.instrument)({
|
|
114
114
|
tracer: this.tracer,
|
|
115
|
-
spanName: `${
|
|
115
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_SIGNAL_WITH_START}${workflow_1.SPAN_DELIMITER}${input.workflowType}`,
|
|
116
116
|
fn: async (span) => {
|
|
117
117
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.options.workflowId);
|
|
118
118
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
@@ -125,7 +125,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
125
125
|
async query(input, next) {
|
|
126
126
|
return await (0, instrumentation_1.instrument)({
|
|
127
127
|
tracer: this.tracer,
|
|
128
|
-
spanName: `${
|
|
128
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_QUERY}${workflow_1.SPAN_DELIMITER}${input.queryType}`,
|
|
129
129
|
fn: async (span) => {
|
|
130
130
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
131
131
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
|
|
@@ -139,7 +139,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
139
139
|
async terminate(input, next) {
|
|
140
140
|
return await (0, instrumentation_1.instrument)({
|
|
141
141
|
tracer: this.tracer,
|
|
142
|
-
spanName:
|
|
142
|
+
spanName: workflow_1.SpanName.WORKFLOW_TERMINATE,
|
|
143
143
|
fn: async (span) => {
|
|
144
144
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
|
|
145
145
|
if (input.workflowExecution.runId) {
|
|
@@ -155,7 +155,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
155
155
|
async cancel(input, next) {
|
|
156
156
|
return await (0, instrumentation_1.instrument)({
|
|
157
157
|
tracer: this.tracer,
|
|
158
|
-
spanName:
|
|
158
|
+
spanName: workflow_1.SpanName.WORKFLOW_CANCEL,
|
|
159
159
|
fn: async (span) => {
|
|
160
160
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
|
|
161
161
|
if (input.workflowExecution.runId) {
|
|
@@ -168,7 +168,7 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
168
168
|
async describe(input, next) {
|
|
169
169
|
return await (0, instrumentation_1.instrument)({
|
|
170
170
|
tracer: this.tracer,
|
|
171
|
-
spanName:
|
|
171
|
+
spanName: workflow_1.SpanName.WORKFLOW_DESCRIBE,
|
|
172
172
|
fn: async (span) => {
|
|
173
173
|
span.setAttribute(instrumentation_1.WORKFLOW_ID_ATTR_KEY, input.workflowExecution.workflowId);
|
|
174
174
|
if (input.workflowExecution.runId) {
|
package/lib/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAoB3C,wDAO4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAoB3C,wDAO4B;AAC5B,0CAAuD;AAMvD;;;;GAIG;AACH,MAAa,sCAAsC;IAC9B,MAAM,CAAc;IAEvC,YAAY,OAA4B;QACtC,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,gCAAgC,CAAC,CAAC;IAC1F,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAAyB,EAAE,IAA8C;QACnF,OAAO,MAAM,IAAA,4BAAU,EAAC;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,GAAG,mBAAQ,CAAC,cAAc,GAAG,yBAAc,GAAG,KAAK,CAAC,YAAY,EAAE;YAC5E,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;gBACjB,MAAM,OAAO,GAAG,IAAA,oCAAkB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBAClD,IAAI,CAAC,YAAY,CAAC,sCAAoB,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAClE,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE,GAAG,KAA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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/worker/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Resource } from '@opentelemetry/resources';
|
|
|
3
3
|
import type { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
4
4
|
import type { Context as ActivityContext } from '@temporalio/activity';
|
|
5
5
|
import type { Next, ActivityInboundCallsInterceptor, ActivityOutboundCallsInterceptor, InjectedSink, GetLogAttributesInput, GetMetricTagsInput, ActivityExecuteInput } from '@temporalio/worker';
|
|
6
|
-
import { type OpenTelemetryWorkflowExporter } from '../workflow
|
|
6
|
+
import { type OpenTelemetryWorkflowExporter } from '../workflow';
|
|
7
7
|
export interface InterceptorOptions {
|
|
8
8
|
readonly tracer?: otel.Tracer;
|
|
9
9
|
}
|
package/lib/worker/index.js
CHANGED
|
@@ -27,7 +27,7 @@ exports.OpenTelemetryActivityOutboundInterceptor = exports.OpenTelemetryActivity
|
|
|
27
27
|
exports.makeWorkflowExporter = makeWorkflowExporter;
|
|
28
28
|
const otel = __importStar(require("@opentelemetry/api"));
|
|
29
29
|
const instrumentation_1 = require("../instrumentation");
|
|
30
|
-
const
|
|
30
|
+
const workflow_1 = require("../workflow");
|
|
31
31
|
/**
|
|
32
32
|
* Intercepts calls to start an Activity.
|
|
33
33
|
*
|
|
@@ -43,7 +43,7 @@ class OpenTelemetryActivityInboundInterceptor {
|
|
|
43
43
|
}
|
|
44
44
|
async execute(input, next) {
|
|
45
45
|
const context = (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
46
|
-
const spanName = `${
|
|
46
|
+
const spanName = `${workflow_1.SpanName.ACTIVITY_EXECUTE}${workflow_1.SPAN_DELIMITER}${this.ctx.info.activityType}`;
|
|
47
47
|
return await (0, instrumentation_1.instrument)({
|
|
48
48
|
tracer: this.tracer,
|
|
49
49
|
spanName,
|
package/lib/worker/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,oDAiBC;AA5HD,yDAA2C;AAa3C,wDAM4B;AAC5B,0CAAkH;AAMlH;;;;;GAKG;AACH,MAAa,uCAAuC;IAI7B;IAHF,MAAM,CAAc;IAEvC,YACqB,GAAoB,EACvC,OAA4B;QADT,QAAG,GAAH,GAAG,CAAiB;QAGvC,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,kCAAkC,CAAC,CAAC;IAC5F,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAA2B,EAAE,IAAsD;QAC/F,MAAM,OAAO,GAAG,IAAA,2CAAyB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzD,MAAM,QAAQ,GAAG,GAAG,mBAAQ,CAAC,gBAAgB,GAAG,yBAAc,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QAC9F,OAAO,MAAM,IAAA,4BAAU,EAAC;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ;YACR,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;gBACX,IAAI,CAAC,YAAY,CAAC,sCAAoB,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;gBACpF,IAAI,CAAC,YAAY,CAAC,iCAAe,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,K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AQ,EAAE,WAAW,CAAC,OAAO;gBAC7B,OAAO,EAAE,WAAW,CAAC,MAAM;gBAC3B,WAAW,EAAE,IAAI,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE;gBACtD,GAAG,KAAK;aACT,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;CACF;AAtCD,4FAsCC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,QAAsB,EACtB,QAAkB;IAElB,OAAO;QACL,MAAM,EAAE;YACN,EAAE,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;gBACrB,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;oBACxC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;oBAC3C,qFAAqF;oBACrF,OAAO,mBAAmB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBACnD,CAAC,CAAC,CAAC;gBACH,0CAA0C;gBAC1C,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC1C,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,YAA8B,EAAE,QAAkB;IAC7E,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,GAAG,YAAY,CAAC;IAC9C,OAAO;QACL,WAAW;YACT,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,QAAQ;QACR,GAAG,IAAI;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type AsyncLocalStorage } from 'async_hooks';
|
|
2
1
|
import * as otel from '@opentelemetry/api';
|
|
3
2
|
export declare class ContextManager implements otel.ContextManager {
|
|
4
|
-
protected storage: AsyncLocalStorage<otel.Context
|
|
3
|
+
protected storage: import("async_hooks").AsyncLocalStorage<otel.Context> | undefined;
|
|
4
|
+
constructor();
|
|
5
5
|
active(): otel.Context;
|
|
6
6
|
bind<T>(context: otel.Context, target: T): T;
|
|
7
7
|
enable(): this;
|
|
@@ -25,9 +25,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ContextManager = void 0;
|
|
27
27
|
const otel = __importStar(require("@opentelemetry/api"));
|
|
28
|
+
const workflow_module_loader_1 = require("./workflow-module-loader");
|
|
29
|
+
const AsyncLocalStorage = (0, workflow_module_loader_1.getWorkflowModuleIfAvailable)()?.AsyncLocalStorage;
|
|
28
30
|
class ContextManager {
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
+
// If `@temporalio/workflow` is not available, ignore for now.
|
|
32
|
+
// When ContextManager is constructed module resolution error will be thrown.
|
|
33
|
+
storage = AsyncLocalStorage ? new AsyncLocalStorage() : undefined;
|
|
34
|
+
constructor() {
|
|
35
|
+
(0, workflow_module_loader_1.ensureWorkflowModuleLoaded)();
|
|
36
|
+
}
|
|
31
37
|
active() {
|
|
32
38
|
return this.storage.getStore() || otel.ROOT_CONTEXT;
|
|
33
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/workflow/context-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/workflow/context-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qEAAoG;AAEpG,MAAM,iBAAiB,GAAG,IAAA,qDAA4B,GAAE,EAAE,iBAAiB,CAAC;AAE5E,MAAa,cAAc;IACzB,8DAA8D;IAC9D,6EAA6E;IACnE,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,IAAI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AE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF;AAtDD,wCAsDC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
2
|
import * as tracing from '@opentelemetry/sdk-trace-base';
|
|
3
3
|
import { InstrumentationLibrary } from '@opentelemetry/core';
|
|
4
|
-
import
|
|
4
|
+
import { Sink, Sinks } from '@temporalio/workflow';
|
|
5
5
|
/**
|
|
6
6
|
* Serializable version of the opentelemetry Span for cross isolate copying
|
|
7
7
|
*/
|
package/lib/workflow/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './definitions';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInterceptor {
|
|
14
14
|
protected readonly tracer: otel.Tracer;
|
|
15
|
+
constructor();
|
|
15
16
|
execute(input: WorkflowExecuteInput, next: Next<WorkflowInboundCallsInterceptor, 'execute'>): Promise<unknown>;
|
|
16
17
|
handleSignal(input: SignalInput, next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>): Promise<void>;
|
|
17
18
|
handleUpdate(input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'handleUpdate'>): Promise<unknown>;
|
|
@@ -27,6 +28,7 @@ export declare class OpenTelemetryInboundInterceptor implements WorkflowInboundC
|
|
|
27
28
|
*/
|
|
28
29
|
export declare class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsInterceptor {
|
|
29
30
|
protected readonly tracer: otel.Tracer;
|
|
31
|
+
constructor();
|
|
30
32
|
scheduleActivity(input: ActivityInput, next: Next<WorkflowOutboundCallsInterceptor, 'scheduleActivity'>): Promise<unknown>;
|
|
31
33
|
scheduleLocalActivity(input: LocalActivityInput, next: Next<WorkflowOutboundCallsInterceptor, 'scheduleLocalActivity'>): Promise<unknown>;
|
|
32
34
|
startNexusOperation(input: StartNexusOperationInput, next: Next<WorkflowOutboundCallsInterceptor, 'startNexusOperation'>): Promise<StartNexusOperationOutput>;
|
package/lib/workflow/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const instrumentation_1 = require("../instrumentation");
|
|
|
36
36
|
const context_manager_1 = require("./context-manager");
|
|
37
37
|
const definitions_1 = require("./definitions");
|
|
38
38
|
const span_exporter_1 = require("./span-exporter");
|
|
39
|
-
const
|
|
39
|
+
const workflow_module_loader_1 = require("./workflow-module-loader");
|
|
40
40
|
__exportStar(require("./definitions"), exports);
|
|
41
41
|
let tracer = undefined;
|
|
42
42
|
let contextManager = undefined;
|
|
@@ -62,24 +62,28 @@ function getTracer() {
|
|
|
62
62
|
*/
|
|
63
63
|
class OpenTelemetryInboundInterceptor {
|
|
64
64
|
tracer = getTracer();
|
|
65
|
+
constructor() {
|
|
66
|
+
(0, workflow_module_loader_1.ensureWorkflowModuleLoaded)();
|
|
67
|
+
}
|
|
65
68
|
async execute(input, next) {
|
|
69
|
+
const { workflowInfo, ContinueAsNew } = (0, workflow_module_loader_1.getWorkflowModule)();
|
|
66
70
|
const context = (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
67
|
-
if (!(0,
|
|
71
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
68
72
|
await Promise.resolve();
|
|
69
73
|
return await (0, instrumentation_1.instrument)({
|
|
70
74
|
tracer: this.tracer,
|
|
71
|
-
spanName: `${definitions_1.SpanName.WORKFLOW_EXECUTE}${definitions_1.SPAN_DELIMITER}${
|
|
75
|
+
spanName: `${definitions_1.SpanName.WORKFLOW_EXECUTE}${definitions_1.SPAN_DELIMITER}${workflowInfo().workflowType}`,
|
|
72
76
|
fn: () => next(input),
|
|
73
77
|
context,
|
|
74
|
-
acceptableErrors: (err) => err instanceof
|
|
78
|
+
acceptableErrors: (err) => err instanceof ContinueAsNew,
|
|
75
79
|
});
|
|
76
80
|
}
|
|
77
81
|
async handleSignal(input, next) {
|
|
78
82
|
// Tracing of inbound signals was added in v1.11.5.
|
|
79
|
-
if (!(0,
|
|
83
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceptorsTracesInboundSignals'))
|
|
80
84
|
return next(input);
|
|
81
85
|
const context = (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
82
|
-
if (!(0,
|
|
86
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
83
87
|
await Promise.resolve();
|
|
84
88
|
return await (0, instrumentation_1.instrument)({
|
|
85
89
|
tracer: this.tracer,
|
|
@@ -89,7 +93,7 @@ class OpenTelemetryInboundInterceptor {
|
|
|
89
93
|
});
|
|
90
94
|
}
|
|
91
95
|
async handleUpdate(input, next) {
|
|
92
|
-
if (!(0,
|
|
96
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceptorsInstrumentsAllMethods'))
|
|
93
97
|
return next(input);
|
|
94
98
|
const context = (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
95
99
|
return await (0, instrumentation_1.instrument)({
|
|
@@ -103,7 +107,7 @@ class OpenTelemetryInboundInterceptor {
|
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
109
|
validateUpdate(input, next) {
|
|
106
|
-
if (!(0,
|
|
110
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceptorsInstrumentsAllMethods'))
|
|
107
111
|
return next(input);
|
|
108
112
|
const context = (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
109
113
|
(0, instrumentation_1.instrumentSync)({
|
|
@@ -117,7 +121,7 @@ class OpenTelemetryInboundInterceptor {
|
|
|
117
121
|
});
|
|
118
122
|
}
|
|
119
123
|
async handleQuery(input, next) {
|
|
120
|
-
if (!(0,
|
|
124
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceptorsInstrumentsAllMethods'))
|
|
121
125
|
return next(input);
|
|
122
126
|
const context = (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
123
127
|
return await (0, instrumentation_1.instrument)({
|
|
@@ -138,13 +142,16 @@ exports.OpenTelemetryInboundInterceptor = OpenTelemetryInboundInterceptor;
|
|
|
138
142
|
*/
|
|
139
143
|
class OpenTelemetryOutboundInterceptor {
|
|
140
144
|
tracer = getTracer();
|
|
145
|
+
constructor() {
|
|
146
|
+
(0, workflow_module_loader_1.ensureWorkflowModuleLoaded)();
|
|
147
|
+
}
|
|
141
148
|
async scheduleActivity(input, next) {
|
|
142
149
|
return await (0, instrumentation_1.instrument)({
|
|
143
150
|
tracer: this.tracer,
|
|
144
151
|
spanName: `${definitions_1.SpanName.ACTIVITY_START}${definitions_1.SPAN_DELIMITER}${input.activityType}`,
|
|
145
152
|
fn: async () => {
|
|
146
153
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
147
|
-
if (!(0,
|
|
154
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
148
155
|
await Promise.resolve();
|
|
149
156
|
return next({
|
|
150
157
|
...input,
|
|
@@ -155,14 +162,14 @@ class OpenTelemetryOutboundInterceptor {
|
|
|
155
162
|
}
|
|
156
163
|
async scheduleLocalActivity(input, next) {
|
|
157
164
|
// Tracing of local activities was added in v1.11.6.
|
|
158
|
-
if (!(0,
|
|
165
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceptorsTracesLocalActivities'))
|
|
159
166
|
return next(input);
|
|
160
167
|
return await (0, instrumentation_1.instrument)({
|
|
161
168
|
tracer: this.tracer,
|
|
162
169
|
spanName: `${definitions_1.SpanName.ACTIVITY_START}${definitions_1.SPAN_DELIMITER}${input.activityType}`,
|
|
163
170
|
fn: async () => {
|
|
164
171
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
165
|
-
if (!(0,
|
|
172
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
166
173
|
await Promise.resolve();
|
|
167
174
|
return next({
|
|
168
175
|
...input,
|
|
@@ -172,7 +179,7 @@ class OpenTelemetryOutboundInterceptor {
|
|
|
172
179
|
});
|
|
173
180
|
}
|
|
174
181
|
async startNexusOperation(input, next) {
|
|
175
|
-
if (!(0,
|
|
182
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceptorsInstrumentsAllMethods'))
|
|
176
183
|
return next(input);
|
|
177
184
|
return await (0, instrumentation_1.instrument)({
|
|
178
185
|
tracer: this.tracer,
|
|
@@ -191,7 +198,7 @@ class OpenTelemetryOutboundInterceptor {
|
|
|
191
198
|
spanName: `${definitions_1.SpanName.CHILD_WORKFLOW_START}${definitions_1.SPAN_DELIMITER}${input.workflowType}`,
|
|
192
199
|
fn: async () => {
|
|
193
200
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
194
|
-
if (!(0,
|
|
201
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
195
202
|
await Promise.resolve();
|
|
196
203
|
return next({
|
|
197
204
|
...input,
|
|
@@ -201,19 +208,20 @@ class OpenTelemetryOutboundInterceptor {
|
|
|
201
208
|
});
|
|
202
209
|
}
|
|
203
210
|
async continueAsNew(input, next) {
|
|
211
|
+
const { ContinueAsNew } = (0, workflow_module_loader_1.getWorkflowModule)();
|
|
204
212
|
return await (0, instrumentation_1.instrument)({
|
|
205
213
|
tracer: this.tracer,
|
|
206
214
|
spanName: `${definitions_1.SpanName.CONTINUE_AS_NEW}${definitions_1.SPAN_DELIMITER}${input.options.workflowType}`,
|
|
207
215
|
fn: async () => {
|
|
208
216
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
209
|
-
if (!(0,
|
|
217
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
210
218
|
await Promise.resolve();
|
|
211
219
|
return next({
|
|
212
220
|
...input,
|
|
213
221
|
headers,
|
|
214
222
|
});
|
|
215
223
|
},
|
|
216
|
-
acceptableErrors: (err) => err instanceof
|
|
224
|
+
acceptableErrors: (err) => err instanceof ContinueAsNew,
|
|
217
225
|
});
|
|
218
226
|
}
|
|
219
227
|
async signalWorkflow(input, next) {
|
|
@@ -222,7 +230,7 @@ class OpenTelemetryOutboundInterceptor {
|
|
|
222
230
|
spanName: `${definitions_1.SpanName.WORKFLOW_SIGNAL}${definitions_1.SPAN_DELIMITER}${input.signalName}`,
|
|
223
231
|
fn: async () => {
|
|
224
232
|
const headers = (0, instrumentation_1.headersWithContext)(input.headers);
|
|
225
|
-
if (!(0,
|
|
233
|
+
if (!(0, workflow_module_loader_1.hasSdkFlag)('OpenTelemetryInterceporsAvoidsExtraYields'))
|
|
226
234
|
await Promise.resolve();
|
|
227
235
|
return next({
|
|
228
236
|
...input,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,uDAAuD;AACvD,qBAAmB,CAAC,uDAAuD;AAC3E,yDAA2C;AAC3C,uEAAyD;AAqBzD,wDAS4B;AAC5B,uDAAmD;AACnD,+CAAyD;AACzD,mDAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,uDAAuD;AACvD,qBAAmB,CAAC,uDAAuD;AAC3E,yDAA2C;AAC3C,uEAAyD;AAqBzD,wDAS4B;AAC5B,uDAAmD;AACnD,+CAAyD;AACzD,mDAA+C;AAC/C,qEAAqG;AAErG,gDAA8B;AAE9B,IAAI,MAAM,GAA4B,SAAS,CAAC;AAChD,IAAI,cAAc,GAA+B,SAAS,CAAC;AAE3D,SAAS,SAAS;IAChB,IAAI,cAAc,KAAK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AC;QACD,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC;CACF;AAPD,8EAOC"}
|
package/lib/workflow/runtime.js
CHANGED
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Sets global variables required for importing opentelemetry in isolate
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const workflow_module_loader_1 = require("./workflow-module-loader");
|
|
8
|
+
const inWorkflowContext = (0, workflow_module_loader_1.getWorkflowModuleIfAvailable)()?.inWorkflowContext;
|
|
9
|
+
if (inWorkflowContext?.()) {
|
|
9
10
|
// Required by opentelemetry (pretend to be a browser)
|
|
10
11
|
Object.assign(globalThis, {
|
|
11
12
|
performance: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/workflow/runtime.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/workflow/runtime.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,qEAAwE;AAExE,MAAM,iBAAiB,GAAG,IAAA,qDAA4B,GAAE,EAAE,iBAAiB,CAAC;AAE5E,IAAI,iBAAiB,EAAE,EAAE,EAAE,CAAC;IAC1B,sDAAsD;IACtD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QACxB,WAAW,EAAE;YACX,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;YACtB,GAAG;gBACD,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;YACtC,CAAC;SACF;QACD,MAAM,EAAE,UAAU;KACnB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -2,7 +2,7 @@ import * as tracing from '@opentelemetry/sdk-trace-base';
|
|
|
2
2
|
import { ExportResult } from '@opentelemetry/core';
|
|
3
3
|
import { SerializableSpan } from './definitions';
|
|
4
4
|
export declare class SpanExporter implements tracing.SpanExporter {
|
|
5
|
-
|
|
5
|
+
constructor();
|
|
6
6
|
export(spans: tracing.ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
7
7
|
shutdown(): Promise<void>;
|
|
8
8
|
makeSerializable(span: tracing.ReadableSpan): SerializableSpan;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SpanExporter = void 0;
|
|
4
4
|
const core_1 = require("@opentelemetry/core");
|
|
5
|
-
const
|
|
5
|
+
const workflow_module_loader_1 = require("./workflow-module-loader");
|
|
6
|
+
const exporter = (0, workflow_module_loader_1.getWorkflowModuleIfAvailable)()?.proxySinks()?.exporter;
|
|
6
7
|
class SpanExporter {
|
|
7
|
-
|
|
8
|
+
constructor() {
|
|
9
|
+
(0, workflow_module_loader_1.ensureWorkflowModuleLoaded)();
|
|
10
|
+
}
|
|
8
11
|
export(spans, resultCallback) {
|
|
9
|
-
|
|
10
|
-
this.exporter = (0, workflow_imports_1.proxySinks)().exporter;
|
|
11
|
-
}
|
|
12
|
-
this.exporter.export(spans.map((span) => this.makeSerializable(span)));
|
|
12
|
+
exporter.export(spans.map((span) => this.makeSerializable(span)));
|
|
13
13
|
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
14
14
|
}
|
|
15
15
|
async shutdown() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"span-exporter.js","sourceRoot":"","sources":["../../src/workflow/span-exporter.ts"],"names":[],"mappings":";;;AACA,8CAAqE;AAErE,
|
|
1
|
+
{"version":3,"file":"span-exporter.js","sourceRoot":"","sources":["../../src/workflow/span-exporter.ts"],"names":[],"mappings":";;;AACA,8CAAqE;AAErE,qEAAoG;AAEpG,MAAM,QAAQ,GAAG,IAAA,qDAA4B,GAAE,EAAE,UAAU,EAAsB,EAAE,QAAQ,CAAC;AAE5F,MAAa,YAAY;IACvB;QACE,IAAA,mDAA0B,GAAE,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,KAA6B,EAAE,cAA8C;QACzF,QAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnE,cAAc,CAAC,EAAE,IAAI,EAAE,uBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,QAAQ;QACnB,uBAAuB;IACzB,CAAC;IAEM,gBAAgB,CAAC,IAA0B;QAChD,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;YAC/B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;YACnD,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;SACpD,CAAC;IACJ,CAAC;CACF;AAlCD,oCAkCC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with a possibly missing `@temporalio/workflow` peer dependency
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type * as WorkflowModule from '@temporalio/workflow';
|
|
6
|
+
import type { SdkFlags as SdkFlagsT } from '@temporalio/workflow/lib/flags';
|
|
7
|
+
type SdkFlags = typeof SdkFlagsT;
|
|
8
|
+
/**
|
|
9
|
+
* Returns `@temporalio/workflow` module if present.
|
|
10
|
+
* Throws if the module failed to load
|
|
11
|
+
*/
|
|
12
|
+
export declare function getWorkflowModule(): typeof WorkflowModule;
|
|
13
|
+
/**
|
|
14
|
+
* Returns if an SDK flag was set
|
|
15
|
+
*
|
|
16
|
+
* Expects to be called only after `ensureWorkflowModuleLoaded`.
|
|
17
|
+
* Will throw if `@temporalio/workflow` is not available
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasSdkFlag(flag: keyof SdkFlags): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the workflow module loaded successfully and throws if not.
|
|
22
|
+
*/
|
|
23
|
+
export declare function ensureWorkflowModuleLoaded(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the workflow module if available, or undefined if it failed to load.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getWorkflowModuleIfAvailable(): typeof WorkflowModule | undefined;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkflowModule = getWorkflowModule;
|
|
4
|
+
exports.hasSdkFlag = hasSdkFlag;
|
|
5
|
+
exports.ensureWorkflowModuleLoaded = ensureWorkflowModuleLoaded;
|
|
6
|
+
exports.getWorkflowModuleIfAvailable = getWorkflowModuleIfAvailable;
|
|
7
|
+
// @temporalio/workflow is an optional peer dependency.
|
|
8
|
+
// It can be missing as long as the user isn't attempting to construct a workflow interceptor.
|
|
9
|
+
// If we start shipping ES modules alongside CJS, we will have to reconsider
|
|
10
|
+
// this dynamic import as `import` is async for ES modules.
|
|
11
|
+
let workflowModule;
|
|
12
|
+
let workflowModuleLoadError;
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
15
|
+
workflowModule = require('@temporalio/workflow');
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
// Capture the module not found error to rethrow if the module is required
|
|
19
|
+
workflowModuleLoadError = err;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns `@temporalio/workflow` module if present.
|
|
23
|
+
* Throws if the module failed to load
|
|
24
|
+
*/
|
|
25
|
+
function getWorkflowModule() {
|
|
26
|
+
if (workflowModuleLoadError) {
|
|
27
|
+
throw workflowModuleLoadError;
|
|
28
|
+
}
|
|
29
|
+
return workflowModule;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns if an SDK flag was set
|
|
33
|
+
*
|
|
34
|
+
* Expects to be called only after `ensureWorkflowModuleLoaded`.
|
|
35
|
+
* Will throw if `@temporalio/workflow` is not available
|
|
36
|
+
*/
|
|
37
|
+
function hasSdkFlag(flag) {
|
|
38
|
+
const { SdkFlags } = require('@temporalio/workflow/lib/flags'); // eslint-disable-line @typescript-eslint/no-require-imports
|
|
39
|
+
const { getActivator } = require('@temporalio/workflow/lib/global-attributes'); // eslint-disable-line @typescript-eslint/no-require-imports
|
|
40
|
+
return getActivator().hasFlag(SdkFlags[flag]);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks if the workflow module loaded successfully and throws if not.
|
|
44
|
+
*/
|
|
45
|
+
function ensureWorkflowModuleLoaded() {
|
|
46
|
+
if (workflowModuleLoadError) {
|
|
47
|
+
throw workflowModuleLoadError;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns the workflow module if available, or undefined if it failed to load.
|
|
52
|
+
*/
|
|
53
|
+
function getWorkflowModuleIfAvailable() {
|
|
54
|
+
return workflowModule;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=workflow-module-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-module-loader.js","sourceRoot":"","sources":["../../src/workflow/workflow-module-loader.ts"],"names":[],"mappings":";;AA4BA,8CAKC;AAQD,gCAMC;AAKD,gEAIC;AAKD,oEAEC;AAtDD,uDAAuD;AACvD,8FAA8F;AAC9F,4EAA4E;AAC5E,2DAA2D;AAC3D,IAAI,cAAiD,CAAC;AACtD,IAAI,uBAAwC,CAAC;AAE7C,IAAI,CAAC;IACH,iEAAiE;IACjE,cAAc,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACnD,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,0EAA0E;IAC1E,uBAAuB,GAAG,GAAG,CAAC;AAChC,CAAC;AAED;;;GAGG;AACH,SAAgB,iBAAiB;IAC/B,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,uBAAuB,CAAC;IAChC,CAAC;IACD,OAAO,cAAe,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,IAAoB;IAC7C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,gCAAgC,CAAoD,CAAC,CAAC,4DAA4D;IAC/K,MAAM,EAAE,YAAY,EAAE,GACpB,OAAO,CAAC,4CAA4C,CAAgE,CAAC,CAAC,4DAA4D;IAEpL,OAAO,YAAY,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,SAAgB,0BAA0B;IACxC,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,uBAAuB,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,4BAA4B;IAC1C,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/interceptors-opentelemetry",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.2",
|
|
4
4
|
"description": "Temporal.io SDK interceptors bundle for tracing with opentelemetry",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
-
"scripts": {},
|
|
8
7
|
"keywords": [
|
|
9
8
|
"temporal",
|
|
10
9
|
"workflow",
|
|
@@ -20,15 +19,15 @@
|
|
|
20
19
|
"@opentelemetry/sdk-trace-base": "^1.25.1"
|
|
21
20
|
},
|
|
22
21
|
"devDependencies": {
|
|
23
|
-
"@temporalio/activity": "1.14.
|
|
24
|
-
"@temporalio/client": "1.14.
|
|
25
|
-
"@temporalio/common": "1.14.
|
|
26
|
-
"@temporalio/
|
|
27
|
-
"@temporalio/
|
|
22
|
+
"@temporalio/activity": "1.14.2",
|
|
23
|
+
"@temporalio/client": "1.14.2",
|
|
24
|
+
"@temporalio/common": "1.14.2",
|
|
25
|
+
"@temporalio/workflow": "1.14.2",
|
|
26
|
+
"@temporalio/worker": "1.14.2"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
30
|
-
"@temporalio/common": "1.14.
|
|
31
|
-
"@temporalio/workflow": "1.14.
|
|
29
|
+
"@temporalio/common": "1.14.2",
|
|
30
|
+
"@temporalio/workflow": "1.14.2"
|
|
32
31
|
},
|
|
33
32
|
"peerDependenciesMeta": {
|
|
34
33
|
"@temporalio/workflow": {
|
|
@@ -54,5 +53,5 @@
|
|
|
54
53
|
"src",
|
|
55
54
|
"lib"
|
|
56
55
|
],
|
|
57
|
-
"
|
|
58
|
-
}
|
|
56
|
+
"scripts": {}
|
|
57
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
UPDATE_ID_ATTR_KEY,
|
|
27
27
|
TERMINATE_REASON_ATTR_KEY,
|
|
28
28
|
} from '../instrumentation';
|
|
29
|
-
import { SpanName, SPAN_DELIMITER } from '../workflow
|
|
29
|
+
import { SpanName, SPAN_DELIMITER } from '../workflow';
|
|
30
30
|
|
|
31
31
|
export interface InterceptorOptions {
|
|
32
32
|
readonly tracer?: otel.Tracer;
|
package/src/worker/index.ts
CHANGED
|
@@ -18,12 +18,7 @@ import {
|
|
|
18
18
|
RUN_ID_ATTR_KEY,
|
|
19
19
|
ACTIVITY_ID_ATTR_KEY,
|
|
20
20
|
} from '../instrumentation';
|
|
21
|
-
import {
|
|
22
|
-
type OpenTelemetryWorkflowExporter,
|
|
23
|
-
type SerializableSpan,
|
|
24
|
-
SpanName,
|
|
25
|
-
SPAN_DELIMITER,
|
|
26
|
-
} from '../workflow/definitions';
|
|
21
|
+
import { type OpenTelemetryWorkflowExporter, type SerializableSpan, SpanName, SPAN_DELIMITER } from '../workflow';
|
|
27
22
|
|
|
28
23
|
export interface InterceptorOptions {
|
|
29
24
|
readonly tracer?: otel.Tracer;
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { type AsyncLocalStorage } from 'async_hooks';
|
|
2
1
|
import * as otel from '@opentelemetry/api';
|
|
2
|
+
import { ensureWorkflowModuleLoaded, getWorkflowModuleIfAvailable } from './workflow-module-loader';
|
|
3
|
+
|
|
4
|
+
const AsyncLocalStorage = getWorkflowModuleIfAvailable()?.AsyncLocalStorage;
|
|
3
5
|
|
|
4
6
|
export class ContextManager implements otel.ContextManager {
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
+
// If `@temporalio/workflow` is not available, ignore for now.
|
|
8
|
+
// When ContextManager is constructed module resolution error will be thrown.
|
|
9
|
+
protected storage = AsyncLocalStorage ? new AsyncLocalStorage<otel.Context>() : undefined;
|
|
10
|
+
|
|
11
|
+
public constructor() {
|
|
12
|
+
ensureWorkflowModuleLoaded();
|
|
13
|
+
}
|
|
7
14
|
|
|
8
15
|
active(): otel.Context {
|
|
9
|
-
return this.storage
|
|
16
|
+
return this.storage!.getStore() || otel.ROOT_CONTEXT;
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
bind<T>(context: otel.Context, target: T): T {
|
|
@@ -37,7 +44,7 @@ export class ContextManager implements otel.ContextManager {
|
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
disable(): this {
|
|
40
|
-
this.storage
|
|
47
|
+
this.storage!.disable();
|
|
41
48
|
return this;
|
|
42
49
|
}
|
|
43
50
|
|
|
@@ -48,6 +55,6 @@ export class ContextManager implements otel.ContextManager {
|
|
|
48
55
|
...args: A
|
|
49
56
|
): ReturnType<F> {
|
|
50
57
|
const cb = thisArg == null ? fn : fn.bind(thisArg);
|
|
51
|
-
return this.storage
|
|
58
|
+
return this.storage!.run(context, cb, ...args);
|
|
52
59
|
}
|
|
53
60
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
2
|
import * as tracing from '@opentelemetry/sdk-trace-base';
|
|
3
3
|
import { InstrumentationLibrary } from '@opentelemetry/core'; // eslint-disable deprecation/deprecation
|
|
4
|
-
import
|
|
4
|
+
import { Sink, Sinks } from '@temporalio/workflow';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Serializable version of the opentelemetry Span for cross isolate copying
|
package/src/workflow/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
import { ContextManager } from './context-manager';
|
|
37
37
|
import { SpanName, SPAN_DELIMITER } from './definitions';
|
|
38
38
|
import { SpanExporter } from './span-exporter';
|
|
39
|
-
import {
|
|
39
|
+
import { ensureWorkflowModuleLoaded, getWorkflowModule, hasSdkFlag } from './workflow-module-loader';
|
|
40
40
|
|
|
41
41
|
export * from './definitions';
|
|
42
42
|
|
|
@@ -67,12 +67,18 @@ function getTracer(): otel.Tracer {
|
|
|
67
67
|
export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInterceptor {
|
|
68
68
|
protected readonly tracer = getTracer();
|
|
69
69
|
|
|
70
|
+
public constructor() {
|
|
71
|
+
ensureWorkflowModuleLoaded();
|
|
72
|
+
}
|
|
73
|
+
|
|
70
74
|
public async execute(
|
|
71
75
|
input: WorkflowExecuteInput,
|
|
72
76
|
next: Next<WorkflowInboundCallsInterceptor, 'execute'>
|
|
73
77
|
): Promise<unknown> {
|
|
78
|
+
const { workflowInfo, ContinueAsNew } = getWorkflowModule();
|
|
79
|
+
|
|
74
80
|
const context = extractContextFromHeaders(input.headers);
|
|
75
|
-
if (!
|
|
81
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
76
82
|
|
|
77
83
|
return await instrument({
|
|
78
84
|
tracer: this.tracer,
|
|
@@ -88,10 +94,10 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
88
94
|
next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>
|
|
89
95
|
): Promise<void> {
|
|
90
96
|
// Tracing of inbound signals was added in v1.11.5.
|
|
91
|
-
if (!
|
|
97
|
+
if (!hasSdkFlag('OpenTelemetryInterceptorsTracesInboundSignals')) return next(input);
|
|
92
98
|
|
|
93
99
|
const context = extractContextFromHeaders(input.headers);
|
|
94
|
-
if (!
|
|
100
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
95
101
|
|
|
96
102
|
return await instrument({
|
|
97
103
|
tracer: this.tracer,
|
|
@@ -105,7 +111,7 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
105
111
|
input: UpdateInput,
|
|
106
112
|
next: Next<WorkflowInboundCallsInterceptor, 'handleUpdate'>
|
|
107
113
|
): Promise<unknown> {
|
|
108
|
-
if (!
|
|
114
|
+
if (!hasSdkFlag('OpenTelemetryInterceptorsInstrumentsAllMethods')) return next(input);
|
|
109
115
|
|
|
110
116
|
const context = extractContextFromHeaders(input.headers);
|
|
111
117
|
|
|
@@ -121,7 +127,7 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
public validateUpdate(input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'validateUpdate'>): void {
|
|
124
|
-
if (!
|
|
130
|
+
if (!hasSdkFlag('OpenTelemetryInterceptorsInstrumentsAllMethods')) return next(input);
|
|
125
131
|
|
|
126
132
|
const context = extractContextFromHeaders(input.headers);
|
|
127
133
|
instrumentSync({
|
|
@@ -139,7 +145,7 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
139
145
|
input: QueryInput,
|
|
140
146
|
next: Next<WorkflowInboundCallsInterceptor, 'handleQuery'>
|
|
141
147
|
): Promise<unknown> {
|
|
142
|
-
if (!
|
|
148
|
+
if (!hasSdkFlag('OpenTelemetryInterceptorsInstrumentsAllMethods')) return next(input);
|
|
143
149
|
|
|
144
150
|
const context = extractContextFromHeaders(input.headers);
|
|
145
151
|
|
|
@@ -162,6 +168,10 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
162
168
|
export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsInterceptor {
|
|
163
169
|
protected readonly tracer = getTracer();
|
|
164
170
|
|
|
171
|
+
public constructor() {
|
|
172
|
+
ensureWorkflowModuleLoaded();
|
|
173
|
+
}
|
|
174
|
+
|
|
165
175
|
public async scheduleActivity(
|
|
166
176
|
input: ActivityInput,
|
|
167
177
|
next: Next<WorkflowOutboundCallsInterceptor, 'scheduleActivity'>
|
|
@@ -171,7 +181,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
171
181
|
spanName: `${SpanName.ACTIVITY_START}${SPAN_DELIMITER}${input.activityType}`,
|
|
172
182
|
fn: async () => {
|
|
173
183
|
const headers = headersWithContext(input.headers);
|
|
174
|
-
if (!
|
|
184
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
175
185
|
|
|
176
186
|
return next({
|
|
177
187
|
...input,
|
|
@@ -186,14 +196,14 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
186
196
|
next: Next<WorkflowOutboundCallsInterceptor, 'scheduleLocalActivity'>
|
|
187
197
|
): Promise<unknown> {
|
|
188
198
|
// Tracing of local activities was added in v1.11.6.
|
|
189
|
-
if (!
|
|
199
|
+
if (!hasSdkFlag('OpenTelemetryInterceptorsTracesLocalActivities')) return next(input);
|
|
190
200
|
|
|
191
201
|
return await instrument({
|
|
192
202
|
tracer: this.tracer,
|
|
193
203
|
spanName: `${SpanName.ACTIVITY_START}${SPAN_DELIMITER}${input.activityType}`,
|
|
194
204
|
fn: async () => {
|
|
195
205
|
const headers = headersWithContext(input.headers);
|
|
196
|
-
if (!
|
|
206
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
197
207
|
|
|
198
208
|
return next({
|
|
199
209
|
...input,
|
|
@@ -207,7 +217,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
207
217
|
input: StartNexusOperationInput,
|
|
208
218
|
next: Next<WorkflowOutboundCallsInterceptor, 'startNexusOperation'>
|
|
209
219
|
): Promise<StartNexusOperationOutput> {
|
|
210
|
-
if (!
|
|
220
|
+
if (!hasSdkFlag('OpenTelemetryInterceptorsInstrumentsAllMethods')) return next(input);
|
|
211
221
|
|
|
212
222
|
return await instrument({
|
|
213
223
|
tracer: this.tracer,
|
|
@@ -230,7 +240,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
230
240
|
spanName: `${SpanName.CHILD_WORKFLOW_START}${SPAN_DELIMITER}${input.workflowType}`,
|
|
231
241
|
fn: async () => {
|
|
232
242
|
const headers = headersWithContext(input.headers);
|
|
233
|
-
if (!
|
|
243
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
234
244
|
|
|
235
245
|
return next({
|
|
236
246
|
...input,
|
|
@@ -244,12 +254,13 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
244
254
|
input: ContinueAsNewInput,
|
|
245
255
|
next: Next<WorkflowOutboundCallsInterceptor, 'continueAsNew'>
|
|
246
256
|
): Promise<never> {
|
|
257
|
+
const { ContinueAsNew } = getWorkflowModule();
|
|
247
258
|
return await instrument({
|
|
248
259
|
tracer: this.tracer,
|
|
249
260
|
spanName: `${SpanName.CONTINUE_AS_NEW}${SPAN_DELIMITER}${input.options.workflowType}`,
|
|
250
261
|
fn: async () => {
|
|
251
262
|
const headers = headersWithContext(input.headers);
|
|
252
|
-
if (!
|
|
263
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
253
264
|
|
|
254
265
|
return next({
|
|
255
266
|
...input,
|
|
@@ -269,7 +280,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
269
280
|
spanName: `${SpanName.WORKFLOW_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
270
281
|
fn: async () => {
|
|
271
282
|
const headers = headersWithContext(input.headers);
|
|
272
|
-
if (!
|
|
283
|
+
if (!hasSdkFlag('OpenTelemetryInterceporsAvoidsExtraYields')) await Promise.resolve();
|
|
273
284
|
|
|
274
285
|
return next({
|
|
275
286
|
...input,
|
package/src/workflow/runtime.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* Sets global variables required for importing opentelemetry in isolate
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { getWorkflowModuleIfAvailable } from './workflow-module-loader';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const inWorkflowContext = getWorkflowModuleIfAvailable()?.inWorkflowContext;
|
|
8
|
+
|
|
9
|
+
if (inWorkflowContext?.()) {
|
|
8
10
|
// Required by opentelemetry (pretend to be a browser)
|
|
9
11
|
Object.assign(globalThis, {
|
|
10
12
|
performance: {
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import * as tracing from '@opentelemetry/sdk-trace-base';
|
|
2
2
|
import { ExportResult, ExportResultCode } from '@opentelemetry/core';
|
|
3
3
|
import { OpenTelemetrySinks, SerializableSpan } from './definitions';
|
|
4
|
-
import {
|
|
4
|
+
import { ensureWorkflowModuleLoaded, getWorkflowModuleIfAvailable } from './workflow-module-loader';
|
|
5
|
+
|
|
6
|
+
const exporter = getWorkflowModuleIfAvailable()?.proxySinks<OpenTelemetrySinks>()?.exporter;
|
|
5
7
|
|
|
6
8
|
export class SpanExporter implements tracing.SpanExporter {
|
|
7
|
-
|
|
9
|
+
public constructor() {
|
|
10
|
+
ensureWorkflowModuleLoaded();
|
|
11
|
+
}
|
|
8
12
|
|
|
9
13
|
public export(spans: tracing.ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
|
|
10
|
-
|
|
11
|
-
this.exporter = proxySinks<OpenTelemetrySinks>().exporter;
|
|
12
|
-
}
|
|
13
|
-
this.exporter.export(spans.map((span) => this.makeSerializable(span)));
|
|
14
|
+
exporter!.export(spans.map((span) => this.makeSerializable(span)));
|
|
14
15
|
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for working with a possibly missing `@temporalio/workflow` peer dependency
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type * as WorkflowModule from '@temporalio/workflow';
|
|
6
|
+
import type { SdkFlags as SdkFlagsT } from '@temporalio/workflow/lib/flags';
|
|
7
|
+
|
|
8
|
+
type SdkFlags = typeof SdkFlagsT;
|
|
9
|
+
|
|
10
|
+
// @temporalio/workflow is an optional peer dependency.
|
|
11
|
+
// It can be missing as long as the user isn't attempting to construct a workflow interceptor.
|
|
12
|
+
// If we start shipping ES modules alongside CJS, we will have to reconsider
|
|
13
|
+
// this dynamic import as `import` is async for ES modules.
|
|
14
|
+
let workflowModule: typeof WorkflowModule | undefined;
|
|
15
|
+
let workflowModuleLoadError: any | undefined;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
19
|
+
workflowModule = require('@temporalio/workflow');
|
|
20
|
+
} catch (err) {
|
|
21
|
+
// Capture the module not found error to rethrow if the module is required
|
|
22
|
+
workflowModuleLoadError = err;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns `@temporalio/workflow` module if present.
|
|
27
|
+
* Throws if the module failed to load
|
|
28
|
+
*/
|
|
29
|
+
export function getWorkflowModule(): typeof WorkflowModule {
|
|
30
|
+
if (workflowModuleLoadError) {
|
|
31
|
+
throw workflowModuleLoadError;
|
|
32
|
+
}
|
|
33
|
+
return workflowModule!;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns if an SDK flag was set
|
|
38
|
+
*
|
|
39
|
+
* Expects to be called only after `ensureWorkflowModuleLoaded`.
|
|
40
|
+
* Will throw if `@temporalio/workflow` is not available
|
|
41
|
+
*/
|
|
42
|
+
export function hasSdkFlag(flag: keyof SdkFlags): boolean {
|
|
43
|
+
const { SdkFlags } = require('@temporalio/workflow/lib/flags') as typeof import('@temporalio/workflow/lib/flags'); // eslint-disable-line @typescript-eslint/no-require-imports
|
|
44
|
+
const { getActivator } =
|
|
45
|
+
require('@temporalio/workflow/lib/global-attributes') as typeof import('@temporalio/workflow/lib/global-attributes'); // eslint-disable-line @typescript-eslint/no-require-imports
|
|
46
|
+
|
|
47
|
+
return getActivator().hasFlag(SdkFlags[flag]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks if the workflow module loaded successfully and throws if not.
|
|
52
|
+
*/
|
|
53
|
+
export function ensureWorkflowModuleLoaded(): void {
|
|
54
|
+
if (workflowModuleLoadError) {
|
|
55
|
+
throw workflowModuleLoadError;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns the workflow module if available, or undefined if it failed to load.
|
|
61
|
+
*/
|
|
62
|
+
export function getWorkflowModuleIfAvailable(): typeof WorkflowModule | undefined {
|
|
63
|
+
return workflowModule;
|
|
64
|
+
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Real workflow imports for otel interceptors.
|
|
3
|
-
* This replaces the stub via webpack alias when bundled.
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
export { inWorkflowContext, proxySinks, workflowInfo, AsyncLocalStorage, ContinueAsNew } from '@temporalio/workflow';
|
|
8
|
-
export { SdkFlags } from '@temporalio/workflow/lib/flags';
|
|
9
|
-
export { getActivator } from '@temporalio/workflow/lib/global-attributes';
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getActivator = exports.SdkFlags = exports.ContinueAsNew = exports.AsyncLocalStorage = exports.workflowInfo = exports.proxySinks = exports.inWorkflowContext = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Real workflow imports for otel interceptors.
|
|
6
|
-
* This replaces the stub via webpack alias when bundled.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
var workflow_1 = require("@temporalio/workflow");
|
|
11
|
-
Object.defineProperty(exports, "inWorkflowContext", { enumerable: true, get: function () { return workflow_1.inWorkflowContext; } });
|
|
12
|
-
Object.defineProperty(exports, "proxySinks", { enumerable: true, get: function () { return workflow_1.proxySinks; } });
|
|
13
|
-
Object.defineProperty(exports, "workflowInfo", { enumerable: true, get: function () { return workflow_1.workflowInfo; } });
|
|
14
|
-
Object.defineProperty(exports, "AsyncLocalStorage", { enumerable: true, get: function () { return workflow_1.AsyncLocalStorage; } });
|
|
15
|
-
Object.defineProperty(exports, "ContinueAsNew", { enumerable: true, get: function () { return workflow_1.ContinueAsNew; } });
|
|
16
|
-
var flags_1 = require("@temporalio/workflow/lib/flags");
|
|
17
|
-
Object.defineProperty(exports, "SdkFlags", { enumerable: true, get: function () { return flags_1.SdkFlags; } });
|
|
18
|
-
var global_attributes_1 = require("@temporalio/workflow/lib/global-attributes");
|
|
19
|
-
Object.defineProperty(exports, "getActivator", { enumerable: true, get: function () { return global_attributes_1.getActivator; } });
|
|
20
|
-
//# sourceMappingURL=workflow-imports-impl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-imports-impl.js","sourceRoot":"","sources":["../../src/workflow/workflow-imports-impl.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,iDAAqH;AAA5G,6GAAA,iBAAiB,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,yGAAA,aAAa,OAAA;AACtF,wDAA0D;AAAjD,iGAAA,QAAQ,OAAA;AACjB,gFAA0E;AAAjE,iHAAA,YAAY,OAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow imports stub module.
|
|
3
|
-
*
|
|
4
|
-
* This module provides stubs for workflow functionality needed by interceptors.
|
|
5
|
-
* When bundled by the workflow bundler, this is replaced with the real
|
|
6
|
-
* implementation via NormalModuleReplacementPlugin.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import type { inWorkflowContext as inWorkflowContextT, workflowInfo as workflowInfoT, proxySinks as proxySinksT, AsyncLocalStorage as AsyncLocalStorageT, ContinueAsNew as ContinueAsNewT } from '@temporalio/workflow';
|
|
11
|
-
import type { getActivator as getActivatorT } from '@temporalio/workflow/lib/global-attributes';
|
|
12
|
-
import type { SdkFlags as SdkFlagsT } from '@temporalio/workflow/lib/flags';
|
|
13
|
-
export declare const inWorkflowContext: typeof inWorkflowContextT;
|
|
14
|
-
export declare const workflowInfo: typeof workflowInfoT;
|
|
15
|
-
export declare const ContinueAsNew: typeof ContinueAsNewT;
|
|
16
|
-
export declare const AsyncLocalStorage: typeof AsyncLocalStorageT;
|
|
17
|
-
export declare const getActivator: typeof getActivatorT;
|
|
18
|
-
export declare const proxySinks: typeof proxySinksT;
|
|
19
|
-
export declare const SdkFlags: typeof SdkFlagsT;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SdkFlags = exports.proxySinks = exports.getActivator = exports.AsyncLocalStorage = exports.ContinueAsNew = exports.workflowInfo = exports.inWorkflowContext = void 0;
|
|
4
|
-
const common_1 = require("@temporalio/common");
|
|
5
|
-
// always returns false since if using this implementation, we are outside of workflow context
|
|
6
|
-
const inWorkflowContext = () => false;
|
|
7
|
-
exports.inWorkflowContext = inWorkflowContext;
|
|
8
|
-
// All of the following stubs will throw if used
|
|
9
|
-
const workflowInfo = () => {
|
|
10
|
-
throw new common_1.IllegalStateError('Workflow.workflowInfo(...) may only be used from a Workflow Execution.');
|
|
11
|
-
};
|
|
12
|
-
exports.workflowInfo = workflowInfo;
|
|
13
|
-
exports.ContinueAsNew = class ContinueAsNew {
|
|
14
|
-
};
|
|
15
|
-
exports.AsyncLocalStorage = class AsyncLocalStorage {
|
|
16
|
-
};
|
|
17
|
-
const getActivator = () => {
|
|
18
|
-
throw new common_1.IllegalStateError('Workflow uninitialized');
|
|
19
|
-
};
|
|
20
|
-
exports.getActivator = getActivator;
|
|
21
|
-
const proxySinks = () => {
|
|
22
|
-
throw new common_1.IllegalStateError('Proxied sinks functions may only be used from a Workflow Execution.');
|
|
23
|
-
};
|
|
24
|
-
exports.proxySinks = proxySinks;
|
|
25
|
-
exports.SdkFlags = {};
|
|
26
|
-
//# sourceMappingURL=workflow-imports.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-imports.js","sourceRoot":"","sources":["../../src/workflow/workflow-imports.ts"],"names":[],"mappings":";;;AAmBA,+CAAuD;AAEvD,8FAA8F;AACvF,MAAM,iBAAiB,GAA8B,GAAG,EAAE,CAAC,KAAK,CAAC;AAA3D,QAAA,iBAAiB,qBAA0C;AAExE,gDAAgD;AACzC,MAAM,YAAY,GAAyB,GAAG,EAAE;IACrD,MAAM,IAAI,0BAAiB,CAAC,wEAAwE,CAAC,CAAC;AACxG,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEW,QAAA,aAAa,GAAG,MAAM,aAAa;CAAuC,CAAC;AAE3E,QAAA,iBAAiB,GAAG,MAAM,iBAAiB;CAA2C,CAAC;AAE7F,MAAM,YAAY,GAAyB,GAAG,EAAE;IACrD,MAAM,IAAI,0BAAiB,CAAC,wBAAwB,CAAC,CAAC;AACxD,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEK,MAAM,UAAU,GAAuB,GAAG,EAAE;IACjD,MAAM,IAAI,0BAAiB,CAAC,qEAAqE,CAAC,CAAC;AACrG,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEW,QAAA,QAAQ,GAAqB,EAAsB,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Real workflow imports for otel interceptors.
|
|
3
|
-
* This replaces the stub via webpack alias when bundled.
|
|
4
|
-
*
|
|
5
|
-
* @module
|
|
6
|
-
*/
|
|
7
|
-
export { inWorkflowContext, proxySinks, workflowInfo, AsyncLocalStorage, ContinueAsNew } from '@temporalio/workflow';
|
|
8
|
-
export { SdkFlags } from '@temporalio/workflow/lib/flags';
|
|
9
|
-
export { getActivator } from '@temporalio/workflow/lib/global-attributes';
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow imports stub module.
|
|
3
|
-
*
|
|
4
|
-
* This module provides stubs for workflow functionality needed by interceptors.
|
|
5
|
-
* When bundled by the workflow bundler, this is replaced with the real
|
|
6
|
-
* implementation via NormalModuleReplacementPlugin.
|
|
7
|
-
*
|
|
8
|
-
* @module
|
|
9
|
-
*/
|
|
10
|
-
import type {
|
|
11
|
-
inWorkflowContext as inWorkflowContextT,
|
|
12
|
-
workflowInfo as workflowInfoT,
|
|
13
|
-
proxySinks as proxySinksT,
|
|
14
|
-
AsyncLocalStorage as AsyncLocalStorageT,
|
|
15
|
-
ContinueAsNew as ContinueAsNewT,
|
|
16
|
-
} from '@temporalio/workflow';
|
|
17
|
-
import type { getActivator as getActivatorT } from '@temporalio/workflow/lib/global-attributes';
|
|
18
|
-
import type { SdkFlags as SdkFlagsT } from '@temporalio/workflow/lib/flags';
|
|
19
|
-
|
|
20
|
-
import { IllegalStateError } from '@temporalio/common';
|
|
21
|
-
|
|
22
|
-
// always returns false since if using this implementation, we are outside of workflow context
|
|
23
|
-
export const inWorkflowContext: typeof inWorkflowContextT = () => false;
|
|
24
|
-
|
|
25
|
-
// All of the following stubs will throw if used
|
|
26
|
-
export const workflowInfo: typeof workflowInfoT = () => {
|
|
27
|
-
throw new IllegalStateError('Workflow.workflowInfo(...) may only be used from a Workflow Execution.');
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const ContinueAsNew = class ContinueAsNew {} as unknown as typeof ContinueAsNewT;
|
|
31
|
-
|
|
32
|
-
export const AsyncLocalStorage = class AsyncLocalStorage {} as unknown as typeof AsyncLocalStorageT;
|
|
33
|
-
|
|
34
|
-
export const getActivator: typeof getActivatorT = () => {
|
|
35
|
-
throw new IllegalStateError('Workflow uninitialized');
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const proxySinks: typeof proxySinksT = () => {
|
|
39
|
-
throw new IllegalStateError('Proxied sinks functions may only be used from a Workflow Execution.');
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const SdkFlags: typeof SdkFlagsT = {} as typeof SdkFlagsT;
|