@temporalio/interceptors-opentelemetry 1.11.3 → 1.11.5
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.d.ts +2 -1
- package/lib/client/index.js +10 -0
- package/lib/client/index.js.map +1 -1
- package/lib/instrumentation.js +4 -4
- package/lib/instrumentation.js.map +1 -1
- package/lib/worker/index.d.ts +11 -1
- package/lib/worker/index.js +28 -2
- package/lib/worker/index.js.map +1 -1
- package/lib/workflow/context-manager.d.ts +0 -1
- package/lib/workflow/definitions.d.ts +4 -0
- package/lib/workflow/definitions.js +4 -0
- package/lib/workflow/definitions.js.map +1 -1
- package/lib/workflow/index.d.ts +4 -1
- package/lib/workflow/index.js +38 -0
- package/lib/workflow/index.js.map +1 -1
- package/package.json +12 -12
- package/src/client/index.ts +12 -1
- package/src/worker/index.ts +35 -1
- package/src/workflow/definitions.ts +5 -0
- package/src/workflow/index.ts +51 -0
package/lib/client/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
|
-
import { Next, WorkflowClientInterceptor, WorkflowStartInput } from '@temporalio/client';
|
|
2
|
+
import { Next, WorkflowClientInterceptor, WorkflowSignalInput, WorkflowStartInput } from '@temporalio/client';
|
|
3
3
|
export interface InterceptorOptions {
|
|
4
4
|
readonly tracer?: otel.Tracer;
|
|
5
5
|
}
|
|
@@ -12,4 +12,5 @@ export declare class OpenTelemetryWorkflowClientInterceptor implements WorkflowC
|
|
|
12
12
|
protected readonly tracer: otel.Tracer;
|
|
13
13
|
constructor(options?: InterceptorOptions);
|
|
14
14
|
start(input: WorkflowStartInput, next: Next<WorkflowClientInterceptor, 'start'>): Promise<string>;
|
|
15
|
+
signal(input: WorkflowSignalInput, next: Next<WorkflowClientInterceptor, 'signal'>): Promise<void>;
|
|
15
16
|
}
|
package/lib/client/index.js
CHANGED
|
@@ -48,6 +48,16 @@ class OpenTelemetryWorkflowClientInterceptor {
|
|
|
48
48
|
},
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
+
async signal(input, next) {
|
|
52
|
+
return await (0, instrumentation_1.instrument)({
|
|
53
|
+
tracer: this.tracer,
|
|
54
|
+
spanName: `${workflow_1.SpanName.WORKFLOW_SIGNAL}${workflow_1.SPAN_DELIMITER}${input.signalName}`,
|
|
55
|
+
fn: async () => {
|
|
56
|
+
const headers = await (0, instrumentation_1.headersWithContext)(input.headers);
|
|
57
|
+
await next({ ...input, headers });
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
51
61
|
}
|
|
52
62
|
exports.OpenTelemetryWorkflowClientInterceptor = OpenTelemetryWorkflowClientInterceptor;
|
|
53
63
|
//# sourceMappingURL=index.js.map
|
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;AAE3C,wDAAqF;AACrF,0CAAuD;AAMvD;;;;GAIG;AACH,MAAa,sCAAsC;IAGjD,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,MAAM,IAAA,oCAAkB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACxD,MAAM,KAAK,GAAG,MAAM,IAAI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,CAAC,eAAe,GAAG,yBAAc,GAAG,KAAK,CAAC,UAAU,EAAE;YAC3E,EAAE,EAAE,KAAK,IAAI,EAAE;gBACb,MAAM,OAAO,GAAG,MAAM,IAAA,oCAAkB,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACxD,MAAM,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;YACpC,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AA9BD,wFA8BC"}
|
package/lib/instrumentation.js
CHANGED
|
@@ -23,7 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.RUN_ID_ATTR_KEY = exports.TRACE_HEADER = void 0;
|
|
27
|
+
exports.extractContextFromHeaders = extractContextFromHeaders;
|
|
28
|
+
exports.headersWithContext = headersWithContext;
|
|
29
|
+
exports.instrument = instrument;
|
|
27
30
|
/**
|
|
28
31
|
* opentelemetry instrumentation helper functions
|
|
29
32
|
* @module
|
|
@@ -46,7 +49,6 @@ async function extractContextFromHeaders(headers) {
|
|
|
46
49
|
const textMap = payloadConverter.fromPayload(encodedSpanContext);
|
|
47
50
|
return otel.propagation.extract(otel.context.active(), textMap, otel.defaultTextMapGetter);
|
|
48
51
|
}
|
|
49
|
-
exports.extractContextFromHeaders = extractContextFromHeaders;
|
|
50
52
|
/**
|
|
51
53
|
* Given headers, return new headers with the current otel context inserted
|
|
52
54
|
*/
|
|
@@ -55,7 +57,6 @@ async function headersWithContext(headers) {
|
|
|
55
57
|
otel.propagation.inject(otel.context.active(), carrier, otel.defaultTextMapSetter);
|
|
56
58
|
return { ...headers, [exports.TRACE_HEADER]: payloadConverter.toPayload(carrier) };
|
|
57
59
|
}
|
|
58
|
-
exports.headersWithContext = headersWithContext;
|
|
59
60
|
async function wrapWithSpan(span, fn, acceptableErrors) {
|
|
60
61
|
try {
|
|
61
62
|
const ret = await fn(span);
|
|
@@ -87,5 +88,4 @@ async function instrument({ tracer, spanName, fn, context, acceptableErrors, })
|
|
|
87
88
|
}
|
|
88
89
|
return await tracer.startActiveSpan(spanName, async (span) => await wrapWithSpan(span, fn, acceptableErrors));
|
|
89
90
|
}
|
|
90
|
-
exports.instrument = instrument;
|
|
91
91
|
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../src/instrumentation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,8DAOC;AAKD,gDAIC;AAmCD,gCAaC;AAjFD;;;GAGG;AACH,yDAA2C;AAC3C,+CAAsE;AAEtE,0DAA0D;AAC7C,QAAA,YAAY,GAAG,cAAc,CAAC;AAC3C,4BAA4B;AACf,QAAA,eAAe,GAAG,QAAQ,CAAC;AAExC,MAAM,gBAAgB,GAAG,gCAAuB,CAAC;AAEjD;;GAEG;AACI,KAAK,UAAU,yBAAyB,CAAC,OAAgB;IAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,oBAAY,CAAC,CAAC;IACjD,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAA2B,gBAAgB,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACzF,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAC7F,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAAgB;IACvD,MAAM,OAAO,GAAG,EAAE,CAA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IAAI,EAAE;YACjD,OAAO,MAAM,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAChH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAChH,CAAC"}
|
package/lib/worker/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as otel from '@opentelemetry/api';
|
|
|
2
2
|
import { Resource } from '@opentelemetry/resources';
|
|
3
3
|
import { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
4
4
|
import { Context as ActivityContext } from '@temporalio/activity';
|
|
5
|
-
import { ActivityExecuteInput, ActivityInboundCallsInterceptor, InjectedSink, Next } from '@temporalio/worker';
|
|
5
|
+
import { ActivityExecuteInput, ActivityInboundCallsInterceptor, ActivityOutboundCallsInterceptor, GetLogAttributesInput, InjectedSink, Next } from '@temporalio/worker';
|
|
6
6
|
import { OpenTelemetryWorkflowExporter } from '../workflow';
|
|
7
7
|
export interface InterceptorOptions {
|
|
8
8
|
readonly tracer?: otel.Tracer;
|
|
@@ -19,6 +19,16 @@ export declare class OpenTelemetryActivityInboundInterceptor implements Activity
|
|
|
19
19
|
constructor(ctx: ActivityContext, options?: InterceptorOptions);
|
|
20
20
|
execute(input: ActivityExecuteInput, next: Next<ActivityInboundCallsInterceptor, 'execute'>): Promise<unknown>;
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Intercepts calls to emit logs from an Activity.
|
|
24
|
+
*
|
|
25
|
+
* Attach OpenTelemetry context tracing attributes to emitted log messages, if appropriate.
|
|
26
|
+
*/
|
|
27
|
+
export declare class OpenTelemetryActivityOutboundInterceptor implements ActivityOutboundCallsInterceptor {
|
|
28
|
+
protected readonly ctx: ActivityContext;
|
|
29
|
+
constructor(ctx: ActivityContext);
|
|
30
|
+
getLogAttributes(input: GetLogAttributesInput, next: Next<ActivityOutboundCallsInterceptor, 'getLogAttributes'>): Record<string, unknown>;
|
|
31
|
+
}
|
|
22
32
|
/**
|
|
23
33
|
* Takes an opentelemetry SpanExporter and turns it into an injected Workflow span exporter sink
|
|
24
34
|
*/
|
package/lib/worker/index.js
CHANGED
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.OpenTelemetryActivityOutboundInterceptor = exports.OpenTelemetryActivityInboundInterceptor = void 0;
|
|
27
|
+
exports.makeWorkflowExporter = makeWorkflowExporter;
|
|
27
28
|
const otel = __importStar(require("@opentelemetry/api"));
|
|
28
29
|
const instrumentation_1 = require("../instrumentation");
|
|
29
30
|
const workflow_1 = require("../workflow");
|
|
@@ -45,6 +46,32 @@ class OpenTelemetryActivityInboundInterceptor {
|
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
exports.OpenTelemetryActivityInboundInterceptor = OpenTelemetryActivityInboundInterceptor;
|
|
49
|
+
/**
|
|
50
|
+
* Intercepts calls to emit logs from an Activity.
|
|
51
|
+
*
|
|
52
|
+
* Attach OpenTelemetry context tracing attributes to emitted log messages, if appropriate.
|
|
53
|
+
*/
|
|
54
|
+
class OpenTelemetryActivityOutboundInterceptor {
|
|
55
|
+
constructor(ctx) {
|
|
56
|
+
this.ctx = ctx;
|
|
57
|
+
}
|
|
58
|
+
getLogAttributes(input, next) {
|
|
59
|
+
const span = otel.trace.getSpan(otel.context.active());
|
|
60
|
+
const spanContext = span?.spanContext();
|
|
61
|
+
if (spanContext && otel.isSpanContextValid(spanContext)) {
|
|
62
|
+
return next({
|
|
63
|
+
trace_id: spanContext.traceId,
|
|
64
|
+
span_id: spanContext.spanId,
|
|
65
|
+
trace_flags: `0${spanContext.traceFlags.toString(16)}`,
|
|
66
|
+
...input,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return next(input);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.OpenTelemetryActivityOutboundInterceptor = OpenTelemetryActivityOutboundInterceptor;
|
|
48
75
|
/**
|
|
49
76
|
* Takes an opentelemetry SpanExporter and turns it into an injected Workflow span exporter sink
|
|
50
77
|
*/
|
|
@@ -63,7 +90,6 @@ function makeWorkflowExporter(exporter, resource) {
|
|
|
63
90
|
},
|
|
64
91
|
};
|
|
65
92
|
}
|
|
66
|
-
exports.makeWorkflowExporter = makeWorkflowExporter;
|
|
67
93
|
/**
|
|
68
94
|
* Deserialize a serialized span created by the Workflow isolate
|
|
69
95
|
*/
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,oDAiBC;AAzFD,yDAA2C;AAY3C,wDAA2E;AAC3E,0CAAwG;AAMxG;;;;;GAKG;AACH,MAAa,uCAAuC;IAGlD,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,MAAM,IAAA,2CAAyB,EAAC,KAAK,CA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AQ,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/workflow/definitions.ts"],"names":[],"mappings":";;;AAwCA,IAAY,
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/workflow/definitions.ts"],"names":[],"mappings":";;;AAwCA,IAAY,QAoCX;AApCD,WAAY,QAAQ;IAClB;;OAEG;IACH,4CAAgC,CAAA;IAEhC;;OAEG;IACH,8CAAkC,CAAA;IAElC;;OAEG;IACH,kEAAsD,CAAA;IAEtD;;OAEG;IACH,4CAAgC,CAAA;IAChC;;OAEG;IACH,uDAA2C,CAAA;IAC3C;;OAEG;IACH,4CAAgC,CAAA;IAChC;;OAEG;IACH,4CAAgC,CAAA;IAChC;;OAEG;IACH,6CAAiC,CAAA;AACnC,CAAC,EApCW,QAAQ,wBAAR,QAAQ,QAoCnB;AAEY,QAAA,cAAc,GAAG,GAAG,CAAC"}
|
package/lib/workflow/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './runtime';
|
|
2
2
|
import * as otel from '@opentelemetry/api';
|
|
3
|
-
import { ActivityInput, ContinueAsNewInput, DisposeInput, Next, StartChildWorkflowExecutionInput, WorkflowExecuteInput, WorkflowInboundCallsInterceptor, WorkflowInternalsInterceptor, WorkflowOutboundCallsInterceptor } from '@temporalio/workflow';
|
|
3
|
+
import { ActivityInput, ContinueAsNewInput, DisposeInput, GetLogAttributesInput, Next, SignalInput, SignalWorkflowInput, StartChildWorkflowExecutionInput, WorkflowExecuteInput, WorkflowInboundCallsInterceptor, WorkflowInternalsInterceptor, WorkflowOutboundCallsInterceptor } from '@temporalio/workflow';
|
|
4
4
|
export * from './definitions';
|
|
5
5
|
/**
|
|
6
6
|
* Intercepts calls to run a Workflow
|
|
@@ -11,6 +11,7 @@ export * from './definitions';
|
|
|
11
11
|
export declare class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInterceptor {
|
|
12
12
|
protected readonly tracer: otel.Tracer;
|
|
13
13
|
execute(input: WorkflowExecuteInput, next: Next<WorkflowInboundCallsInterceptor, 'execute'>): Promise<unknown>;
|
|
14
|
+
handleSignal(input: SignalInput, next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>): Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Intercepts outbound calls to schedule an Activity
|
|
@@ -22,6 +23,8 @@ export declare class OpenTelemetryOutboundInterceptor implements WorkflowOutboun
|
|
|
22
23
|
scheduleActivity(input: ActivityInput, next: Next<WorkflowOutboundCallsInterceptor, 'scheduleActivity'>): Promise<unknown>;
|
|
23
24
|
startChildWorkflowExecution(input: StartChildWorkflowExecutionInput, next: Next<WorkflowOutboundCallsInterceptor, 'startChildWorkflowExecution'>): Promise<[Promise<string>, Promise<unknown>]>;
|
|
24
25
|
continueAsNew(input: ContinueAsNewInput, next: Next<WorkflowOutboundCallsInterceptor, 'continueAsNew'>): Promise<never>;
|
|
26
|
+
signalWorkflow(input: SignalWorkflowInput, next: Next<WorkflowOutboundCallsInterceptor, 'signalWorkflow'>): Promise<void>;
|
|
27
|
+
getLogAttributes(input: GetLogAttributesInput, next: Next<WorkflowOutboundCallsInterceptor, 'getLogAttributes'>): Record<string, unknown>;
|
|
25
28
|
}
|
|
26
29
|
export declare class OpenTelemetryInternalsInterceptor implements WorkflowInternalsInterceptor {
|
|
27
30
|
dispose(input: DisposeInput, next: Next<WorkflowInternalsInterceptor, 'dispose'>): Promise<void>;
|
package/lib/workflow/index.js
CHANGED
|
@@ -30,6 +30,7 @@ exports.OpenTelemetryInternalsInterceptor = exports.OpenTelemetryOutboundInterce
|
|
|
30
30
|
/* eslint-disable import/order */
|
|
31
31
|
// eslint-disable-next-line import/no-unassigned-import
|
|
32
32
|
require("./runtime"); // Patch the Workflow isolate runtime for opentelemetry
|
|
33
|
+
const otel = __importStar(require("@opentelemetry/api"));
|
|
33
34
|
const tracing = __importStar(require("@opentelemetry/sdk-trace-base"));
|
|
34
35
|
const workflow_1 = require("@temporalio/workflow");
|
|
35
36
|
const instrumentation_1 = require("../instrumentation");
|
|
@@ -71,6 +72,15 @@ class OpenTelemetryInboundInterceptor {
|
|
|
71
72
|
acceptableErrors: (err) => err instanceof workflow_1.ContinueAsNew,
|
|
72
73
|
});
|
|
73
74
|
}
|
|
75
|
+
async handleSignal(input, next) {
|
|
76
|
+
const context = await (0, instrumentation_1.extractContextFromHeaders)(input.headers);
|
|
77
|
+
return await (0, instrumentation_1.instrument)({
|
|
78
|
+
tracer: this.tracer,
|
|
79
|
+
spanName: `${definitions_1.SpanName.WORKFLOW_SIGNAL}${definitions_1.SPAN_DELIMITER}${input.signalName}`,
|
|
80
|
+
fn: () => next(input),
|
|
81
|
+
context,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
74
84
|
}
|
|
75
85
|
exports.OpenTelemetryInboundInterceptor = OpenTelemetryInboundInterceptor;
|
|
76
86
|
/**
|
|
@@ -122,6 +132,34 @@ class OpenTelemetryOutboundInterceptor {
|
|
|
122
132
|
acceptableErrors: (err) => err instanceof workflow_1.ContinueAsNew,
|
|
123
133
|
});
|
|
124
134
|
}
|
|
135
|
+
async signalWorkflow(input, next) {
|
|
136
|
+
return await (0, instrumentation_1.instrument)({
|
|
137
|
+
tracer: this.tracer,
|
|
138
|
+
spanName: `${definitions_1.SpanName.WORKFLOW_SIGNAL}${definitions_1.SPAN_DELIMITER}${input.signalName}`,
|
|
139
|
+
fn: async () => {
|
|
140
|
+
const headers = await (0, instrumentation_1.headersWithContext)(input.headers);
|
|
141
|
+
return next({
|
|
142
|
+
...input,
|
|
143
|
+
headers,
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
getLogAttributes(input, next) {
|
|
149
|
+
const span = otel.trace.getSpan(otel.context.active());
|
|
150
|
+
const spanContext = span?.spanContext();
|
|
151
|
+
if (spanContext && otel.isSpanContextValid(spanContext)) {
|
|
152
|
+
return next({
|
|
153
|
+
trace_id: spanContext.traceId,
|
|
154
|
+
span_id: spanContext.spanId,
|
|
155
|
+
trace_flags: `0${spanContext.traceFlags.toString(16)}`,
|
|
156
|
+
...input,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return next(input);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
125
163
|
}
|
|
126
164
|
exports.OpenTelemetryOutboundInterceptor = OpenTelemetryOutboundInterceptor;
|
|
127
165
|
class OpenTelemetryInternalsInterceptor {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC,uDAAuD;AACvD,qBAAmB,CAAC,uDAAuD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/workflow/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAiC;AACjC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BAAgB,CACrB,KAA4B,EAC5B,IAAgE;QAEhE,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;AAzFD,4EAyFC;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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/interceptors-opentelemetry",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.5",
|
|
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",
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"@opentelemetry/sdk-trace-base": "^1.19.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@temporalio/activity": "1.11.
|
|
24
|
-
"@temporalio/client": "1.11.
|
|
25
|
-
"@temporalio/common": "1.11.
|
|
26
|
-
"@temporalio/worker": "1.11.
|
|
27
|
-
"@temporalio/workflow": "1.11.
|
|
23
|
+
"@temporalio/activity": "1.11.5",
|
|
24
|
+
"@temporalio/client": "1.11.5",
|
|
25
|
+
"@temporalio/common": "1.11.5",
|
|
26
|
+
"@temporalio/worker": "1.11.5",
|
|
27
|
+
"@temporalio/workflow": "1.11.5"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@temporalio/activity": "1.11.
|
|
31
|
-
"@temporalio/client": "1.11.
|
|
32
|
-
"@temporalio/common": "1.11.
|
|
33
|
-
"@temporalio/worker": "1.11.
|
|
34
|
-
"@temporalio/workflow": "1.11.
|
|
30
|
+
"@temporalio/activity": "1.11.5",
|
|
31
|
+
"@temporalio/client": "1.11.5",
|
|
32
|
+
"@temporalio/common": "1.11.5",
|
|
33
|
+
"@temporalio/worker": "1.11.5",
|
|
34
|
+
"@temporalio/workflow": "1.11.5"
|
|
35
35
|
},
|
|
36
36
|
"bugs": {
|
|
37
37
|
"url": "https://github.com/temporalio/sdk-typescript/issues"
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"src",
|
|
50
50
|
"lib"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "a7b946cd5d4d58432509ead0f8d0c0c40742c107"
|
|
53
53
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as otel from '@opentelemetry/api';
|
|
2
|
-
import { Next, WorkflowClientInterceptor, WorkflowStartInput } from '@temporalio/client';
|
|
2
|
+
import { Next, WorkflowClientInterceptor, WorkflowSignalInput, WorkflowStartInput } from '@temporalio/client';
|
|
3
3
|
import { instrument, headersWithContext, RUN_ID_ATTR_KEY } from '../instrumentation';
|
|
4
4
|
import { SpanName, SPAN_DELIMITER } from '../workflow';
|
|
5
5
|
|
|
@@ -31,4 +31,15 @@ export class OpenTelemetryWorkflowClientInterceptor implements WorkflowClientInt
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
async signal(input: WorkflowSignalInput, next: Next<WorkflowClientInterceptor, 'signal'>): Promise<void> {
|
|
36
|
+
return await instrument({
|
|
37
|
+
tracer: this.tracer,
|
|
38
|
+
spanName: `${SpanName.WORKFLOW_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
39
|
+
fn: async () => {
|
|
40
|
+
const headers = await headersWithContext(input.headers);
|
|
41
|
+
await next({ ...input, headers });
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
34
45
|
}
|
package/src/worker/index.ts
CHANGED
|
@@ -2,7 +2,14 @@ import * as otel from '@opentelemetry/api';
|
|
|
2
2
|
import { Resource } from '@opentelemetry/resources';
|
|
3
3
|
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
4
4
|
import { Context as ActivityContext } from '@temporalio/activity';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ActivityExecuteInput,
|
|
7
|
+
ActivityInboundCallsInterceptor,
|
|
8
|
+
ActivityOutboundCallsInterceptor,
|
|
9
|
+
GetLogAttributesInput,
|
|
10
|
+
InjectedSink,
|
|
11
|
+
Next,
|
|
12
|
+
} from '@temporalio/worker';
|
|
6
13
|
import { instrument, extractContextFromHeaders } from '../instrumentation';
|
|
7
14
|
import { OpenTelemetryWorkflowExporter, SerializableSpan, SpanName, SPAN_DELIMITER } from '../workflow';
|
|
8
15
|
|
|
@@ -33,6 +40,33 @@ export class OpenTelemetryActivityInboundInterceptor implements ActivityInboundC
|
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Intercepts calls to emit logs from an Activity.
|
|
45
|
+
*
|
|
46
|
+
* Attach OpenTelemetry context tracing attributes to emitted log messages, if appropriate.
|
|
47
|
+
*/
|
|
48
|
+
export class OpenTelemetryActivityOutboundInterceptor implements ActivityOutboundCallsInterceptor {
|
|
49
|
+
constructor(protected readonly ctx: ActivityContext) {}
|
|
50
|
+
|
|
51
|
+
public getLogAttributes(
|
|
52
|
+
input: GetLogAttributesInput,
|
|
53
|
+
next: Next<ActivityOutboundCallsInterceptor, 'getLogAttributes'>
|
|
54
|
+
): Record<string, unknown> {
|
|
55
|
+
const span = otel.trace.getSpan(otel.context.active());
|
|
56
|
+
const spanContext = span?.spanContext();
|
|
57
|
+
if (spanContext && otel.isSpanContextValid(spanContext)) {
|
|
58
|
+
return next({
|
|
59
|
+
trace_id: spanContext.traceId,
|
|
60
|
+
span_id: spanContext.spanId,
|
|
61
|
+
trace_flags: `0${spanContext.traceFlags.toString(16)}`,
|
|
62
|
+
...input,
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
return next(input);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
36
70
|
/**
|
|
37
71
|
* Takes an opentelemetry SpanExporter and turns it into an injected Workflow span exporter sink
|
|
38
72
|
*/
|
package/src/workflow/index.ts
CHANGED
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
ContinueAsNew,
|
|
9
9
|
ContinueAsNewInput,
|
|
10
10
|
DisposeInput,
|
|
11
|
+
GetLogAttributesInput,
|
|
11
12
|
Next,
|
|
13
|
+
SignalInput,
|
|
14
|
+
SignalWorkflowInput,
|
|
12
15
|
StartChildWorkflowExecutionInput,
|
|
13
16
|
WorkflowExecuteInput,
|
|
14
17
|
WorkflowInboundCallsInterceptor,
|
|
@@ -61,6 +64,19 @@ export class OpenTelemetryInboundInterceptor implements WorkflowInboundCallsInte
|
|
|
61
64
|
acceptableErrors: (err) => err instanceof ContinueAsNew,
|
|
62
65
|
});
|
|
63
66
|
}
|
|
67
|
+
|
|
68
|
+
public async handleSignal(
|
|
69
|
+
input: SignalInput,
|
|
70
|
+
next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>
|
|
71
|
+
): Promise<void> {
|
|
72
|
+
const context = await extractContextFromHeaders(input.headers);
|
|
73
|
+
return await instrument({
|
|
74
|
+
tracer: this.tracer,
|
|
75
|
+
spanName: `${SpanName.WORKFLOW_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
76
|
+
fn: () => next(input),
|
|
77
|
+
context,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
/**
|
|
@@ -122,6 +138,41 @@ export class OpenTelemetryOutboundInterceptor implements WorkflowOutboundCallsIn
|
|
|
122
138
|
acceptableErrors: (err) => err instanceof ContinueAsNew,
|
|
123
139
|
});
|
|
124
140
|
}
|
|
141
|
+
|
|
142
|
+
public async signalWorkflow(
|
|
143
|
+
input: SignalWorkflowInput,
|
|
144
|
+
next: Next<WorkflowOutboundCallsInterceptor, 'signalWorkflow'>
|
|
145
|
+
): Promise<void> {
|
|
146
|
+
return await instrument({
|
|
147
|
+
tracer: this.tracer,
|
|
148
|
+
spanName: `${SpanName.WORKFLOW_SIGNAL}${SPAN_DELIMITER}${input.signalName}`,
|
|
149
|
+
fn: async () => {
|
|
150
|
+
const headers = await headersWithContext(input.headers);
|
|
151
|
+
return next({
|
|
152
|
+
...input,
|
|
153
|
+
headers,
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public getLogAttributes(
|
|
160
|
+
input: GetLogAttributesInput,
|
|
161
|
+
next: Next<WorkflowOutboundCallsInterceptor, 'getLogAttributes'>
|
|
162
|
+
): Record<string, unknown> {
|
|
163
|
+
const span = otel.trace.getSpan(otel.context.active());
|
|
164
|
+
const spanContext = span?.spanContext();
|
|
165
|
+
if (spanContext && otel.isSpanContextValid(spanContext)) {
|
|
166
|
+
return next({
|
|
167
|
+
trace_id: spanContext.traceId,
|
|
168
|
+
span_id: spanContext.spanId,
|
|
169
|
+
trace_flags: `0${spanContext.traceFlags.toString(16)}`,
|
|
170
|
+
...input,
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
return next(input);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
125
176
|
}
|
|
126
177
|
|
|
127
178
|
export class OpenTelemetryInternalsInterceptor implements WorkflowInternalsInterceptor {
|