@temporalio/interceptors-opentelemetry 1.14.2 → 1.15.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/lib/client/index.js +11 -11
- package/lib/client/index.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/plugin.d.ts +31 -0
- package/lib/plugin.js +60 -0
- package/lib/plugin.js.map +1 -0
- package/lib/worker/index.d.ts +11 -3
- package/lib/worker/index.js +21 -9
- package/lib/worker/index.js.map +1 -1
- package/lib/workflow/context-manager.d.ts +2 -2
- package/lib/workflow/context-manager.js +2 -9
- package/lib/workflow/context-manager.js.map +1 -1
- package/lib/workflow/definitions.d.ts +8 -2
- package/lib/workflow/definitions.js.map +1 -1
- package/lib/workflow/index.d.ts +0 -2
- package/lib/workflow/index.js +17 -26
- 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 +15 -7
- 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/lib/workflow-interceptors.d.ts +3 -0
- package/lib/workflow-interceptors.js +12 -0
- package/lib/workflow-interceptors.js.map +1 -0
- package/package.json +11 -10
- package/src/client/index.ts +1 -1
- package/src/index.ts +1 -0
- package/src/plugin.ts +77 -0
- package/src/worker/index.ts +46 -6
- package/src/workflow/context-manager.ts +7 -14
- package/src/workflow/definitions.ts +9 -4
- package/src/workflow/index.ts +14 -26
- package/src/workflow/runtime.ts +2 -4
- package/src/workflow/span-exporter.ts +16 -9
- package/src/workflow/workflow-imports-impl.ts +9 -0
- package/src/workflow/workflow-imports.ts +42 -0
- package/src/workflow-interceptors.ts +14 -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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable import/order */
|
|
2
1
|
// eslint-disable-next-line import/no-unassigned-import
|
|
3
2
|
import './runtime'; // Patch the Workflow isolate runtime for opentelemetry
|
|
4
3
|
import * as otel from '@opentelemetry/api';
|
|
@@ -36,7 +35,7 @@ import {
|
|
|
36
35
|
import { ContextManager } from './context-manager';
|
|
37
36
|
import { SpanName, SPAN_DELIMITER } from './definitions';
|
|
38
37
|
import { SpanExporter } from './span-exporter';
|
|
39
|
-
import {
|
|
38
|
+
import { workflowInfo, ContinueAsNew, getActivator, SdkFlags } from './workflow-imports';
|
|
40
39
|
|
|
41
40
|
export * from './definitions';
|
|
42
41
|
|
|
@@ -67,18 +66,12 @@ function getTracer(): otel.Tracer {
|
|
|
67
66
|
export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInterceptor {
|
|
68
67
|
protected readonly tracer = getTracer();
|
|
69
68
|
|
|
70
|
-
public constructor() {
|
|
71
|
-
ensureWorkflowModuleLoaded();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
69
|
public async execute(
|
|
75
70
|
input: WorkflowExecuteInput,
|
|
76
71
|
next: Next<WorkflowInboundCallsInterceptor, 'execute'>
|
|
77
72
|
): Promise<unknown> {
|
|
78
|
-
const { workflowInfo, ContinueAsNew } = getWorkflowModule();
|
|
79
|
-
|
|
80
73
|
const context = extractContextFromHeaders(input.headers);
|
|
81
|
-
if (!
|
|
74
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
82
75
|
|
|
83
76
|
return await instrument({
|
|
84
77
|
tracer: this.tracer,
|
|
@@ -94,10 +87,10 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
94
87
|
next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>
|
|
95
88
|
): Promise<void> {
|
|
96
89
|
// Tracing of inbound signals was added in v1.11.5.
|
|
97
|
-
if (!
|
|
90
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsTracesInboundSignals)) return next(input);
|
|
98
91
|
|
|
99
92
|
const context = extractContextFromHeaders(input.headers);
|
|
100
|
-
if (!
|
|
93
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
101
94
|
|
|
102
95
|
return await instrument({
|
|
103
96
|
tracer: this.tracer,
|
|
@@ -111,7 +104,7 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
111
104
|
input: UpdateInput,
|
|
112
105
|
next: Next<WorkflowInboundCallsInterceptor, 'handleUpdate'>
|
|
113
106
|
): Promise<unknown> {
|
|
114
|
-
if (!
|
|
107
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
115
108
|
|
|
116
109
|
const context = extractContextFromHeaders(input.headers);
|
|
117
110
|
|
|
@@ -127,7 +120,7 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
127
120
|
}
|
|
128
121
|
|
|
129
122
|
public validateUpdate(input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'validateUpdate'>): void {
|
|
130
|
-
if (!
|
|
123
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
131
124
|
|
|
132
125
|
const context = extractContextFromHeaders(input.headers);
|
|
133
126
|
instrumentSync({
|
|
@@ -145,7 +138,7 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
145
138
|
input: QueryInput,
|
|
146
139
|
next: Next<WorkflowInboundCallsInterceptor, 'handleQuery'>
|
|
147
140
|
): Promise<unknown> {
|
|
148
|
-
if (!
|
|
141
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
149
142
|
|
|
150
143
|
const context = extractContextFromHeaders(input.headers);
|
|
151
144
|
|
|
@@ -168,10 +161,6 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
168
161
|
export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsInterceptor {
|
|
169
162
|
protected readonly tracer = getTracer();
|
|
170
163
|
|
|
171
|
-
public constructor() {
|
|
172
|
-
ensureWorkflowModuleLoaded();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
164
|
public async scheduleActivity(
|
|
176
165
|
input: ActivityInput,
|
|
177
166
|
next: Next<WorkflowOutboundCallsInterceptor, 'scheduleActivity'>
|
|
@@ -181,7 +170,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
181
170
|
spanName: `${SpanName.ACTIVITY_START}${SPAN_DELIMITER}${input.activityType}`,
|
|
182
171
|
fn: async () => {
|
|
183
172
|
const headers = headersWithContext(input.headers);
|
|
184
|
-
if (!
|
|
173
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
185
174
|
|
|
186
175
|
return next({
|
|
187
176
|
...input,
|
|
@@ -196,14 +185,14 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
196
185
|
next: Next<WorkflowOutboundCallsInterceptor, 'scheduleLocalActivity'>
|
|
197
186
|
): Promise<unknown> {
|
|
198
187
|
// Tracing of local activities was added in v1.11.6.
|
|
199
|
-
if (!
|
|
188
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsTracesLocalActivities)) return next(input);
|
|
200
189
|
|
|
201
190
|
return await instrument({
|
|
202
191
|
tracer: this.tracer,
|
|
203
192
|
spanName: `${SpanName.ACTIVITY_START}${SPAN_DELIMITER}${input.activityType}`,
|
|
204
193
|
fn: async () => {
|
|
205
194
|
const headers = headersWithContext(input.headers);
|
|
206
|
-
if (!
|
|
195
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
207
196
|
|
|
208
197
|
return next({
|
|
209
198
|
...input,
|
|
@@ -217,7 +206,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
217
206
|
input: StartNexusOperationInput,
|
|
218
207
|
next: Next<WorkflowOutboundCallsInterceptor, 'startNexusOperation'>
|
|
219
208
|
): Promise<StartNexusOperationOutput> {
|
|
220
|
-
if (!
|
|
209
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceptorsInstrumentsAllMethods)) return next(input);
|
|
221
210
|
|
|
222
211
|
return await instrument({
|
|
223
212
|
tracer: this.tracer,
|
|
@@ -240,7 +229,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
240
229
|
spanName: `${SpanName.CHILD_WORKFLOW_START}${SPAN_DELIMITER}${input.workflowType}`,
|
|
241
230
|
fn: async () => {
|
|
242
231
|
const headers = headersWithContext(input.headers);
|
|
243
|
-
if (!
|
|
232
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
244
233
|
|
|
245
234
|
return next({
|
|
246
235
|
...input,
|
|
@@ -254,13 +243,12 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
254
243
|
input: ContinueAsNewInput,
|
|
255
244
|
next: Next<WorkflowOutboundCallsInterceptor, 'continueAsNew'>
|
|
256
245
|
): Promise<never> {
|
|
257
|
-
const { ContinueAsNew } = getWorkflowModule();
|
|
258
246
|
return await instrument({
|
|
259
247
|
tracer: this.tracer,
|
|
260
248
|
spanName: `${SpanName.CONTINUE_AS_NEW}${SPAN_DELIMITER}${input.options.workflowType}`,
|
|
261
249
|
fn: async () => {
|
|
262
250
|
const headers = headersWithContext(input.headers);
|
|
263
|
-
if (!
|
|
251
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
264
252
|
|
|
265
253
|
return next({
|
|
266
254
|
...input,
|
|
@@ -280,7 +268,7 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
280
268
|
spanName: `${SpanName.WORKFLOW_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
281
269
|
fn: async () => {
|
|
282
270
|
const headers = headersWithContext(input.headers);
|
|
283
|
-
if (!
|
|
271
|
+
if (!getActivator().hasFlag(SdkFlags.OpenTelemetryInterceporsAvoidsExtraYields)) await Promise.resolve();
|
|
284
272
|
|
|
285
273
|
return next({
|
|
286
274
|
...input,
|
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
|
-
import { OpenTelemetrySinks, SerializableSpan } from './definitions';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const exporter = getWorkflowModuleIfAvailable()?.proxySinks<OpenTelemetrySinks>()?.exporter;
|
|
3
|
+
import { OpenTelemetrySinks, SerializableSpan, SerializableSpanContext } from './definitions';
|
|
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
|
|
|
@@ -20,10 +19,18 @@ export class SpanExporter implements tracing.SpanExporter {
|
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
public makeSerializable(span: tracing.ReadableSpan): SerializableSpan {
|
|
22
|
+
const { traceState, ...restSpanContext } = span.spanContext();
|
|
23
|
+
// Serialize traceState to a string because TraceState objects lose their
|
|
24
|
+
// prototype methods when crossing the V8 isolate boundary.
|
|
25
|
+
// See: https://github.com/temporalio/sdk-typescript/issues/1738
|
|
26
|
+
const serializableSpanContext: SerializableSpanContext = {
|
|
27
|
+
traceState: traceState?.serialize(),
|
|
28
|
+
...restSpanContext,
|
|
29
|
+
};
|
|
23
30
|
return {
|
|
24
31
|
name: span.name,
|
|
25
32
|
kind: span.kind,
|
|
26
|
-
spanContext:
|
|
33
|
+
spanContext: serializableSpanContext,
|
|
27
34
|
parentSpanId: span.parentSpanId,
|
|
28
35
|
startTime: span.startTime,
|
|
29
36
|
endTime: span.endTime,
|
|
@@ -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;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Not a workflow, just interceptors */
|
|
2
|
+
|
|
3
|
+
import type { WorkflowInterceptors } from '@temporalio/workflow';
|
|
4
|
+
import {
|
|
5
|
+
OpenTelemetryInboundInterceptor,
|
|
6
|
+
OpenTelemetryOutboundInterceptor,
|
|
7
|
+
OpenTelemetryInternalsInterceptor,
|
|
8
|
+
} from './workflow';
|
|
9
|
+
|
|
10
|
+
export const interceptors = (): WorkflowInterceptors => ({
|
|
11
|
+
inbound: [new OpenTelemetryInboundInterceptor()],
|
|
12
|
+
outbound: [new OpenTelemetryOutboundInterceptor()],
|
|
13
|
+
internals: [new OpenTelemetryInternalsInterceptor()],
|
|
14
|
+
});
|
|
@@ -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
|
-
}
|