Skip to content

Commit 6d9d2e0

Browse files
committed
Self review
1 parent de1f658 commit 6d9d2e0

File tree

16 files changed

+180
-201
lines changed

16 files changed

+180
-201
lines changed

packages/activity/src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ export class Context {
284284
/**
285285
* Get the metric meter for this activity with activity-specific tags.
286286
*
287-
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
288-
* `getMetricsTags()` method.
287+
* To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
288+
* intercepts the `getMetricTags()` method.
289289
*/
290290
public readonly metricMeter: MetricMeter;
291291

@@ -447,6 +447,11 @@ export function cancellationSignal(): AbortSignal {
447447

448448
/**
449449
* 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}).
450455
*/
451456
export const metricMeter: MetricMeter = {
452457
createCounter(name, unit, description) {

packages/common/src/metrics.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export type MetricTagsOrFunc = MetricTags | (() => MetricTags);
231231
* @internal
232232
* @hidden
233233
*/
234-
export class MetricsMeterWithComposedTags implements MetricMeter {
234+
export class MetricMeterWithComposedTags implements MetricMeter {
235235
/**
236236
* Return a {@link MetricMeter} that adds tags before delegating calls to a parent meter.
237237
*
@@ -244,20 +244,20 @@ export class MetricsMeterWithComposedTags implements MetricMeter {
244244
* @param meter The parent meter to delegate calls to.
245245
* @param tagsOrFunc New tags may either be specified statically as a delta object, or as a function
246246
* evaluated every time a metric is recorded that will return a delta object.
247-
* @param force if `true`, then a `MetricsMeterWithComposedTags` will be created even if there
247+
* @param force if `true`, then a `MetricMeterWithComposedTags` will be created even if there
248248
* is no tags to add. This is useful to add tags support to an underlying meter
249249
* implementation that does not support tags directly.
250250
*/
251251
public static compose(meter: MetricMeter, tagsOrFunc: MetricTagsOrFunc, force: boolean = false): MetricMeter {
252-
if (meter instanceof MetricsMeterWithComposedTags) {
252+
if (meter instanceof MetricMeterWithComposedTags) {
253253
const contributors = appendToChain(meter.contributors, tagsOrFunc);
254254
// If the new contributor results in no actual change to the chain, then we don't need a new meter
255255
if (contributors === undefined && !force) return meter;
256-
return new MetricsMeterWithComposedTags(meter.parentMeter, contributors ?? []);
256+
return new MetricMeterWithComposedTags(meter.parentMeter, contributors ?? []);
257257
} else {
258258
const contributors = appendToChain(undefined, tagsOrFunc);
259259
if (contributors === undefined && !force) return meter;
260-
return new MetricsMeterWithComposedTags(meter, contributors ?? []);
260+
return new MetricMeterWithComposedTags(meter, contributors ?? []);
261261
}
262262
}
263263

@@ -292,7 +292,7 @@ export class MetricsMeterWithComposedTags implements MetricMeter {
292292
}
293293

294294
withTags(tags: MetricTags): MetricMeter {
295-
return MetricsMeterWithComposedTags.compose(this, tags);
295+
return MetricMeterWithComposedTags.compose(this, tags);
296296
}
297297
}
298298

packages/core-bridge/src/metrics.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use temporal_sdk_core::api::telemetry::metrics::{
1616
};
1717

1818
use bridge_macros::js_function;
19-
use temporal_sdk_core::CoreRuntime;
2019

2120
use crate::helpers::{
2221
BridgeError, BridgeResult, JsonString, MutableFinalize, OpaqueInboundHandle,
@@ -44,41 +43,31 @@ pub fn init(cx: &mut neon::prelude::ModuleContext) -> neon::prelude::NeonResult<
4443
}
4544

4645
pub struct Counter {
47-
// We only hang on to Runtime to ensure proper shutdown sequencing
48-
// core_runtime: Arc<CoreRuntime>,
4946
pub(crate) meter: TemporalMeter,
5047
pub(crate) counter: Arc<dyn CoreCounter>,
5148
}
5249

5350
impl MutableFinalize for Counter {}
5451

5552
pub struct Histogram {
56-
// We only hang on to Runtime to ensure proper shutdown sequencing
57-
// core_runtime: Arc<CoreRuntime>,
5853
pub(crate) meter: TemporalMeter,
5954
pub(crate) histogram: Arc<dyn CoreHistogram>,
6055
}
6156
impl MutableFinalize for Histogram {}
6257

6358
pub struct HistogramF64 {
64-
// We only hang on to Runtime to ensure proper shutdown sequencing
65-
// core_runtime: Arc<CoreRuntime>,
6659
pub(crate) meter: TemporalMeter,
6760
pub(crate) histogram: Arc<dyn CoreHistogramF64>,
6861
}
6962
impl MutableFinalize for HistogramF64 {}
7063

7164
pub struct Gauge {
72-
// We only hang on to Runtime to ensure proper shutdown sequencing
73-
// core_runtime: Arc<CoreRuntime>,
7465
pub(crate) meter: TemporalMeter,
7566
pub(crate) gauge: Arc<dyn CoreGauge>,
7667
}
7768
impl MutableFinalize for Gauge {}
7869

7970
pub struct GaugeF64 {
80-
// We only hang on to Runtime to ensure proper shutdown sequencing
81-
// core_runtime: Arc<CoreRuntime>,
8271
pub(crate) meter: TemporalMeter,
8372
pub(crate) gauge: Arc<dyn CoreGaugeF64>,
8473
}
@@ -135,11 +124,7 @@ pub fn new_metric_counter(
135124
.context("Failed to build metric parameters")?,
136125
);
137126

138-
Ok(OpaqueOutboundHandle::new(Counter {
139-
// core_runtime,
140-
meter,
141-
counter,
142-
}))
127+
Ok(OpaqueOutboundHandle::new(Counter { meter, counter }))
143128
}
144129

145130
#[js_function]
@@ -166,11 +151,7 @@ pub fn new_metric_histogram(
166151
.context("Failed to build metric parameters")?,
167152
);
168153

169-
Ok(OpaqueOutboundHandle::new(Histogram {
170-
// core_runtime,
171-
meter,
172-
histogram,
173-
}))
154+
Ok(OpaqueOutboundHandle::new(Histogram { meter, histogram }))
174155
}
175156

176157
#[js_function]
@@ -197,11 +178,7 @@ pub fn new_metric_histogram_f64(
197178
.context("Failed to build metric parameters")?,
198179
);
199180

200-
Ok(OpaqueOutboundHandle::new(HistogramF64 {
201-
// core_runtime,
202-
meter,
203-
histogram,
204-
}))
181+
Ok(OpaqueOutboundHandle::new(HistogramF64 { meter, histogram }))
205182
}
206183

207184
#[js_function]
@@ -228,11 +205,7 @@ pub fn new_metric_gauge(
228205
.context("Failed to build metric parameters")?,
229206
);
230207

231-
Ok(OpaqueOutboundHandle::new(Gauge {
232-
// core_runtime,
233-
meter,
234-
gauge,
235-
}))
208+
Ok(OpaqueOutboundHandle::new(Gauge { meter, gauge }))
236209
}
237210

238211
#[js_function]
@@ -259,11 +232,7 @@ pub fn new_metric_gauge_f64(
259232
.context("Failed to build metric parameters")?,
260233
);
261234

262-
Ok(OpaqueOutboundHandle::new(GaugeF64 {
263-
// core_runtime,
264-
meter,
265-
gauge,
266-
}))
235+
Ok(OpaqueOutboundHandle::new(GaugeF64 { meter, gauge }))
267236
}
268237

269238
#[js_function]

packages/core-bridge/ts/native.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -377,27 +377,27 @@ type LogEntryMetadata = {
377377
// Custom Metrics
378378
////////////////////////////////////////////////////////////////////////////////////////////////////
379379

380-
export interface NativeMetricMeter {
380+
export interface MetricMeter {
381381
type: 'metric-meter';
382382
}
383383

384-
export interface NativeMetricCounter {
384+
export interface MetricCounter {
385385
type: 'metric-counter';
386386
}
387387

388-
export interface NativeMetricHistogram {
388+
export interface MetricHistogram {
389389
type: 'metric-histogram';
390390
}
391391

392-
export interface NativeMetricHistogramF64 {
392+
export interface MetricHistogramF64 {
393393
type: 'metric-histogram-f64';
394394
}
395395

396-
export interface NativeMetricGauge {
396+
export interface MetricGauge {
397397
type: 'metric-gauge';
398398
}
399399

400-
export interface NativeMetricGaugeF64 {
400+
export interface MetricGaugeF64 {
401401
type: 'metric-gauge-f64';
402402
}
403403

@@ -408,62 +408,57 @@ export declare function newMetricCounter(
408408
name: string,
409409
unit: string,
410410
description: string
411-
): NativeMetricCounter;
411+
): MetricCounter;
412412

413413
export declare function newMetricHistogram(
414414
runtime: Runtime,
415415
name: string,
416416
unit: string,
417417
description: string
418-
): NativeMetricHistogram;
418+
): MetricHistogram;
419419

420420
export declare function newMetricHistogramF64(
421421
runtime: Runtime,
422422
name: string,
423423
unit: string,
424424
description: string
425-
): NativeMetricHistogramF64;
425+
): MetricHistogramF64;
426426

427-
export declare function newMetricGauge(
428-
runtime: Runtime,
429-
name: string,
430-
unit: string,
431-
description: string
432-
): NativeMetricGauge;
427+
export declare function newMetricGauge(runtime: Runtime, name: string, unit: string, description: string): MetricGauge;
433428

434429
export declare function newMetricGaugeF64(
435430
runtime: Runtime,
436431
name: string,
437432
unit: string,
438433
description: string
439-
): NativeMetricGaugeF64;
434+
): MetricGaugeF64;
440435

441436
export declare function addMetricCounterValue(
442-
counter: NativeMetricCounter,
437+
counter: MetricCounter,
443438
value: number,
444439
attrs: JsonString<MetricAttributes>
445440
): void;
446441

447442
export declare function recordMetricHistogramValue(
448-
histogram: NativeMetricHistogram,
443+
histogram: MetricHistogram,
449444
value: number,
450445
attrs: JsonString<MetricAttributes>
451446
): void;
452447

453448
export declare function recordMetricHistogramF64Value(
454-
histogram: NativeMetricHistogramF64,
449+
histogram: MetricHistogramF64,
455450
value: number,
456451
attrs: JsonString<MetricAttributes>
457452
): void;
458453

459454
export declare function setMetricGaugeValue(
460-
gauge: NativeMetricGauge,
455+
gauge: MetricGauge,
461456
value: number,
462457
attrs: JsonString<MetricAttributes>
463458
): void;
464459

465460
export declare function setMetricGaugeF64Value(
466-
gauge: NativeMetricGaugeF64,
461+
gauge: MetricGaugeF64,
467462
value: number,
468463
attrs: JsonString<MetricAttributes>
469464
): void;

packages/proto/scripts/compile-proto.js

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,8 @@ const pbts = require('protobufjs-cli/pbts');
99
const outputDir = resolve(__dirname, '../protos');
1010
const jsOutputFile = resolve(outputDir, 'json-module.js');
1111
const tempFile = resolve(outputDir, 'temp.js');
12-
const protoBaseDir = resolve(__dirname, '../../core-bridge/sdk-core/sdk-core-protos/protos');
1312

14-
const coreProtoPath = resolve(protoBaseDir, 'local/temporal/sdk/core/core_interface.proto');
15-
const workflowServiceProtoPath = resolve(protoBaseDir, 'api_upstream/temporal/api/workflowservice/v1/service.proto');
16-
const operatorServiceProtoPath = resolve(protoBaseDir, 'api_upstream/temporal/api/operatorservice/v1/service.proto');
17-
const cloudServiceProtoPath = resolve(
18-
protoBaseDir,
19-
'api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto'
20-
);
21-
const errorDetailsProtoPath = resolve(protoBaseDir, 'api_upstream/temporal/api/errordetails/v1/message.proto');
22-
const workflowMetadataProtoPath = resolve(protoBaseDir, 'api_upstream/temporal/api/sdk/v1/workflow_metadata.proto');
23-
const testServiceRRProtoPath = resolve(
24-
protoBaseDir,
25-
'testsrv_upstream/temporal/api/testservice/v1/request_response.proto'
26-
);
27-
const testServiceProtoPath = resolve(protoBaseDir, 'testsrv_upstream/temporal/api/testservice/v1/service.proto');
28-
const healthServiceProtoPath = resolve(protoBaseDir, 'grpc/health/v1/health.proto');
29-
const googleRpcStatusProtoPath = resolve(protoBaseDir, 'google/rpc/status.proto');
13+
const protoBaseDir = resolve(__dirname, '../../core-bridge/sdk-core/sdk-core-protos/protos');
3014

3115
function mtime(path) {
3216
try {
@@ -40,28 +24,15 @@ function mtime(path) {
4024
}
4125

4226
async function compileProtos(dtsOutputFile, ...args) {
43-
// Use --root to avoid conflicting with user's root
44-
// and to avoid this error: https://github.com/protobufjs/protobuf.js/issues/1114
4527
const pbjsArgs = [
46-
...args,
47-
'--wrap',
48-
'commonjs',
28+
...['--wrap', 'commonjs'],
4929
'--force-long',
5030
'--no-verify',
5131
'--alt-comment',
52-
'--root',
53-
'__temporal',
54-
resolve(require.resolve('protobufjs'), '../google/protobuf/descriptor.proto'),
55-
coreProtoPath,
56-
workflowServiceProtoPath,
57-
operatorServiceProtoPath,
58-
cloudServiceProtoPath,
59-
errorDetailsProtoPath,
60-
workflowMetadataProtoPath,
61-
testServiceRRProtoPath,
62-
testServiceProtoPath,
63-
healthServiceProtoPath,
64-
googleRpcStatusProtoPath,
32+
// Use --root to avoid conflicting with user's root
33+
// and to avoid this error: https://github.com/protobufjs/protobuf.js/issues/1114
34+
...['--root', '__temporal'],
35+
...args,
6536
];
6637

6738
console.log(`Creating protobuf JS definitions`);
@@ -101,14 +72,32 @@ async function main() {
10172
return;
10273
}
10374

104-
await compileProtos(
105-
resolve(outputDir, 'root.d.ts'),
106-
'--path',
75+
const rootDirs = [
10776
resolve(protoBaseDir, 'api_upstream'),
108-
'--path',
77+
resolve(protoBaseDir, 'testsrv_upstream'),
10978
resolve(protoBaseDir, 'local'),
110-
'--path',
111-
resolve(protoBaseDir, 'api_cloud_upstream')
79+
resolve(protoBaseDir, 'api_cloud_upstream'),
80+
protoBaseDir, // 'grpc' and 'google' are directly under protoBaseDir
81+
];
82+
83+
const entrypoints = [
84+
'temporal/sdk/core/core_interface.proto',
85+
'temporal/api/workflowservice/v1/service.proto',
86+
'temporal/api/operatorservice/v1/service.proto',
87+
'temporal/api/cloud/cloudservice/v1/service.proto',
88+
'temporal/api/errordetails/v1/message.proto',
89+
'temporal/api/sdk/v1/workflow_metadata.proto',
90+
'temporal/api/testservice/v1/request_response.proto',
91+
'temporal/api/testservice/v1/service.proto',
92+
'grpc/health/v1/health.proto',
93+
'google/rpc/status.proto',
94+
];
95+
96+
await compileProtos(
97+
resolve(outputDir, 'root.d.ts'),
98+
// Make sure to include all
99+
...rootDirs.flatMap((dir) => ['--path', dir]),
100+
...entrypoints
112101
);
113102

114103
console.log('Done');

0 commit comments

Comments
 (0)