Skip to content

Commit 500d999

Browse files
authored
Replace legacy process.hrtime with process.hrtime.bigint (#7)
* Replace legacy api with current one * Tweak comment
1 parent 27342c7 commit 500d999

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/instruments/instrument.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type InstrumentOperationParams = {
2020
*/
2121

2222
async function instrument({ meter, name, delegate, instrumentAttributes }: InstrumentOperationParams) {
23-
const start = process.hrtime();
23+
const start = process.hrtime.bigint();
2424
try {
2525
return await delegate();
2626
} catch (err) {
@@ -31,12 +31,12 @@ async function instrument({ meter, name, delegate, instrumentAttributes }: Instr
3131
});
3232
throw err;
3333
} finally {
34-
const elapsed = process.hrtime(start);
35-
const elapsedNanos = elapsed[0] * 1000000000 + elapsed[1];
34+
const end = process.hrtime.bigint();
35+
const elapsedNanos = end - start;
3636
recordTimer({
3737
meter,
3838
name: 'function.executionTime',
39-
val: elapsedNanos,
39+
val: Number(elapsedNanos) /** convert bigint to number */,
4040
timerAttributes: { function: name, ...instrumentAttributes },
4141
});
4242
}

0 commit comments

Comments
 (0)