@temporalio/activity 1.11.7 → 1.12.0-rc.0
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/index.d.ts +24 -4
- package/lib/index.js +118 -40
- package/lib/index.js.map +1 -1
- package/package.json +6 -3
- package/src/index.ts +41 -4
package/lib/index.d.ts
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
* @module
|
|
70
70
|
*/
|
|
71
71
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
72
|
-
import { Logger, Duration } from '@temporalio/common';
|
|
72
|
+
import { Logger, Duration, MetricMeter, Priority } from '@temporalio/common';
|
|
73
73
|
export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
|
|
74
74
|
ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/common';
|
|
75
75
|
/**
|
|
@@ -80,14 +80,14 @@ ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/com
|
|
|
80
80
|
*
|
|
81
81
|
* @example
|
|
82
82
|
*
|
|
83
|
-
|
|
83
|
+
* ```ts
|
|
84
84
|
*import { CompleteAsyncError } from '@temporalio/activity';
|
|
85
85
|
*
|
|
86
86
|
*export async function myActivity(): Promise<never> {
|
|
87
87
|
* // ...
|
|
88
88
|
* throw new CompleteAsyncError();
|
|
89
89
|
*}
|
|
90
|
-
|
|
90
|
+
* ```
|
|
91
91
|
*/
|
|
92
92
|
export declare class CompleteAsyncError extends Error {
|
|
93
93
|
}
|
|
@@ -179,6 +179,10 @@ export interface Info {
|
|
|
179
179
|
* For Local Activities, this is set to the Workflow's Task Queue.
|
|
180
180
|
*/
|
|
181
181
|
readonly taskQueue: string;
|
|
182
|
+
/**
|
|
183
|
+
* Priority of this activity
|
|
184
|
+
*/
|
|
185
|
+
readonly priority?: Priority;
|
|
182
186
|
}
|
|
183
187
|
/**
|
|
184
188
|
* Activity Context, used to:
|
|
@@ -245,12 +249,19 @@ export declare class Context {
|
|
|
245
249
|
* {@link Runtime.logger} property instead.
|
|
246
250
|
*/
|
|
247
251
|
log: Logger;
|
|
252
|
+
/**
|
|
253
|
+
* Get the metric meter for this activity with activity-specific tags.
|
|
254
|
+
*
|
|
255
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
256
|
+
* intercepts the `getMetricTags()` method.
|
|
257
|
+
*/
|
|
258
|
+
readonly metricMeter: MetricMeter;
|
|
248
259
|
/**
|
|
249
260
|
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
250
261
|
*
|
|
251
262
|
* @ignore
|
|
252
263
|
*/
|
|
253
|
-
constructor(info: Info, cancelled: Promise<never>, cancellationSignal: AbortSignal, heartbeat: (details?: any) => void, log: Logger);
|
|
264
|
+
constructor(info: Info, cancelled: Promise<never>, cancellationSignal: AbortSignal, heartbeat: (details?: any) => void, log: Logger, metricMeter: MetricMeter);
|
|
254
265
|
/**
|
|
255
266
|
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
256
267
|
*
|
|
@@ -338,3 +349,12 @@ export declare function cancelled(): Promise<never>;
|
|
|
338
349
|
* This is a shortcut for `Context.current().cancellationSignal` (see {@link Context.cancellationSignal}).
|
|
339
350
|
*/
|
|
340
351
|
export declare function cancellationSignal(): AbortSignal;
|
|
352
|
+
/**
|
|
353
|
+
* Get the metric meter for the current activity, with activity-specific tags.
|
|
354
|
+
*
|
|
355
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
356
|
+
* intercepts the `getMetricTags()` method.
|
|
357
|
+
*
|
|
358
|
+
* This is a shortcut for `Context.current().metricMeter` (see {@link Context.metricMeter}).
|
|
359
|
+
*/
|
|
360
|
+
export declare const metricMeter: MetricMeter;
|
package/lib/index.js
CHANGED
|
@@ -76,7 +76,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
76
76
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
77
77
|
};
|
|
78
78
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
-
exports.log = exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.CancelledFailure = exports.ApplicationFailure = void 0;
|
|
79
|
+
exports.metricMeter = exports.log = exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.CancelledFailure = exports.ApplicationFailure = void 0;
|
|
80
80
|
exports.activityInfo = activityInfo;
|
|
81
81
|
exports.sleep = sleep;
|
|
82
82
|
exports.heartbeat = heartbeat;
|
|
@@ -96,14 +96,14 @@ Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: func
|
|
|
96
96
|
*
|
|
97
97
|
* @example
|
|
98
98
|
*
|
|
99
|
-
|
|
99
|
+
* ```ts
|
|
100
100
|
*import { CompleteAsyncError } from '@temporalio/activity';
|
|
101
101
|
*
|
|
102
102
|
*export async function myActivity(): Promise<never> {
|
|
103
103
|
* // ...
|
|
104
104
|
* throw new CompleteAsyncError();
|
|
105
105
|
*}
|
|
106
|
-
|
|
106
|
+
* ```
|
|
107
107
|
*/
|
|
108
108
|
let CompleteAsyncError = class CompleteAsyncError extends Error {
|
|
109
109
|
};
|
|
@@ -140,54 +140,110 @@ class Context {
|
|
|
140
140
|
}
|
|
141
141
|
return store;
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Holds information about the current executing Activity.
|
|
145
|
+
*/
|
|
146
|
+
info;
|
|
147
|
+
/**
|
|
148
|
+
* A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
|
|
149
|
+
* is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
|
|
150
|
+
*
|
|
151
|
+
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
152
|
+
*
|
|
153
|
+
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
154
|
+
*/
|
|
155
|
+
cancelled;
|
|
156
|
+
/**
|
|
157
|
+
* An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
|
|
158
|
+
* Activity cancellation.
|
|
159
|
+
*
|
|
160
|
+
* This can be passed in to libraries such as
|
|
161
|
+
* {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
|
|
162
|
+
* in-progress request and
|
|
163
|
+
* {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
|
|
164
|
+
* to abort a child process, as well as other built-in node modules and modules found on npm.
|
|
165
|
+
*
|
|
166
|
+
* Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
|
|
167
|
+
*
|
|
168
|
+
* @see [Cancellation](/api/namespaces/activity#cancellation)
|
|
169
|
+
*/
|
|
170
|
+
cancellationSignal;
|
|
171
|
+
/**
|
|
172
|
+
* The heartbeat implementation, injected via the constructor.
|
|
173
|
+
*/
|
|
174
|
+
heartbeatFn;
|
|
175
|
+
/**
|
|
176
|
+
* The logger for this Activity.
|
|
177
|
+
*
|
|
178
|
+
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
|
|
179
|
+
* are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
|
|
180
|
+
* added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
|
|
181
|
+
*
|
|
182
|
+
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
|
|
183
|
+
* `getLogAttributes()` method.
|
|
184
|
+
*
|
|
185
|
+
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
|
|
186
|
+
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
|
|
187
|
+
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
|
|
188
|
+
* {@link Runtime.logger} property instead.
|
|
189
|
+
*/
|
|
190
|
+
log;
|
|
191
|
+
/**
|
|
192
|
+
* Get the metric meter for this activity with activity-specific tags.
|
|
193
|
+
*
|
|
194
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
195
|
+
* intercepts the `getMetricTags()` method.
|
|
196
|
+
*/
|
|
197
|
+
metricMeter;
|
|
143
198
|
/**
|
|
144
199
|
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
145
200
|
*
|
|
146
201
|
* @ignore
|
|
147
202
|
*/
|
|
148
|
-
constructor(info, cancelled, cancellationSignal, heartbeat, log) {
|
|
149
|
-
/**
|
|
150
|
-
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
151
|
-
*
|
|
152
|
-
* If an Activity times out, then during the next retry, the last value of `details` is available at
|
|
153
|
-
* {@link Info.heartbeatDetails}. This acts as a periodic checkpoint mechanism for the progress of an Activity.
|
|
154
|
-
*
|
|
155
|
-
* If an Activity times out on the final retry (relevant in cases in which {@link RetryPolicy.maximumAttempts} is
|
|
156
|
-
* set), the Activity function call in the Workflow code will throw an {@link ActivityFailure} with the `cause`
|
|
157
|
-
* attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
|
|
158
|
-
* {@link TimeoutFailure.lastHeartbeatDetails}.
|
|
159
|
-
*
|
|
160
|
-
* Calling `heartbeat()` from a Local Activity has no effect.
|
|
161
|
-
*
|
|
162
|
-
* The SDK automatically throttles heartbeat calls to the server with a duration of 80% of the specified activity
|
|
163
|
-
* heartbeat timeout. Throttling behavior may be customized with the `{@link maxHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#maxheartbeatthrottleinterval} and {@link defaultHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#defaultheartbeatthrottleinterval} worker options.
|
|
164
|
-
*
|
|
165
|
-
* Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
|
|
166
|
-
*
|
|
167
|
-
* :warning: Cancellation is not propagated from this function, use {@link cancelled} or {@link cancellationSignal} to
|
|
168
|
-
* subscribe to cancellation notifications.
|
|
169
|
-
*/
|
|
170
|
-
this.heartbeat = (details) => {
|
|
171
|
-
this.heartbeatFn(details);
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Helper function for sleeping in an Activity.
|
|
175
|
-
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
176
|
-
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
|
|
177
|
-
*/
|
|
178
|
-
this.sleep = (ms) => {
|
|
179
|
-
let handle;
|
|
180
|
-
const timer = new Promise((resolve) => {
|
|
181
|
-
handle = setTimeout(resolve, (0, time_1.msToNumber)(ms));
|
|
182
|
-
});
|
|
183
|
-
return Promise.race([this.cancelled.finally(() => clearTimeout(handle)), timer]);
|
|
184
|
-
};
|
|
203
|
+
constructor(info, cancelled, cancellationSignal, heartbeat, log, metricMeter) {
|
|
185
204
|
this.info = info;
|
|
186
205
|
this.cancelled = cancelled;
|
|
187
206
|
this.cancellationSignal = cancellationSignal;
|
|
188
207
|
this.heartbeatFn = heartbeat;
|
|
189
208
|
this.log = log;
|
|
209
|
+
this.metricMeter = metricMeter;
|
|
190
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
|
|
213
|
+
*
|
|
214
|
+
* If an Activity times out, then during the next retry, the last value of `details` is available at
|
|
215
|
+
* {@link Info.heartbeatDetails}. This acts as a periodic checkpoint mechanism for the progress of an Activity.
|
|
216
|
+
*
|
|
217
|
+
* If an Activity times out on the final retry (relevant in cases in which {@link RetryPolicy.maximumAttempts} is
|
|
218
|
+
* set), the Activity function call in the Workflow code will throw an {@link ActivityFailure} with the `cause`
|
|
219
|
+
* attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
|
|
220
|
+
* {@link TimeoutFailure.lastHeartbeatDetails}.
|
|
221
|
+
*
|
|
222
|
+
* Calling `heartbeat()` from a Local Activity has no effect.
|
|
223
|
+
*
|
|
224
|
+
* The SDK automatically throttles heartbeat calls to the server with a duration of 80% of the specified activity
|
|
225
|
+
* heartbeat timeout. Throttling behavior may be customized with the `{@link maxHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#maxheartbeatthrottleinterval} and {@link defaultHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#defaultheartbeatthrottleinterval} worker options.
|
|
226
|
+
*
|
|
227
|
+
* Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
|
|
228
|
+
*
|
|
229
|
+
* :warning: Cancellation is not propagated from this function, use {@link cancelled} or {@link cancellationSignal} to
|
|
230
|
+
* subscribe to cancellation notifications.
|
|
231
|
+
*/
|
|
232
|
+
heartbeat = (details) => {
|
|
233
|
+
this.heartbeatFn(details);
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Helper function for sleeping in an Activity.
|
|
237
|
+
* @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
238
|
+
* @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
|
|
239
|
+
*/
|
|
240
|
+
sleep = (ms) => {
|
|
241
|
+
let handle;
|
|
242
|
+
const timer = new Promise((resolve) => {
|
|
243
|
+
handle = setTimeout(resolve, (0, time_1.msToNumber)(ms));
|
|
244
|
+
});
|
|
245
|
+
return Promise.race([this.cancelled.finally(() => clearTimeout(handle)), timer]);
|
|
246
|
+
};
|
|
191
247
|
}
|
|
192
248
|
exports.Context = Context;
|
|
193
249
|
/**
|
|
@@ -280,4 +336,26 @@ function cancelled() {
|
|
|
280
336
|
function cancellationSignal() {
|
|
281
337
|
return Context.current().cancellationSignal;
|
|
282
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Get the metric meter for the current activity, with activity-specific tags.
|
|
341
|
+
*
|
|
342
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
343
|
+
* intercepts the `getMetricTags()` method.
|
|
344
|
+
*
|
|
345
|
+
* This is a shortcut for `Context.current().metricMeter` (see {@link Context.metricMeter}).
|
|
346
|
+
*/
|
|
347
|
+
exports.metricMeter = {
|
|
348
|
+
createCounter(name, unit, description) {
|
|
349
|
+
return Context.current().metricMeter.createCounter(name, unit, description);
|
|
350
|
+
},
|
|
351
|
+
createHistogram(name, valueType = 'int', unit, description) {
|
|
352
|
+
return Context.current().metricMeter.createHistogram(name, valueType, unit, description);
|
|
353
|
+
},
|
|
354
|
+
createGauge(name, valueType = 'int', unit, description) {
|
|
355
|
+
return Context.current().metricMeter.createGauge(name, valueType, unit, description);
|
|
356
|
+
},
|
|
357
|
+
withTags(tags) {
|
|
358
|
+
return Context.current().metricMeter.withTags(tags);
|
|
359
|
+
},
|
|
360
|
+
};
|
|
283
361
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;;;;;;;;;AA6RH,oCAGC;AAsCD,sBAEC;AAeD,8BAEC;AAWD,8BAEC;AAgBD,gDAEC;AAtXD,uDAAqD;AAErD,sDAAyD;AACzD,sEAAiF;AAEjF,6CAM4B;AAH1B,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAIlB;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,KAAK;CAAG,CAAA;AAAnC,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,yCAA0B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,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC3F,CAAC;IACD,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW;QACpD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACvF,CAAC;IACD,QAAQ,CAAC,IAAI;QACX,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temporalio/activity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0-rc.0",
|
|
4
4
|
"description": "Temporal.io SDK Activity sub-package",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -13,9 +13,12 @@
|
|
|
13
13
|
"author": "Temporal Technologies Inc. <sdk@temporal.io>",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@temporalio/common": "1.
|
|
16
|
+
"@temporalio/common": "1.12.0-rc.0",
|
|
17
17
|
"abort-controller": "^3.0.0"
|
|
18
18
|
},
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">= 18.0.0"
|
|
21
|
+
},
|
|
19
22
|
"bugs": {
|
|
20
23
|
"url": "https://github.com/temporalio/sdk-typescript/issues"
|
|
21
24
|
},
|
|
@@ -32,5 +35,5 @@
|
|
|
32
35
|
"src",
|
|
33
36
|
"lib"
|
|
34
37
|
],
|
|
35
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "3e02f59f5c3edbdd3a4d05bc77c3bee9dbdc1226"
|
|
36
39
|
}
|
package/src/index.ts
CHANGED
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
73
|
-
import { Logger, Duration, LogLevel, LogMetadata } from '@temporalio/common';
|
|
73
|
+
import { Logger, Duration, LogLevel, LogMetadata, MetricMeter, Priority } from '@temporalio/common';
|
|
74
74
|
import { msToNumber } from '@temporalio/common/lib/time';
|
|
75
75
|
import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
|
|
76
76
|
|
|
@@ -90,14 +90,14 @@ export {
|
|
|
90
90
|
*
|
|
91
91
|
* @example
|
|
92
92
|
*
|
|
93
|
-
|
|
93
|
+
* ```ts
|
|
94
94
|
*import { CompleteAsyncError } from '@temporalio/activity';
|
|
95
95
|
*
|
|
96
96
|
*export async function myActivity(): Promise<never> {
|
|
97
97
|
* // ...
|
|
98
98
|
* throw new CompleteAsyncError();
|
|
99
99
|
*}
|
|
100
|
-
|
|
100
|
+
* ```
|
|
101
101
|
*/
|
|
102
102
|
@SymbolBasedInstanceOfError('CompleteAsyncError')
|
|
103
103
|
export class CompleteAsyncError extends Error {}
|
|
@@ -198,6 +198,10 @@ export interface Info {
|
|
|
198
198
|
* For Local Activities, this is set to the Workflow's Task Queue.
|
|
199
199
|
*/
|
|
200
200
|
readonly taskQueue: string;
|
|
201
|
+
/**
|
|
202
|
+
* Priority of this activity
|
|
203
|
+
*/
|
|
204
|
+
readonly priority?: Priority;
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
/**
|
|
@@ -277,6 +281,14 @@ export class Context {
|
|
|
277
281
|
*/
|
|
278
282
|
public log: Logger;
|
|
279
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Get the metric meter for this activity with activity-specific tags.
|
|
286
|
+
*
|
|
287
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
288
|
+
* intercepts the `getMetricTags()` method.
|
|
289
|
+
*/
|
|
290
|
+
public readonly metricMeter: MetricMeter;
|
|
291
|
+
|
|
280
292
|
/**
|
|
281
293
|
* **Not** meant to instantiated by Activity code, used by the worker.
|
|
282
294
|
*
|
|
@@ -287,13 +299,15 @@ export class Context {
|
|
|
287
299
|
cancelled: Promise<never>,
|
|
288
300
|
cancellationSignal: AbortSignal,
|
|
289
301
|
heartbeat: (details?: any) => void,
|
|
290
|
-
log: Logger
|
|
302
|
+
log: Logger,
|
|
303
|
+
metricMeter: MetricMeter
|
|
291
304
|
) {
|
|
292
305
|
this.info = info;
|
|
293
306
|
this.cancelled = cancelled;
|
|
294
307
|
this.cancellationSignal = cancellationSignal;
|
|
295
308
|
this.heartbeatFn = heartbeat;
|
|
296
309
|
this.log = log;
|
|
310
|
+
this.metricMeter = metricMeter;
|
|
297
311
|
}
|
|
298
312
|
|
|
299
313
|
/**
|
|
@@ -430,3 +444,26 @@ export function cancelled(): Promise<never> {
|
|
|
430
444
|
export function cancellationSignal(): AbortSignal {
|
|
431
445
|
return Context.current().cancellationSignal;
|
|
432
446
|
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Get the metric meter for the current activity, with activity-specific tags.
|
|
450
|
+
*
|
|
451
|
+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
|
|
452
|
+
* intercepts the `getMetricTags()` method.
|
|
453
|
+
*
|
|
454
|
+
* This is a shortcut for `Context.current().metricMeter` (see {@link Context.metricMeter}).
|
|
455
|
+
*/
|
|
456
|
+
export const metricMeter: MetricMeter = {
|
|
457
|
+
createCounter(name, unit, description) {
|
|
458
|
+
return Context.current().metricMeter.createCounter(name, unit, description);
|
|
459
|
+
},
|
|
460
|
+
createHistogram(name, valueType = 'int', unit, description) {
|
|
461
|
+
return Context.current().metricMeter.createHistogram(name, valueType, unit, description);
|
|
462
|
+
},
|
|
463
|
+
createGauge(name, valueType = 'int', unit, description) {
|
|
464
|
+
return Context.current().metricMeter.createGauge(name, valueType, unit, description);
|
|
465
|
+
},
|
|
466
|
+
withTags(tags) {
|
|
467
|
+
return Context.current().metricMeter.withTags(tags);
|
|
468
|
+
},
|
|
469
|
+
};
|