Skip to content

Commit

Permalink
fix(node): Catch os.uptime() throwing because of EPERM (#8206)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed May 24, 2023
1 parent a663a9c commit 55ff2a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/node/src/integrations/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,17 @@ function getAppContext(): AppContext {
export function getDeviceContext(deviceOpt: DeviceContextOptions | true): DeviceContext {
const device: DeviceContext = {};

// Sometimes os.uptime() throws due to lacking permissions: https://github.com/getsentry/sentry-javascript/issues/8202
let uptime;
try {
uptime = os.uptime && os.uptime();
} catch (e) {
// noop
}

// os.uptime or its return value seem to be undefined in certain environments (e.g. Azure functions).
// Hence, we only set boot time, if we get a valid uptime value.
// @see https://github.com/getsentry/sentry-javascript/issues/5856
const uptime = os.uptime && os.uptime();
if (typeof uptime === 'number') {
device.boot_time = new Date(Date.now() - uptime * 1000).toISOString();
}
Expand Down

0 comments on commit 55ff2a1

Please sign in to comment.