Skip to content

Commit 6862264

Browse files
committed
optimise createCallstack
+ make `traceId` shorter (using sha256)
1 parent 4d0d8c3 commit 6862264

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
"typescript": "^5.5.2",
2424
"webpack": "5.92.1",
2525
"webpack-cli": "5.1.4"
26+
},
27+
"dependencies": {
28+
"js-sha256": "^0.11.0"
2629
}
2730
}

pnpm-lock.yaml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-monitor-cs-main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const eachSecond = new Timer(
4747
{ interval: true }
4848
);
4949
const tick = new Timer(
50-
() => {
50+
function apiMonitorPostMetric() {
5151
meanExecutionTime.add(tick.executionTime);
5252
// adaptive update-frequency
5353
if (tick.executionTime < 3) {

src/api/wrappers.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@/api/const.ts';
1414
import { TAG_EXCEPTION, cloneObjectSafely } from '@/api/clone.ts';
1515
import type { TPanelVisibilityMap } from '@/api/settings.ts';
16+
import { sha256 } from 'js-sha256';
1617

1718
export type TCallstack = {
1819
name: string;
@@ -74,8 +75,9 @@ function createCallstack(e: Error): TCallstack {
7475
}
7576
}
7677

77-
for (let i = 1, I = arr.length; i < I; i++) {
78-
let v = arr[i];
78+
// loop from the end, excluding error name and self trace
79+
for (let n = arr.length - 1; n > 1; n--) {
80+
let v = arr[n];
7981
v = v.replace(REGEX_STACKTRACE_PREFIX, '');
8082
const link = v.replace(REGEX_STACKTRACE_LINK, '$1').trim();
8183

@@ -98,11 +100,15 @@ function createCallstack(e: Error): TCallstack {
98100

99101
return rv;
100102
}
103+
101104
function createTraceId(trace: TCallstack) {
102-
return trace
103-
.reverse()
104-
.map((v) => v.link)
105-
.join('');
105+
const joinedLinks = trace.map((v) => v.link).join('');
106+
107+
if (joinedLinks.length > 64) {
108+
return sha256(joinedLinks);
109+
}
110+
111+
return joinedLinks;
106112
}
107113

108114
export class Wrapper {

0 commit comments

Comments
 (0)