-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathclient.ts
More file actions
79 lines (67 loc) · 2.24 KB
/
client.ts
File metadata and controls
79 lines (67 loc) · 2.24 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
import type { ServerRuntimeClientOptions } from '@sentry/core';
import { _INTERNAL_flushLogsBuffer, SDK_VERSION, ServerRuntimeClient } from '@sentry/core';
import type { DenoClientOptions } from './types';
function getHostName(): string | undefined {
// Deno.permissions.querySync is not available on Deno Deploy
if (!Deno.permissions.querySync) {
return undefined;
}
const result = Deno.permissions.querySync({ name: 'sys', kind: 'hostname' });
return result.state === 'granted' ? Deno.hostname() : undefined;
}
/**
* The Sentry Deno SDK Client.
*
* @see DenoClientOptions for documentation on configuration options.
* @see SentryClient for usage documentation.
*/
export class DenoClient extends ServerRuntimeClient<DenoClientOptions> {
private _logOnExitFlushListener: (() => void) | undefined;
/**
* Creates a new Deno SDK instance.
* @param options Configuration options for this SDK.
*/
public constructor(options: DenoClientOptions) {
options._metadata = options._metadata || {};
options._metadata.sdk = options._metadata.sdk || {
name: 'sentry.javascript.deno',
packages: [
{
name: 'denoland:sentry',
version: SDK_VERSION,
},
],
version: SDK_VERSION,
};
const serverName = options.serverName || getHostName();
const clientOptions: ServerRuntimeClientOptions = {
...options,
platform: 'javascript',
runtime: { name: 'deno', version: Deno.version.deno },
serverName,
};
super(clientOptions);
if (this.getOptions().enableLogs) {
this._logOnExitFlushListener = () => {
_INTERNAL_flushLogsBuffer(this);
};
if (serverName) {
this.on('beforeCaptureLog', log => {
log.attributes = {
...log.attributes,
'server.address': serverName,
};
});
}
globalThis.addEventListener('unload', this._logOnExitFlushListener);
}
}
/** @inheritDoc */
// @ts-expect-error - PromiseLike is a subset of Promise
public async close(timeout?: number | undefined): PromiseLike<boolean> {
if (this._logOnExitFlushListener) {
globalThis.removeEventListener('unload', this._logOnExitFlushListener);
}
return super.close(timeout);
}
}