-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathhub.ts
More file actions
173 lines (153 loc) · 4.46 KB
/
Copy pathhub.ts
File metadata and controls
173 lines (153 loc) · 4.46 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import type {
Client,
CustomSamplingContext,
EventHint,
Hub,
Integration,
IntegrationClass,
Severity,
SeverityLevel,
TransactionContext,
} from '@sentry/types';
import { endSession, startSession } from '@sentry/core';
import {
addBreadcrumb,
captureEvent,
configureScope,
getClient,
getCurrentScope,
lastEventId,
setContext,
setExtra,
setExtras,
setTag,
setTags,
setUser,
withScope,
} from './api';
import { callExtensionMethod, getGlobalCarrier } from './globals';
import type { Scope } from './scope';
import { getIsolationScope } from './scope';
import type { SentryCarrier } from './types';
/** Ensure the global hub is our proxied hub. */
export function setupGlobalHub(): void {
const carrier = getGlobalCarrier();
carrier.hub = getCurrentHub();
}
/**
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
*/
// eslint-disable-next-line deprecation/deprecation
export function getCurrentHub(): Hub {
return {
isOlderThan(_version: number): boolean {
return false;
},
bindClient(client: Client): void {
const scope = getCurrentScope();
scope.setClient(client);
},
pushScope(): Scope {
// TODO: This does not work and is actually deprecated
return getCurrentScope();
},
popScope(): boolean {
// TODO: This does not work and is actually deprecated
return false;
},
withScope,
getClient,
getScope: getCurrentScope,
getIsolationScope,
captureException: (exception: unknown, hint?: EventHint) => {
return getCurrentScope().captureException(exception, hint);
},
captureMessage: (
message: string,
// eslint-disable-next-line deprecation/deprecation
level?: Severity | SeverityLevel,
hint?: EventHint,
) => {
return getCurrentScope().captureMessage(message, level, hint);
},
captureEvent,
lastEventId,
addBreadcrumb,
setUser,
setTags,
setTag,
setExtra,
setExtras,
setContext,
// eslint-disable-next-line deprecation/deprecation
configureScope: configureScope,
// eslint-disable-next-line deprecation/deprecation
run(callback: (hub: Hub) => void): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return withScope(() => callback(this as any));
},
getIntegration<T extends Integration>(integration: IntegrationClass<T>): T | null {
// eslint-disable-next-line deprecation/deprecation
return getClient().getIntegration(integration);
},
traceHeaders(): { [key: string]: string } {
return callExtensionMethod<{ [key: string]: string }>(this, 'traceHeaders');
},
startTransaction(
_context: TransactionContext,
_customSamplingContext?: CustomSamplingContext,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any {
// eslint-disable-next-line no-console
console.warn('startTransaction is a noop in @sentry/node-experimental. Use `startSpan` instead.');
// We return an object here as hub.ts checks for the result of this
// and renders a different warning if this is empty
return {};
},
startSession,
endSession,
captureSession(endSession?: boolean): void {
// both send the update and pull the session from the scope
if (endSession) {
// eslint-disable-next-line deprecation/deprecation
return this.endSession();
}
// only send the update
_sendSessionUpdate();
},
shouldSendDefaultPii(): boolean {
const client = getClient();
const options = client.getOptions();
return Boolean(options.sendDefaultPii);
},
};
}
/**
* Replaces the current main hub with the passed one on the global object
*
* @returns The old replaced hub
*/
// eslint-disable-next-line deprecation/deprecation
export function makeMain(hub: Hub): Hub {
// eslint-disable-next-line no-console
console.warn('makeMain is a noop in @sentry/node-experimental. Use `setCurrentClient` instead.');
return hub;
}
/**
* Sends the current Session on the scope
*/
function _sendSessionUpdate(): void {
const scope = getCurrentScope();
const client = getClient();
const session = scope.getSession();
if (session && client.captureSession) {
client.captureSession(session);
}
}
/**
* Set a mocked hub on the current carrier.
*/
export function setLegacyHubOnCarrier(carrier: SentryCarrier): boolean {
carrier.hub = getCurrentHub();
return true;
}