Skip to content

Commit

Permalink
Replace legacy process.hrtime with process.hrtime.bigint (#7)
Browse files Browse the repository at this point in the history
* Replace legacy api with current one

* Tweak comment
  • Loading branch information
niwsa authored Apr 13, 2023
1 parent 27342c7 commit 500d999
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/instruments/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type InstrumentOperationParams = {
*/

async function instrument({ meter, name, delegate, instrumentAttributes }: InstrumentOperationParams) {
const start = process.hrtime();
const start = process.hrtime.bigint();
try {
return await delegate();
} catch (err) {
Expand All @@ -31,12 +31,12 @@ async function instrument({ meter, name, delegate, instrumentAttributes }: Instr
});
throw err;
} finally {
const elapsed = process.hrtime(start);
const elapsedNanos = elapsed[0] * 1000000000 + elapsed[1];
const end = process.hrtime.bigint();
const elapsedNanos = end - start;
recordTimer({
meter,
name: 'function.executionTime',
val: elapsedNanos,
val: Number(elapsedNanos) /** convert bigint to number */,
timerAttributes: { function: name, ...instrumentAttributes },
});
}
Expand Down

0 comments on commit 500d999

Please sign in to comment.