@temporalio/interceptors-opentelemetry 1.13.2 → 1.14.1
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/{LICENSE.md → LICENSE} +6 -8
- package/lib/client/index.d.ts +9 -1
- package/lib/client/index.js +125 -6
- package/lib/client/index.js.map +1 -1
- package/lib/instrumentation.d.ts +18 -0
- package/lib/instrumentation.js +50 -10
- package/lib/instrumentation.js.map +1 -1
- package/lib/worker/index.d.ts +5 -4
- package/lib/worker/index.js +30 -5
- package/lib/worker/index.js.map +1 -1
- package/lib/workflow/context-manager.d.ts +2 -2
- package/lib/workflow/context-manager.js +2 -8
- package/lib/workflow/context-manager.js.map +1 -1
- package/lib/workflow/definitions.d.ts +46 -2
- package/lib/workflow/definitions.js +44 -0
- package/lib/workflow/definitions.js.map +1 -1
- package/lib/workflow/index.d.ts +6 -3
- package/lib/workflow/index.js +82 -22
- package/lib/workflow/index.js.map +1 -1
- package/lib/workflow/runtime.js +2 -3
- 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-imports-impl.d.ts +9 -0
- package/lib/workflow/workflow-imports-impl.js +20 -0
- package/lib/workflow/workflow-imports-impl.js.map +1 -0
- package/lib/workflow/workflow-imports.d.ts +19 -0
- package/lib/workflow/workflow-imports.js +26 -0
- package/lib/workflow/workflow-imports.js.map +1 -0
- package/package.json +13 -13
- package/src/client/index.ts +179 -6
- package/src/instrumentation.ts +54 -8
- package/src/worker/index.ts +45 -5
- package/src/workflow/context-manager.ts +6 -13
- package/src/workflow/definitions.ts +55 -1
- package/src/workflow/index.ts +112 -23
- package/src/workflow/runtime.ts +2 -4
- package/src/workflow/span-exporter.ts +6 -7
- package/src/workflow/workflow-imports-impl.ts +9 -0
- package/src/workflow/workflow-imports.ts +42 -0
- package/lib/workflow/workflow-module-loader.d.ts +0 -28
- package/lib/workflow/workflow-module-loader.js +0 -56
- package/lib/workflow/workflow-module-loader.js.map +0 -1
- package/src/workflow/workflow-module-loader.ts +0 -64
package/src/workflow/index.ts
CHANGED
|
@@ -8,21 +8,35 @@ import type {
|
|
|
8
8
|
ContinueAsNewInput,
|
|
9
9
|
DisposeInput,
|
|
10
10
|
GetLogAttributesInput,
|
|
11
|
+
GetMetricTagsInput,
|
|
11
12
|
LocalActivityInput,
|
|
12
13
|
Next,
|
|
14
|
+
QueryInput,
|
|
13
15
|
SignalInput,
|
|
14
16
|
SignalWorkflowInput,
|
|
15
17
|
StartChildWorkflowExecutionInput,
|
|
18
|
+
UpdateInput,
|
|
16
19
|
WorkflowExecuteInput,
|
|
17
20
|
WorkflowInboundCallsInterceptor,
|
|
18
21
|
WorkflowInternalsInterceptor,
|
|
19
22
|
WorkflowOutboundCallsInterceptor,
|
|
23
|
+
StartNexusOperationInput,
|
|
24
|
+
StartNexusOperationOutput,
|
|
20
25
|
} from '@temporalio/workflow';
|
|
21
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
instrument,
|
|
28
|
+
instrumentSync,
|
|
29
|
+
extractContextFromHeaders,
|
|
30
|
+
headersWithContext,
|
|
31
|
+
UPDATE_ID_ATTR_KEY,
|
|
32
|
+
NEXUS_SERVICE_ATTR_KEY,
|
|
33
|
+
NEXUS_OPERATION_ATTR_KEY,
|
|
34
|
+
NEXUS_ENDPOINT_ATTR_KEY,
|
|
35
|
+
} from '../instrumentation';
|
|
22
36
|
import { ContextManager } from './context-manager';
|
|
23
37
|
import { SpanName, SPAN_DELIMITER } from './definitions';
|
|
24
38
|
import { SpanExporter } from './span-exporter';
|
|
25
|
-
import {
|
|
39
|
+
import { workflowInfo, ContinueAsNew, getActivator, SdkFlags } from './workflow-imports';
|
|
26
40
|
|
|
27
41
|
export * from './definitions';
|
|
28
42
|
|
|
@@ -53,18 +67,12 @@ function getTracer(): otel.Tracer {
|
|
|
53
67
|
export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInterceptor {
|
|
54
68
|
protected readonly tracer = getTracer();
|
|
55
69
|
|
|
56
|
-
public constructor() {
|
|
57
|
-
ensureWorkflowModuleLoaded();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
70
|
public async execute(
|
|
61
71
|
input: WorkflowExecuteInput,
|
|
62
72
|
next: Next<WorkflowInboundCallsInterceptor, 'execute'>
|
|
63
73
|
): Promise<unknown> {
|
|
64
|
-
const { workflowInfo, ContinueAsNew } = getWorkflowModule();
|
|
65
|
-
|
|
66
74
|
const context = extractContextFromHeaders(input.headers);
|
|
67
|
-
if (!
|
|
75
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
68
76
|
|
|
69
77
|
return await instrument({
|
|
70
78
|
tracer: this.tracer,
|
|
@@ -80,14 +88,64 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
80
88
|
next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>
|
|
81
89
|
): Promise<void> {
|
|
82
90
|
// Tracing of inbound signals was added in v1.11.5.
|
|
83
|
-
if (!
|
|
91
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsTracesInboundSignals)) return next(input);
|
|
84
92
|
|
|
85
93
|
const context = extractContextFromHeaders(input.headers);
|
|
86
|
-
if (!
|
|
94
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
87
95
|
|
|
88
96
|
return await instrument({
|
|
89
97
|
tracer: this.tracer,
|
|
90
|
-
spanName: `${SpanName.
|
|
98
|
+
spanName: `${SpanName.WORKFLOW_HANDLE_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
99
|
+
fn: () => next(input),
|
|
100
|
+
context,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public async handleUpdate(
|
|
105
|
+
input: UpdateInput,
|
|
106
|
+
next: Next<WorkflowInboundCallsInterceptor, 'handleUpdate'>
|
|
107
|
+
): Promise<unknown> {
|
|
108
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
109
|
+
|
|
110
|
+
const context = extractContextFromHeaders(input.headers);
|
|
111
|
+
|
|
112
|
+
return await instrument({
|
|
113
|
+
tracer: this.tracer,
|
|
114
|
+
spanName: `${SpanName.WORKFLOW_HANDLE_UPDATE}${SPAN_DELIMITER}${input.name}`,
|
|
115
|
+
fn: (span) => {
|
|
116
|
+
span.setAttribute(UPDATE_ID_ATTR_KEY, input.updateId);
|
|
117
|
+
return next(input);
|
|
118
|
+
},
|
|
119
|
+
context,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public validateUpdate(input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'validateUpdate'>): void {
|
|
124
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
125
|
+
|
|
126
|
+
const context = extractContextFromHeaders(input.headers);
|
|
127
|
+
instrumentSync({
|
|
128
|
+
tracer: this.tracer,
|
|
129
|
+
spanName: `${SpanName.WORKFLOW_VALIDATE_UPDATE}${SPAN_DELIMITER}${input.name}`,
|
|
130
|
+
fn: (span) => {
|
|
131
|
+
span.setAttribute(UPDATE_ID_ATTR_KEY, input.updateId);
|
|
132
|
+
return next(input);
|
|
133
|
+
},
|
|
134
|
+
context,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public async handleQuery(
|
|
139
|
+
input: QueryInput,
|
|
140
|
+
next: Next<WorkflowInboundCallsInterceptor, 'handleQuery'>
|
|
141
|
+
): Promise<unknown> {
|
|
142
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
143
|
+
|
|
144
|
+
const context = extractContextFromHeaders(input.headers);
|
|
145
|
+
|
|
146
|
+
return await instrument({
|
|
147
|
+
tracer: this.tracer,
|
|
148
|
+
spanName: `${SpanName.WORKFLOW_HANDLE_QUERY}${SPAN_DELIMITER}${input.queryName}`,
|
|
91
149
|
fn: () => next(input),
|
|
92
150
|
context,
|
|
93
151
|
});
|
|
@@ -104,10 +162,6 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
104
162
|
export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsInterceptor {
|
|
105
163
|
protected readonly tracer = getTracer();
|
|
106
164
|
|
|
107
|
-
public constructor() {
|
|
108
|
-
ensureWorkflowModuleLoaded();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
165
|
public async scheduleActivity(
|
|
112
166
|
input: ActivityInput,
|
|
113
167
|
next: Next<WorkflowOutboundCallsInterceptor, 'scheduleActivity'>
|
|
@@ -117,7 +171,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
117
171
|
spanName: `${SpanName.ACTIVITY_START}${SPAN_DELIMITER}${input.activityType}`,
|
|
118
172
|
fn: async () => {
|
|
119
173
|
const headers = headersWithContext(input.headers);
|
|
120
|
-
if (!
|
|
174
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
121
175
|
|
|
122
176
|
return next({
|
|
123
177
|
...input,
|
|
@@ -132,14 +186,14 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
132
186
|
next: Next<WorkflowOutboundCallsInterceptor, 'scheduleLocalActivity'>
|
|
133
187
|
): Promise<unknown> {
|
|
134
188
|
// Tracing of local activities was added in v1.11.6.
|
|
135
|
-
if (!
|
|
189
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsTracesLocalActivities)) return next(input);
|
|
136
190
|
|
|
137
191
|
return await instrument({
|
|
138
192
|
tracer: this.tracer,
|
|
139
193
|
spanName: `${SpanName.ACTIVITY_START}${SPAN_DELIMITER}${input.activityType}`,
|
|
140
194
|
fn: async () => {
|
|
141
195
|
const headers = headersWithContext(input.headers);
|
|
142
|
-
if (!
|
|
196
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
143
197
|
|
|
144
198
|
return next({
|
|
145
199
|
...input,
|
|
@@ -149,6 +203,24 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
149
203
|
});
|
|
150
204
|
}
|
|
151
205
|
|
|
206
|
+
public async startNexusOperation(
|
|
207
|
+
input: StartNexusOperationInput,
|
|
208
|
+
next: Next<WorkflowOutboundCallsInterceptor, 'startNexusOperation'>
|
|
209
|
+
): Promise<StartNexusOperationOutput> {
|
|
210
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
211
|
+
|
|
212
|
+
return await instrument({
|
|
213
|
+
tracer: this.tracer,
|
|
214
|
+
spanName: `${SpanName.NEXUS_OPERATION_START}${SPAN_DELIMITER}${input.service}${SPAN_DELIMITER}${input.operation}`,
|
|
215
|
+
fn: async (span) => {
|
|
216
|
+
span.setAttribute(NEXUS_SERVICE_ATTR_KEY, input.service);
|
|
217
|
+
span.setAttribute(NEXUS_OPERATION_ATTR_KEY, input.operation);
|
|
218
|
+
span.setAttribute(NEXUS_ENDPOINT_ATTR_KEY, input.endpoint);
|
|
219
|
+
return await next(input);
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
152
224
|
public async startChildWorkflowExecution(
|
|
153
225
|
input: StartChildWorkflowExecutionInput,
|
|
154
226
|
next: Next<WorkflowOutboundCallsInterceptor, 'startChildWorkflowExecution'>
|
|
@@ -158,7 +230,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
158
230
|
spanName: `${SpanName.CHILD_WORKFLOW_START}${SPAN_DELIMITER}${input.workflowType}`,
|
|
159
231
|
fn: async () => {
|
|
160
232
|
const headers = headersWithContext(input.headers);
|
|
161
|
-
if (!
|
|
233
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
162
234
|
|
|
163
235
|
return next({
|
|
164
236
|
...input,
|
|
@@ -172,13 +244,12 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
172
244
|
input: ContinueAsNewInput,
|
|
173
245
|
next: Next<WorkflowOutboundCallsInterceptor, 'continueAsNew'>
|
|
174
246
|
): Promise<never> {
|
|
175
|
-
const { ContinueAsNew } = getWorkflowModule();
|
|
176
247
|
return await instrument({
|
|
177
248
|
tracer: this.tracer,
|
|
178
249
|
spanName: `${SpanName.CONTINUE_AS_NEW}${SPAN_DELIMITER}${input.options.workflowType}`,
|
|
179
250
|
fn: async () => {
|
|
180
251
|
const headers = headersWithContext(input.headers);
|
|
181
|
-
if (!
|
|
252
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
182
253
|
|
|
183
254
|
return next({
|
|
184
255
|
...input,
|
|
@@ -198,7 +269,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
198
269
|
spanName: `${SpanName.WORKFLOW_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
199
270
|
fn: async () => {
|
|
200
271
|
const headers = headersWithContext(input.headers);
|
|
201
|
-
if (!
|
|
272
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
202
273
|
|
|
203
274
|
return next({
|
|
204
275
|
...input,
|
|
@@ -225,6 +296,24 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
225
296
|
return next(input);
|
|
226
297
|
}
|
|
227
298
|
}
|
|
299
|
+
|
|
300
|
+
public getMetricTags(
|
|
301
|
+
input: GetMetricTagsInput,
|
|
302
|
+
next: Next<WorkflowOutboundCallsInterceptor, 'getMetricTags'>
|
|
303
|
+
): GetMetricTagsInput {
|
|
304
|
+
const span = otel.trace.getSpan(otel.context.active());
|
|
305
|
+
const spanContext = span?.spanContext();
|
|
306
|
+
if (spanContext && otel.isSpanContextValid(spanContext)) {
|
|
307
|
+
return next({
|
|
308
|
+
trace_id: spanContext.traceId,
|
|
309
|
+
span_id: spanContext.spanId,
|
|
310
|
+
trace_flags: `0${spanContext.traceFlags.toString(16)}`,
|
|
311
|
+
...input,
|
|
312
|
+
});
|
|
313
|
+
} else {
|
|
314
|
+
return next(input);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
228
317
|
}
|
|
229
318
|
|
|
230
319
|
export class OpenTelemetryInternalsInterceptor implements WorkflowInternalsInterceptor {
|
package/src/workflow/runtime.ts
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* Sets global variables required for importing opentelemetry in isolate
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { inWorkflowContext } from './workflow-imports';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (inWorkflowContext?.()) {
|
|
7
|
+
if (inWorkflowContext()) {
|
|
10
8
|
// Required by opentelemetry (pretend to be a browser)
|
|
11
9
|
Object.assign(globalThis, {
|
|
12
10
|
performance: {
|
|
@@ -1,17 +1,16 @@
|
|
|
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 {
|
|
5
|
-
|
|
6
|
-
const exporter = getWorkflowModuleIfAvailable()?.proxySinks<OpenTelemetrySinks>()?.exporter;
|
|
4
|
+
import { proxySinks } from './workflow-imports';
|
|
7
5
|
|
|
8
6
|
export class SpanExporter implements tracing.SpanExporter {
|
|
9
|
-
|
|
10
|
-
ensureWorkflowModuleLoaded();
|
|
11
|
-
}
|
|
7
|
+
private exporter?: OpenTelemetrySinks['exporter'];
|
|
12
8
|
|
|
13
9
|
public export(spans: tracing.ReadableSpan[], resultCallback: (result: ExportResult) => void): void {
|
|
14
|
-
|
|
10
|
+
if (!this.exporter) {
|
|
11
|
+
this.exporter = proxySinks<OpenTelemetrySinks>().exporter;
|
|
12
|
+
}
|
|
13
|
+
this.exporter.export(spans.map((span) => this.makeSerializable(span)));
|
|
15
14
|
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -0,0 +1,9 @@
|
|
|
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';
|
|
@@ -0,0 +1,42 @@
|
|
|
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;
|
|
@@ -1,28 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,56 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
}
|