Skip to content

Commit 0ce9b91

Browse files
perf: server monitor add more tags for timing/counter event (#7968)
1 parent 4d11075 commit 0ce9b91

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

.changeset/silent-tables-dress.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/types': patch
3+
'@modern-js/server-core': patch
4+
---
5+
6+
perf: server monitor add more tags for timing/counter event
7+
perf: server monitor 为 timing/couter 事件添加更多的 tags

packages/server/core/src/plugins/monitors.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,33 @@ function createMonitors(): Monitors {
5252
log('trace', message, args);
5353
},
5454

55-
timing(name: string, dur: number, desc?: string, ...args: any[]) {
55+
timing(
56+
name: string,
57+
dur: number,
58+
desc?: string,
59+
tags?: Record<string, any>,
60+
...args: any[]
61+
) {
5662
const event: TimingEvent = {
5763
type: 'timing',
5864
payload: {
5965
name,
6066
dur,
6167
desc,
68+
tags,
6269
args,
6370
},
6471
};
6572
coreMonitors.forEach(monitor => monitor(event));
6673
},
6774

68-
counter(name: string, ...args: any[]) {
75+
counter(name: string, tags?: Record<string, any>, ...args: any[]) {
6976
const event: CounterEvent = {
7077
type: 'counter',
7178
payload: {
7279
name,
7380
args,
81+
tags,
7482
},
7583
};
7684
coreMonitors.forEach(monitor => monitor(event));

packages/toolkit/types/server/monitor.d.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface TimingEvent {
1616
name: string;
1717
dur: number;
1818
desc?: string;
19+
tags?: Record<string, any>;
1920
args?: any[];
2021
};
2122
}
@@ -24,6 +25,7 @@ export interface CounterEvent {
2425
type: 'counter';
2526
payload: {
2627
name: string;
28+
tags?: Record<string, any>;
2729
args?: any[];
2830
};
2931
}
@@ -43,6 +45,12 @@ export interface Monitors {
4345
trace(message: string, ...args: any[]): void;
4446

4547
// 打点事件
46-
timing(name: string, dur: number, ...args: any[]): void;
47-
counter(name: string, ...args: any[]): void;
48+
timing(
49+
name: string,
50+
dur: number,
51+
desc?: string,
52+
tags?: Record<string, any>,
53+
...args: any[]
54+
): void;
55+
counter(name: string, tags?: Record<string, any>, ...args: any[]): void;
4856
}

0 commit comments

Comments
 (0)