@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,qBAAmB,CAAC,uDAAuD;AAC3E,yDAA2C;AAC3C,uEAAyD;AAqBzD,wDAS4B;AAC5B,uDAAmD;AACnD,+CAAyD;AACzD,mDAA+C;AAC/C,yDAAyF;AAEzF,gDAA8B;AAE9B,IAAI,MAAM,GAA4B,SAAS,CAAC;AAChD,IAAI,cAAc,GAA+B,SAAS,CAAC;AAE3D,SAAS,SAAS;IAChB,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,cAAc,GAAG,IAAI,gCAAc,EAAE,CAAC;IACxC,CAAC;IACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;QACnD,QAAQ,CAAC,gBAAgB,CAAC,IAAI,OAAO,CAAC,mBAAmB,CAAC,IAAI,4BAAY,EAAE,CAAC,CAAC,CAAC;QAC/E,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC;QACtC,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,kCAAkC,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAa,+BAA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W,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;IAEM,aAAa,CAClB,KAAyB,EACzB,IAA6D;QAE7D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACvD,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,EAAE,CAAC;QACxC,IAAI,WAAW,IAAI,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;YACxD,OAAO,IAAI,CAAC;gBACV,QAAQ,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;AA3JD,4EA2JC;AAED,MAAa,iCAAiC;IAC5C,KAAK,CAAC,OAAO,CAAC,KAAmB,EAAE,IAAmD;QACpF,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,CAAC;IACd,CAAC;CACF;AAPD,8EAOC"}
|
package/lib/workflow/runtime.js
CHANGED
|
@@ -4,9 +4,8 @@ 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
|
-
|
|
9
|
-
if (inWorkflowContext?.()) {
|
|
7
|
+
const workflow_imports_1 = require("./workflow-imports");
|
|
8
|
+
if ((0, workflow_imports_1.inWorkflowContext)()) {
|
|
10
9
|
// Required by opentelemetry (pretend to be a browser)
|
|
11
10
|
Object.assign(globalThis, {
|
|
12
11
|
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,yDAAuD;AAEvD,IAAI,IAAA,oCAAiB,GAAE,EAAE,CAAC;IACxB,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
|
+
private exporter?;
|
|
6
6
|
export(spans: tracing.ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
7
7
|
shutdown(): Promise<void>;
|
|
8
8
|
makeSerializable(span: tracing.ReadableSpan): SerializableSpan;
|
|
@@ -2,24 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SpanExporter = void 0;
|
|
4
4
|
const core_1 = require("@opentelemetry/core");
|
|
5
|
-
const
|
|
6
|
-
const exporter = (0, workflow_module_loader_1.getWorkflowModuleIfAvailable)()?.proxySinks()?.exporter;
|
|
5
|
+
const workflow_imports_1 = require("./workflow-imports");
|
|
7
6
|
class SpanExporter {
|
|
8
|
-
|
|
9
|
-
(0, workflow_module_loader_1.ensureWorkflowModuleLoaded)();
|
|
10
|
-
}
|
|
7
|
+
exporter;
|
|
11
8
|
export(spans, resultCallback) {
|
|
12
|
-
|
|
9
|
+
if (!this.exporter) {
|
|
10
|
+
this.exporter = (0, workflow_imports_1.proxySinks)().exporter;
|
|
11
|
+
}
|
|
12
|
+
this.exporter.export(spans.map((span) => this.makeSerializable(span)));
|
|
13
13
|
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
14
14
|
}
|
|
15
15
|
async shutdown() {
|
|
16
16
|
// Nothing to shut down
|
|
17
17
|
}
|
|
18
18
|
makeSerializable(span) {
|
|
19
|
+
const { traceState, ...restSpanContext } = span.spanContext();
|
|
20
|
+
// Serialize traceState to a string because TraceState objects lose their
|
|
21
|
+
// prototype methods when crossing the V8 isolate boundary.
|
|
22
|
+
// See: https://github.com/temporalio/sdk-typescript/issues/1738
|
|
23
|
+
const serializableSpanContext = {
|
|
24
|
+
traceState: traceState?.serialize(),
|
|
25
|
+
...restSpanContext,
|
|
26
|
+
};
|
|
19
27
|
return {
|
|
20
28
|
name: span.name,
|
|
21
29
|
kind: span.kind,
|
|
22
|
-
spanContext:
|
|
30
|
+
spanContext: serializableSpanContext,
|
|
23
31
|
parentSpanId: span.parentSpanId,
|
|
24
32
|
startTime: span.startTime,
|
|
25
33
|
endTime: span.endTime,
|
|
@@ -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,yDAAgD;AAEhD,MAAa,YAAY;IACf,QAAQ,CAAkC;IAE3C,MA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C3C,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;SACpD,CAAC;IACJ,CAAC;CACF;AA3CD,oCA2CC"}
|
|
@@ -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,20 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Not a workflow, just interceptors */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.interceptors = void 0;
|
|
5
|
+
const workflow_1 = require("./workflow");
|
|
6
|
+
const interceptors = () => ({
|
|
7
|
+
inbound: [new workflow_1.OpenTelemetryInboundInterceptor()],
|
|
8
|
+
outbound: [new workflow_1.OpenTelemetryOutboundInterceptor()],
|
|
9
|
+
internals: [new workflow_1.OpenTelemetryInternalsInterceptor()],
|
|
10
|
+
});
|
|
11
|
+
exports.interceptors = interceptors;
|
|
12
|
+
//# sourceMappingURL=workflow-interceptors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-interceptors.js","sourceRoot":"","sources":["../src/workflow-interceptors.ts"],"names":[],"mappings":";AAAA,wCAAwC;;;AAGxC,yCAIoB;AAEb,MAAM,YAAY,GAAG,GAAyB,EAAE,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,IAAI,0CAA+B,EAAE,CAAC;IAChD,QAAQ,EAAE,CAAC,IAAI,2CAAgC,EAAE,CAAC;IAClD,SAAS,EAAE,CAAC,IAAI,4CAAiC,EAAE,CAAC;CACrD,CAAC,CAAC;AAJU,QAAA,YAAY,gBAItB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/interceptors-opentelemetry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.1",
|
|
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",
|
|
@@ -16,18 +16,19 @@
|
|
|
16
16
|
"@opentelemetry/api": "^1.9.0",
|
|
17
17
|
"@opentelemetry/core": "^1.25.1",
|
|
18
18
|
"@opentelemetry/resources": "^1.25.1",
|
|
19
|
-
"@opentelemetry/sdk-trace-base": "^1.25.1"
|
|
19
|
+
"@opentelemetry/sdk-trace-base": "^1.25.1",
|
|
20
|
+
"@temporalio/plugin": "1.15.1"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@temporalio/activity": "1.
|
|
23
|
-
"@temporalio/client": "1.
|
|
24
|
-
"@temporalio/
|
|
25
|
-
"@temporalio/
|
|
26
|
-
"@temporalio/worker": "1.
|
|
23
|
+
"@temporalio/activity": "1.15.1",
|
|
24
|
+
"@temporalio/client": "1.15.1",
|
|
25
|
+
"@temporalio/workflow": "1.15.1",
|
|
26
|
+
"@temporalio/common": "1.15.1",
|
|
27
|
+
"@temporalio/worker": "1.15.1"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
|
-
"@temporalio/
|
|
30
|
-
"@temporalio/
|
|
30
|
+
"@temporalio/workflow": "1.15.1",
|
|
31
|
+
"@temporalio/common": "1.15.1"
|
|
31
32
|
},
|
|
32
33
|
"peerDependenciesMeta": {
|
|
33
34
|
"@temporalio/workflow": {
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
50
|
"engines": {
|
|
50
|
-
"node": ">=
|
|
51
|
+
"node": ">= 20.0.0"
|
|
51
52
|
},
|
|
52
53
|
"files": [
|
|
53
54
|
"src",
|
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/definitions';
|
|
30
30
|
|
|
31
31
|
export interface InterceptorOptions {
|
|
32
32
|
readonly tracer?: otel.Tracer;
|
package/src/index.ts
CHANGED
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
2
|
+
import { Resource } from '@opentelemetry/resources';
|
|
3
|
+
import { SimplePlugin } from '@temporalio/plugin';
|
|
4
|
+
import { InjectedSinks, ReplayWorkerOptions, WorkerOptions } from '@temporalio/worker';
|
|
5
|
+
import { InterceptorOptions, OpenTelemetryWorkflowClientInterceptor } from './client';
|
|
6
|
+
import {
|
|
7
|
+
makeWorkflowExporter,
|
|
8
|
+
OpenTelemetryActivityInboundInterceptor,
|
|
9
|
+
OpenTelemetryActivityOutboundInterceptor,
|
|
10
|
+
} from './worker';
|
|
11
|
+
import { OpenTelemetrySinks } from './workflow';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration options for {@link OpenTelemetryPlugin}.
|
|
15
|
+
*
|
|
16
|
+
* @experimental Plugins is an experimental feature; APIs may change without notice.
|
|
17
|
+
*/
|
|
18
|
+
export interface OpenTelemetryPluginOptions extends InterceptorOptions {
|
|
19
|
+
/** OpenTelemetry resource attributes to attach to exported spans */
|
|
20
|
+
readonly resource: Resource;
|
|
21
|
+
/** Exporter used to send spans to a tracing backend */
|
|
22
|
+
readonly spanProcessor: SpanProcessor;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A plugin that adds OpenTelemetry tracing.
|
|
27
|
+
*
|
|
28
|
+
* Configures Client, Activity, and Workflow interceptors for trace propagation and injects
|
|
29
|
+
* a span exporter sink for Workflow spans.
|
|
30
|
+
*
|
|
31
|
+
* @experimental Plugins is an experimental feature; APIs may change without notice.
|
|
32
|
+
*/
|
|
33
|
+
export class OpenTelemetryPlugin extends SimplePlugin {
|
|
34
|
+
constructor(readonly otelOptions: OpenTelemetryPluginOptions) {
|
|
35
|
+
const workflowInterceptorsPath = require.resolve('./workflow-interceptors');
|
|
36
|
+
const interceptorOptions = otelOptions.tracer ? { tracer: otelOptions.tracer } : {};
|
|
37
|
+
super({
|
|
38
|
+
name: 'OpenTelemetryPlugin',
|
|
39
|
+
clientInterceptors: {
|
|
40
|
+
workflow: [new OpenTelemetryWorkflowClientInterceptor(interceptorOptions)],
|
|
41
|
+
},
|
|
42
|
+
workerInterceptors: {
|
|
43
|
+
client: {
|
|
44
|
+
workflow: [new OpenTelemetryWorkflowClientInterceptor(interceptorOptions)],
|
|
45
|
+
},
|
|
46
|
+
workflowModules: [workflowInterceptorsPath],
|
|
47
|
+
activity: [
|
|
48
|
+
(ctx) => ({
|
|
49
|
+
inbound: new OpenTelemetryActivityInboundInterceptor(ctx, interceptorOptions),
|
|
50
|
+
outbound: new OpenTelemetryActivityOutboundInterceptor(ctx),
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
configureWorker(options: WorkerOptions): WorkerOptions {
|
|
58
|
+
return super.configureWorker(this.injectSinks(options));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
configureReplayWorker(options: ReplayWorkerOptions): ReplayWorkerOptions {
|
|
62
|
+
return super.configureReplayWorker(this.injectSinks(options));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private injectSinks<T extends { sinks?: InjectedSinks<any> }>(options: T): T {
|
|
66
|
+
const sinks: InjectedSinks<OpenTelemetrySinks> = {
|
|
67
|
+
exporter: makeWorkflowExporter(this.otelOptions.spanProcessor, this.otelOptions.resource),
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
...options,
|
|
71
|
+
sinks: {
|
|
72
|
+
...options.sinks,
|
|
73
|
+
...sinks,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/worker/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
|
+
import { createTraceState } from '@opentelemetry/api';
|
|
2
3
|
import type { Resource } from '@opentelemetry/resources';
|
|
3
|
-
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
4
|
+
import type { ReadableSpan, SpanExporter, SpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
4
5
|
import type { Context as ActivityContext } from '@temporalio/activity';
|
|
5
6
|
import type {
|
|
6
7
|
Next,
|
|
@@ -18,7 +19,12 @@ import {
|
|
|
18
19
|
RUN_ID_ATTR_KEY,
|
|
19
20
|
ACTIVITY_ID_ATTR_KEY,
|
|
20
21
|
} from '../instrumentation';
|
|
21
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
type OpenTelemetryWorkflowExporter,
|
|
24
|
+
type SerializableSpan,
|
|
25
|
+
SpanName,
|
|
26
|
+
SPAN_DELIMITER,
|
|
27
|
+
} from '../workflow/definitions';
|
|
22
28
|
|
|
23
29
|
export interface InterceptorOptions {
|
|
24
30
|
readonly tracer?: otel.Tracer;
|
|
@@ -104,11 +110,28 @@ export class OpenTelemetryActivityOutboundInterceptor implements ActivityOutboun
|
|
|
104
110
|
|
|
105
111
|
/**
|
|
106
112
|
* Takes an opentelemetry SpanExporter and turns it into an injected Workflow span exporter sink
|
|
113
|
+
*
|
|
114
|
+
* @deprecated Do not directly pass a `SpanExporter`. Pass a `SpanProcessor` instead to ensure proper handling of async attributes.
|
|
115
|
+
*/
|
|
116
|
+
export function makeWorkflowExporter(
|
|
117
|
+
spanExporter: SpanExporter,
|
|
118
|
+
resource: Resource
|
|
119
|
+
): InjectedSink<OpenTelemetryWorkflowExporter>;
|
|
120
|
+
/**
|
|
121
|
+
* Takes an opentelemetry SpanProcessor and turns it into an injected Workflow span exporter sink.
|
|
122
|
+
*
|
|
123
|
+
* For backward compatibility, passing a `SpanExporter` directly is still supported.
|
|
107
124
|
*/
|
|
108
125
|
export function makeWorkflowExporter(
|
|
109
|
-
|
|
126
|
+
spanProcessor: SpanProcessor,
|
|
127
|
+
resource: Resource
|
|
128
|
+
): InjectedSink<OpenTelemetryWorkflowExporter>;
|
|
129
|
+
export function makeWorkflowExporter(
|
|
130
|
+
processorOrExporter: SpanProcessor | SpanExporter,
|
|
110
131
|
resource: Resource
|
|
111
132
|
): InjectedSink<OpenTelemetryWorkflowExporter> {
|
|
133
|
+
const givenSpanProcessor = isSpanProcessor(processorOrExporter);
|
|
134
|
+
|
|
112
135
|
return {
|
|
113
136
|
export: {
|
|
114
137
|
fn: (info, spanData) => {
|
|
@@ -117,18 +140,35 @@ export function makeWorkflowExporter(
|
|
|
117
140
|
// Spans are copied over from the isolate and are converted to ReadableSpan instances
|
|
118
141
|
return extractReadableSpan(serialized, resource);
|
|
119
142
|
});
|
|
120
|
-
|
|
121
|
-
|
|
143
|
+
|
|
144
|
+
if (givenSpanProcessor) {
|
|
145
|
+
spans.forEach((span) => processorOrExporter.onEnd(span));
|
|
146
|
+
} else {
|
|
147
|
+
// Ignore the export result for simplicity
|
|
148
|
+
processorOrExporter.export(spans, () => undefined);
|
|
149
|
+
}
|
|
122
150
|
},
|
|
123
151
|
},
|
|
124
152
|
};
|
|
125
153
|
}
|
|
126
154
|
|
|
155
|
+
function isSpanProcessor(obj: SpanProcessor | SpanExporter): obj is SpanProcessor {
|
|
156
|
+
return 'onEnd' in obj && typeof obj.onEnd === 'function';
|
|
157
|
+
}
|
|
158
|
+
|
|
127
159
|
/**
|
|
128
160
|
* Deserialize a serialized span created by the Workflow isolate
|
|
129
161
|
*/
|
|
130
162
|
function extractReadableSpan(serializable: SerializableSpan, resource: Resource): ReadableSpan {
|
|
131
|
-
const {
|
|
163
|
+
const {
|
|
164
|
+
spanContext: { traceState, ...restSpanContext },
|
|
165
|
+
...rest
|
|
166
|
+
} = serializable;
|
|
167
|
+
const spanContext: otel.SpanContext = {
|
|
168
|
+
// Reconstruct the TraceState from the serialized string.
|
|
169
|
+
traceState: traceState ? createTraceState(traceState) : undefined,
|
|
170
|
+
...restSpanContext,
|
|
171
|
+
};
|
|
132
172
|
return {
|
|
133
173
|
spanContext() {
|
|
134
174
|
return spanContext;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
+
import { type AsyncLocalStorage } from 'async_hooks';
|
|
1
2
|
import * as otel from '@opentelemetry/api';
|
|
2
|
-
import { ensureWorkflowModuleLoaded, getWorkflowModuleIfAvailable } from './workflow-module-loader';
|
|
3
|
-
|
|
4
|
-
const AsyncLocalStorage = getWorkflowModuleIfAvailable()?.AsyncLocalStorage;
|
|
5
3
|
|
|
6
4
|
export class ContextManager implements otel.ContextManager {
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
protected storage = AsyncLocalStorage ? new AsyncLocalStorage<otel.Context>() : undefined;
|
|
10
|
-
|
|
11
|
-
public constructor() {
|
|
12
|
-
ensureWorkflowModuleLoaded();
|
|
13
|
-
}
|
|
5
|
+
// The workflow sandbox provides AsyncLocalStorage through globalThis.
|
|
6
|
+
protected storage: AsyncLocalStorage<otel.Context> = new (globalThis as any).AsyncLocalStorage();
|
|
14
7
|
|
|
15
8
|
active(): otel.Context {
|
|
16
|
-
return this.storage
|
|
9
|
+
return this.storage.getStore() || otel.ROOT_CONTEXT;
|
|
17
10
|
}
|
|
18
11
|
|
|
19
12
|
bind<T>(context: otel.Context, target: T): T {
|
|
@@ -35,7 +28,7 @@ export class ContextManager implements otel.ContextManager {
|
|
|
35
28
|
* It isn't possible to tell Typescript that contextWrapper is the same as T
|
|
36
29
|
* so we forced to cast as any here.
|
|
37
30
|
*/
|
|
38
|
-
|
|
31
|
+
|
|
39
32
|
return contextWrapper as any;
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -44,7 +37,7 @@ export class ContextManager implements otel.ContextManager {
|
|
|
44
37
|
}
|
|
45
38
|
|
|
46
39
|
disable(): this {
|
|
47
|
-
this.storage
|
|
40
|
+
this.storage.disable();
|
|
48
41
|
return this;
|
|
49
42
|
}
|
|
50
43
|
|
|
@@ -55,6 +48,6 @@ export class ContextManager implements otel.ContextManager {
|
|
|
55
48
|
...args: A
|
|
56
49
|
): ReturnType<F> {
|
|
57
50
|
const cb = thisArg == null ? fn : fn.bind(thisArg);
|
|
58
|
-
return this.storage
|
|
51
|
+
return this.storage.run(context, cb, ...args);
|
|
59
52
|
}
|
|
60
53
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
2
|
import * as tracing from '@opentelemetry/sdk-trace-base';
|
|
3
|
-
import { InstrumentationLibrary } from '@opentelemetry/core'; // eslint-disable
|
|
4
|
-
import { Sink, Sinks } from '@temporalio/workflow';
|
|
3
|
+
import { InstrumentationLibrary } from '@opentelemetry/core'; // eslint-disable @typescript-eslint/no-deprecated
|
|
4
|
+
import type { Sink, Sinks } from '@temporalio/workflow';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Serializable version of SpanContext where traceState is converted to a string.
|
|
8
|
+
*/
|
|
9
|
+
export type SerializableSpanContext = Omit<otel.SpanContext, 'traceState'> & { traceState?: string };
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Serializable version of the opentelemetry Span for cross isolate copying
|
|
@@ -9,7 +14,7 @@ import { Sink, Sinks } from '@temporalio/workflow';
|
|
|
9
14
|
export interface SerializableSpan {
|
|
10
15
|
readonly name: string;
|
|
11
16
|
readonly kind: otel.SpanKind;
|
|
12
|
-
readonly spanContext:
|
|
17
|
+
readonly spanContext: SerializableSpanContext;
|
|
13
18
|
readonly parentSpanId?: string;
|
|
14
19
|
readonly startTime: otel.HrTime;
|
|
15
20
|
readonly endTime: otel.HrTime;
|
|
@@ -23,7 +28,7 @@ export interface SerializableSpan {
|
|
|
23
28
|
readonly droppedLinksCount: number;
|
|
24
29
|
readonly droppedEventsCount: number;
|
|
25
30
|
// readonly resource: Resource;
|
|
26
|
-
// eslint-disable-next-line
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
27
32
|
readonly instrumentationLibrary: InstrumentationLibrary;
|
|
28
33
|
}
|
|
29
34
|
|