Skip to content

Commit 55ff2a1

Browse files
authored
fix(node): Catch os.uptime() throwing because of EPERM (#8206)
1 parent a663a9c commit 55ff2a1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/node/src/integrations/context.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,17 @@ function getAppContext(): AppContext {
195195
export function getDeviceContext(deviceOpt: DeviceContextOptions | true): DeviceContext {
196196
const device: DeviceContext = {};
197197

198+
// Sometimes os.uptime() throws due to lacking permissions: https://github.com/getsentry/sentry-javascript/issues/8202
199+
let uptime;
200+
try {
201+
uptime = os.uptime && os.uptime();
202+
} catch (e) {
203+
// noop
204+
}
205+
198206
// os.uptime or its return value seem to be undefined in certain environments (e.g. Azure functions).
199207
// Hence, we only set boot time, if we get a valid uptime value.
200208
// @see https://github.com/getsentry/sentry-javascript/issues/5856
201-
const uptime = os.uptime && os.uptime();
202209
if (typeof uptime === 'number') {
203210
device.boot_time = new Date(Date.now() - uptime * 1000).toISOString();
204211
}

0 commit comments

Comments
 (0)