Repository navigation
Expand file tree
/
Copy pathcontext.ts
More file actions
90 lines (81 loc) · 2.57 KB
/
Copy pathcontext.ts
File metadata and controls
90 lines (81 loc) · 2.57 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
import type { IntegrationFn } from '@sentry/core';
import { defineIntegration, safeSetSpanJSONAttributes } from '@sentry/core';
const INTEGRATION_NAME = 'DenoContext' as const;
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;
}
const _denoContextIntegration = (() => {
const appStartTime = new Date(Date.now() - performance.now()).toISOString();
const osName = getOSName();
const arch = Deno.build.arch;
// eslint-disable-next-line no-restricted-globals
const processorCount = navigator.hardwareConcurrency;
const v8Version = Deno.version.v8;
const tsVersion = Deno.version.typescript;
const cachedContext = {
app: { app_start_time: appStartTime },
device: { arch, processor_count: processorCount },
os: { name: osName } as { name: string; version?: string },
v8: { name: 'v8', version: v8Version },
typescript: { name: 'TypeScript', version: tsVersion },
};
const cachedSpanAttributes: Record<string, unknown> = {
'app.start_time': appStartTime,
// Convention uses 'device.archs' (string[]), but array attributes are not yet serialized.
// Once array serialization lands, this will start appearing on spans automatically.
'device.archs': [arch],
'device.processor_count': processorCount,
'os.name': osName,
'process.runtime.engine.name': 'v8',
'process.runtime.engine.version': v8Version,
};
getOSRelease()
.then(release => {
cachedContext.os.version = release;
cachedSpanAttributes['os.version'] = release;
})
.catch(() => {
// Ignore - os.version will be undefined
});
return {
name: INTEGRATION_NAME,
processEvent(event) {
event.contexts = {
...cachedContext,
...event.contexts,
};
return event;
},
processSegmentSpan(span) {
safeSetSpanJSONAttributes(span, cachedSpanAttributes);
},
};
}) 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);