Skip to content

Commit b76ef3c

Browse files
committed
ref: Remove makeMain export
Instead, use a combination of `setCurrentClient()` and `client.init()`
1 parent d76126b commit b76ef3c

File tree

17 files changed

+113
-782
lines changed

17 files changed

+113
-782
lines changed

packages/browser/src/exports.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export {
4040
getIsolationScope,
4141
getGlobalScope,
4242
Hub,
43-
// eslint-disable-next-line deprecation/deprecation
44-
makeMain,
4543
setCurrentClient,
4644
Scope,
4745
// eslint-disable-next-line deprecation/deprecation

packages/bun/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export {
4444
getGlobalScope,
4545
getIsolationScope,
4646
Hub,
47-
// eslint-disable-next-line deprecation/deprecation
48-
makeMain,
4947
setCurrentClient,
5048
// eslint-disable-next-line deprecation/deprecation
5149
runWithAsyncContext,

packages/core/src/hub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ Sentry.init({...});
617617
*
618618
* @deprecated Use `setCurrentClient()` instead.
619619
*/
620-
export function makeMain(hub: HubInterface): HubInterface {
620+
function makeMain(hub: HubInterface): HubInterface {
621621
const registry = getMainCarrier();
622622
const oldHub = getHubFromCarrier(registry);
623623
setHubOnCarrier(registry, hub);

packages/core/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ export {
3737
getCurrentHub,
3838
getHubFromCarrier,
3939
Hub,
40-
// eslint-disable-next-line deprecation/deprecation
41-
makeMain,
4240
setHubOnCarrier,
4341
ensureHubOnCarrier,
4442
getGlobalHub,

packages/deno/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export {
4343
getGlobalScope,
4444
getIsolationScope,
4545
Hub,
46-
// eslint-disable-next-line deprecation/deprecation
47-
makeMain,
4846
setCurrentClient,
4947
// eslint-disable-next-line deprecation/deprecation
5048
runWithAsyncContext,

packages/node-experimental/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ export {
7474
continueTrace,
7575
cron,
7676
parameterize,
77-
// eslint-disable-next-line deprecation/deprecation
78-
makeMain,
7977
getCurrentScope,
8078
getIsolationScope,
8179
withScope,

packages/node/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export {
4343
getGlobalScope,
4444
getIsolationScope,
4545
Hub,
46-
// eslint-disable-next-line deprecation/deprecation
47-
makeMain,
4846
setCurrentClient,
4947
// eslint-disable-next-line deprecation/deprecation
5048
runWithAsyncContext,

packages/node/test/async/domain.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint-disable deprecation/deprecation */
2-
import { Hub, getCurrentHub, getCurrentScope, makeMain, setAsyncContextStrategy, withScope } from '@sentry/core';
2+
import type { Hub} from '@sentry/core';
3+
import { getCurrentHub, getCurrentScope, setAsyncContextStrategy, withScope } from '@sentry/core';
34
import { getIsolationScope, withIsolationScope } from '@sentry/core';
45
import type { Scope } from '@sentry/types';
56

67
import { setDomainAsyncContextStrategy } from '../../src/async/domain';
78

89
describe('setDomainAsyncContextStrategy()', () => {
910
beforeEach(() => {
10-
const hub = new Hub();
11-
12-
makeMain(hub);
11+
getCurrentScope().clear();
12+
getIsolationScope().clear();
1313
});
1414

1515
afterEach(() => {

packages/node/test/async/hooks.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable deprecation/deprecation */
2+
import type {
3+
Hub} from '@sentry/core';
24
import {
3-
Hub,
45
getCurrentHub,
56
getCurrentScope,
67
getIsolationScope,
7-
makeMain,
88
setAsyncContextStrategy,
99
withIsolationScope,
1010
withScope,
@@ -15,9 +15,8 @@ import { setHooksAsyncContextStrategy } from '../../src/async/hooks';
1515

1616
describe('setHooksAsyncContextStrategy()', () => {
1717
beforeEach(() => {
18-
const hub = new Hub();
19-
20-
makeMain(hub);
18+
getCurrentScope().clear();
19+
getIsolationScope().clear();
2120
});
2221

2322
afterEach(() => {

packages/node/test/handlers.test.ts

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import * as http from 'http';
22
import * as sentryCore from '@sentry/core';
33
import {
44
Hub,
5-
Scope as ScopeClass,
65
Transaction,
76
getClient,
87
getCurrentScope,
98
getIsolationScope,
109
getMainCarrier,
11-
makeMain,
1210
mergeScopeData,
11+
setCurrentClient,
1312
spanToJSON,
13+
withScope,
1414
} from '@sentry/core';
1515
import type { Event, PropagationContext, Scope } from '@sentry/types';
1616
import { SentryError } from '@sentry/utils';
@@ -21,10 +21,14 @@ import { getDefaultNodeClientOptions } from './helper/node-client-options';
2121

2222
describe('requestHandler', () => {
2323
beforeEach(() => {
24+
getCurrentScope().clear();
25+
getIsolationScope().clear();
26+
2427
// Ensure we reset a potentially set acs to use the default
2528
const sentry = getMainCarrier().__SENTRY__;
2629
if (sentry) {
2730
sentry.acs = undefined;
31+
sentry.hub = undefined;
2832
}
2933
});
3034

@@ -38,7 +42,6 @@ describe('requestHandler', () => {
3842
const sentryRequestMiddleware = requestHandler();
3943

4044
let req: http.IncomingMessage, res: http.ServerResponse, next: () => undefined;
41-
let client: NodeClient;
4245

4346
function createNoOpSpy() {
4447
const noop = { noop: () => undefined }; // this is wrapped in an object so jest can spy on it
@@ -63,11 +66,8 @@ describe('requestHandler', () => {
6366

6467
it('autoSessionTracking is enabled, sets requestSession status to ok, when handling a request', done => {
6568
const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.2' });
66-
client = new NodeClient(options);
67-
// eslint-disable-next-line deprecation/deprecation
68-
const hub = new Hub(client);
69-
// eslint-disable-next-line deprecation/deprecation
70-
makeMain(hub);
69+
const client = new NodeClient(options);
70+
setCurrentClient(client);
7171

7272
let isolationScope: Scope;
7373
sentryRequestMiddleware(req, res, () => {
@@ -83,11 +83,8 @@ describe('requestHandler', () => {
8383

8484
it('autoSessionTracking is disabled, does not set requestSession, when handling a request', done => {
8585
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '1.2' });
86-
client = new NodeClient(options);
87-
// eslint-disable-next-line deprecation/deprecation
88-
const hub = new Hub(client);
89-
// eslint-disable-next-line deprecation/deprecation
90-
makeMain(hub);
86+
const client = new NodeClient(options);
87+
setCurrentClient(client);
9188

9289
let isolationScope: Scope;
9390
sentryRequestMiddleware(req, res, () => {
@@ -103,11 +100,8 @@ describe('requestHandler', () => {
103100

104101
it('autoSessionTracking is enabled, calls _captureRequestSession, on response finish', done => {
105102
const options = getDefaultNodeClientOptions({ autoSessionTracking: true, release: '1.2' });
106-
client = new NodeClient(options);
107-
// eslint-disable-next-line deprecation/deprecation
108-
const hub = new Hub(client);
109-
// eslint-disable-next-line deprecation/deprecation
110-
makeMain(hub);
103+
const client = new NodeClient(options);
104+
setCurrentClient(client);
111105

112106
const captureRequestSession = jest.spyOn<any, any>(client, '_captureRequestSession');
113107

@@ -128,11 +122,8 @@ describe('requestHandler', () => {
128122

129123
it('autoSessionTracking is disabled, does not call _captureRequestSession, on response finish', done => {
130124
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '1.2' });
131-
client = new NodeClient(options);
132-
// eslint-disable-next-line deprecation/deprecation
133-
const hub = new Hub(client);
134-
// eslint-disable-next-line deprecation/deprecation
135-
makeMain(hub);
125+
const client = new NodeClient(options);
126+
setCurrentClient(client);
136127

137128
const captureRequestSession = jest.spyOn<any, any>(client, '_captureRequestSession');
138129

@@ -179,10 +170,8 @@ describe('requestHandler', () => {
179170
});
180171

181172
it('stores request and request data options in `sdkProcessingMetadata`', done => {
182-
// eslint-disable-next-line deprecation/deprecation
183-
const hub = new Hub(new NodeClient(getDefaultNodeClientOptions()));
184-
// eslint-disable-next-line deprecation/deprecation
185-
makeMain(hub);
173+
const client = new NodeClient(getDefaultNodeClientOptions());
174+
setCurrentClient(client);
186175

187176
const requestHandlerOptions = { include: { ip: false } };
188177
const sentryRequestMiddleware = requestHandler(requestHandlerOptions);
@@ -208,6 +197,18 @@ describe('requestHandler', () => {
208197
});
209198

210199
describe('tracingHandler', () => {
200+
beforeEach(() => {
201+
getCurrentScope().clear();
202+
getIsolationScope().clear();
203+
204+
// Ensure we reset a potentially set acs to use the default
205+
const sentry = getMainCarrier().__SENTRY__;
206+
if (sentry) {
207+
sentry.acs = undefined;
208+
sentry.hub = undefined;
209+
}
210+
});
211+
211212
const headers = { ears: 'furry', nose: 'wet', tongue: 'spotted', cookie: 'favorite=zukes' };
212213
const method = 'wagging';
213214
const protocol = 'mutualsniffing';
@@ -218,18 +219,16 @@ describe('tracingHandler', () => {
218219

219220
const sentryTracingMiddleware = tracingHandler();
220221

221-
let hub: Hub, req: http.IncomingMessage, res: http.ServerResponse, next: () => undefined;
222+
let req: http.IncomingMessage, res: http.ServerResponse, next: () => undefined;
222223

223224
function createNoOpSpy() {
224225
const noop = { noop: () => undefined }; // this is wrapped in an object so jest can spy on it
225226
return jest.spyOn(noop, 'noop') as any;
226227
}
227228

228229
beforeEach(() => {
229-
// eslint-disable-next-line deprecation/deprecation
230-
hub = new Hub(new NodeClient(getDefaultNodeClientOptions({ tracesSampleRate: 1.0 })));
231-
// eslint-disable-next-line deprecation/deprecation
232-
makeMain(hub);
230+
const client = new NodeClient(getDefaultNodeClientOptions({ tracesSampleRate: 1.0 }));
231+
setCurrentClient(client);
233232

234233
req = {
235234
headers,
@@ -349,12 +348,10 @@ describe('tracingHandler', () => {
349348
it('extracts request data for sampling context', () => {
350349
const tracesSampler = jest.fn();
351350
const options = getDefaultNodeClientOptions({ tracesSampler });
352-
// eslint-disable-next-line deprecation/deprecation
353-
const hub = new Hub(new NodeClient(options));
354-
// eslint-disable-next-line deprecation/deprecation
355-
makeMain(hub);
351+
const client = new NodeClient(options);
352+
setCurrentClient(client);
356353

357-
hub.run(() => {
354+
withScope(() => {
358355
sentryTracingMiddleware(req, res, next);
359356

360357
expect(tracesSampler).toHaveBeenCalledWith(
@@ -373,10 +370,8 @@ describe('tracingHandler', () => {
373370

374371
it('puts its transaction on the scope', () => {
375372
const options = getDefaultNodeClientOptions({ tracesSampleRate: 1.0 });
376-
// eslint-disable-next-line deprecation/deprecation
377-
const hub = new Hub(new NodeClient(options));
378-
// eslint-disable-next-line deprecation/deprecation
379-
makeMain(hub);
373+
const client = new NodeClient(options);
374+
setCurrentClient(client);
380375

381376
sentryTracingMiddleware(req, res, next);
382377

@@ -521,6 +516,18 @@ describe('tracingHandler', () => {
521516
});
522517

523518
describe('errorHandler()', () => {
519+
beforeEach(() => {
520+
getCurrentScope().clear();
521+
getIsolationScope().clear();
522+
523+
// Ensure we reset a potentially set acs to use the default
524+
const sentry = getMainCarrier().__SENTRY__;
525+
if (sentry) {
526+
sentry.acs = undefined;
527+
sentry.hub = undefined;
528+
}
529+
});
530+
524531
const headers = { ears: 'furry', nose: 'wet', tongue: 'spotted', cookie: 'favorite=zukes' };
525532
const method = 'wagging';
526533
const protocol = 'mutualsniffing';
@@ -561,10 +568,7 @@ describe('errorHandler()', () => {
561568
// by the`requestHandler`)
562569
client.initSessionFlusher();
563570

564-
// eslint-disable-next-line deprecation/deprecation
565-
const hub = new Hub(client);
566-
// eslint-disable-next-line deprecation/deprecation
567-
makeMain(hub);
571+
setCurrentClient(client);
568572

569573
jest.spyOn<any, any>(client, '_captureRequestSession');
570574

@@ -585,11 +589,9 @@ describe('errorHandler()', () => {
585589
it('autoSessionTracking is enabled + requestHandler is not used -> does not set requestSession status on Crash', done => {
586590
const options = getDefaultNodeClientOptions({ autoSessionTracking: false, release: '3.3' });
587591
client = new NodeClient(options);
588-
// eslint-disable-next-line deprecation/deprecation
589-
const hub = new Hub(client);
592+
setCurrentClient(client);
590593

591594
jest.spyOn<any, any>(client, '_captureRequestSession');
592-
jest.spyOn(sentryCore, 'getCurrentHub').mockReturnValue(hub);
593595

594596
getIsolationScope().setRequestSession({ status: 'ok' });
595597

@@ -611,15 +613,12 @@ describe('errorHandler()', () => {
611613
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
612614
// by the`requestHandler`)
613615
client.initSessionFlusher();
614-
const scope = new ScopeClass();
615-
// eslint-disable-next-line deprecation/deprecation
616-
const hub = new Hub(client, scope);
617-
// eslint-disable-next-line deprecation/deprecation
618-
makeMain(hub);
616+
617+
setCurrentClient(client);
619618

620619
jest.spyOn<any, any>(client, '_captureRequestSession');
621620

622-
hub.run(() => {
621+
withScope(() => {
623622
getIsolationScope().setRequestSession({ status: 'ok' });
624623
sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, () => {
625624
expect(getIsolationScope().getRequestSession()).toEqual({ status: 'crashed' });
@@ -633,11 +632,7 @@ describe('errorHandler()', () => {
633632
// It is required to initialise SessionFlusher to capture Session Aggregates (it is usually initialised
634633
// by the`requestHandler`)
635634
client.initSessionFlusher();
636-
const scope = new ScopeClass();
637-
// eslint-disable-next-line deprecation/deprecation
638-
const hub = new Hub(client, scope);
639-
// eslint-disable-next-line deprecation/deprecation
640-
makeMain(hub);
635+
setCurrentClient(client);
641636

642637
jest.spyOn<any, any>(client, '_captureRequestSession');
643638

@@ -656,11 +651,7 @@ describe('errorHandler()', () => {
656651
it('stores request in `sdkProcessingMetadata`', done => {
657652
const options = getDefaultNodeClientOptions({});
658653
client = new NodeClient(options);
659-
660-
// eslint-disable-next-line deprecation/deprecation
661-
const hub = new Hub(client);
662-
// eslint-disable-next-line deprecation/deprecation
663-
makeMain(hub);
654+
setCurrentClient(client);
664655

665656
let isolationScope: Scope;
666657
sentryErrorMiddleware({ name: 'error', message: 'this is an error' }, req, res, () => {

0 commit comments

Comments
 (0)