-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcontext.ts
77 lines (70 loc) · 1.76 KB
/
context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { defineIntegration } from '@sentry/core';
import type { Event, IntegrationFn } from '@sentry/core';
const INTEGRATION_NAME = 'DenoContext';
function getOSName(): string {
switch (Deno.build.os) {
case 'darwin':
return 'macOS';
case 'linux':
return 'Linux';
case 'windows':
return 'Windows';
default:
return Deno.build.os;
}
}
async function getOSRelease(): Promise<string | undefined> {
return (await Deno.permissions.query({ name: 'sys', kind: 'osRelease' })).state === 'granted'
? Deno.osRelease()
: undefined;
}
async function addDenoRuntimeContext(event: Event): Promise<Event> {
event.contexts = {
...{
app: {
app_start_time: new Date(Date.now() - performance.now()).toISOString(),
},
device: {
arch: Deno.build.arch,
// eslint-disable-next-line no-restricted-globals
processor_count: navigator.hardwareConcurrency,
},
os: {
name: getOSName(),
version: await getOSRelease(),
},
v8: {
name: 'v8',
version: Deno.version.v8,
},
typescript: {
name: 'TypeScript',
version: Deno.version.typescript,
},
},
...event.contexts,
};
return event;
}
const _denoContextIntegration = (() => {
return {
name: INTEGRATION_NAME,
processEvent(event) {
return addDenoRuntimeContext(event);
},
};
}) satisfies IntegrationFn;
/**
* Adds Deno related context to events. This includes contexts about app, device, os, v8, and TypeScript.
*
* Enabled by default in the Deno SDK.
*
* ```js
* Sentry.init({
* integrations: [
* Sentry.denoContextIntegration(),
* ],
* })
* ```
*/
export const denoContextIntegration = defineIntegration(_denoContextIntegration);