Skip to content

Commit b8c75f4

Browse files
authored
feat(node): Remove deprecated/duplicate/unused definitions (#11120)
- Removes `makeMain` impl and exports from node (and downstream SDKs) - Removes custom `getCurrentHub/getClient` impl in favour of core - Removes `callExtensionMethod` as its not called from anywhere - Fixes all the tests that relied on `getClient` never returning undefined - Removes `_callExtensionMethod` from core as it's not used
1 parent b0e1db0 commit b8c75f4

File tree

14 files changed

+31
-204
lines changed

14 files changed

+31
-204
lines changed

packages/core/src/hub.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -530,20 +530,6 @@ export class Hub implements HubInterface {
530530
client.captureSession(session);
531531
}
532532
}
533-
534-
/**
535-
* Calls global extension method and binding current instance to the function call
536-
*/
537-
// @ts-expect-error Function lacks ending return statement and return type does not include 'undefined'. ts(2366)
538-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
539-
private _callExtensionMethod<T>(method: string, ...args: any[]): T {
540-
const carrier = getMainCarrier();
541-
const sentry = getSentryCarrier(carrier);
542-
if (sentry.extensions && typeof sentry.extensions[method] === 'function') {
543-
return sentry.extensions[method].apply(this, args);
544-
}
545-
DEBUG_BUILD && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
546-
}
547533
}
548534

549535
/**

packages/node-experimental/src/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,10 @@ export { spotlightIntegration } from './integrations/spotlight';
2525

2626
export { init, getDefaultIntegrations } from './sdk/init';
2727
export { getAutoPerformanceIntegrations } from './integrations/tracing';
28-
export {
29-
getClient,
30-
getSentryRelease,
31-
defaultStackParser,
32-
// eslint-disable-next-line deprecation/deprecation
33-
makeMain,
34-
} from './sdk/api';
28+
export { getSentryRelease, defaultStackParser } from './sdk/api';
3529
export { createGetModuleFromFilename } from './utils/module';
3630
export { makeNodeTransport } from './transports';
3731
export { NodeClient } from './sdk/client';
38-
// eslint-disable-next-line deprecation/deprecation
39-
export { getCurrentHub } from './sdk/hub';
4032
export { cron } from './cron';
4133

4234
export type { NodeOptions } from './types';
@@ -84,6 +76,9 @@ export {
8476
setMeasurement,
8577
getSpanDescendants,
8678
parameterize,
79+
getClient,
80+
// eslint-disable-next-line deprecation/deprecation
81+
getCurrentHub,
8782
getCurrentScope,
8883
getIsolationScope,
8984
withScope,

packages/node-experimental/src/integrations/anr/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44
import * as inspector from 'inspector';
55
import { Worker } from 'worker_threads';
6-
import { NODE_MAJOR, NODE_VERSION } from '../../nodeVersion';
6+
import { NODE_VERSION } from '../../nodeVersion';
77
import type { NodeClient } from '../../sdk/client';
88
import type { AnrIntegrationOptions, WorkerStartData } from './common';
99
import { base64WorkerScript } from './worker-script';
@@ -36,7 +36,7 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
3636
return {
3737
name: INTEGRATION_NAME,
3838
setup(client: NodeClient) {
39-
if (NODE_MAJOR < 16 || (NODE_MAJOR === 16 && (NODE_VERSION.minor || 0) < 17)) {
39+
if (NODE_VERSION.major < 16 || (NODE_VERSION.major === 16 && NODE_VERSION.minor < 17)) {
4040
throw new Error('ANR detection requires Node 16.17.0 or later');
4141
}
4242

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { parseSemver } from '@sentry/utils';
22

3-
export const NODE_VERSION = parseSemver(process.versions.node) as {
4-
major: number | undefined;
5-
minor: number | undefined;
6-
};
7-
export const NODE_MAJOR = NODE_VERSION.major || 0;
3+
export const NODE_VERSION = parseSemver(process.versions.node) as { major: number; minor: number; patch: number };
4+
export const NODE_MAJOR = NODE_VERSION.major;

packages/node-experimental/src/sdk/api.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
// PUBLIC APIS
22

3-
import { getCurrentScope } from '@sentry/core';
4-
import type { Client, StackParser } from '@sentry/types';
5-
import type { Hub } from '@sentry/types';
3+
import type { StackParser } from '@sentry/types';
64
import { GLOBAL_OBJ, createStackParser, nodeStackLineParser } from '@sentry/utils';
75
import { createGetModuleFromFilename } from '../utils/module';
86

9-
/** Get the currently active client. */
10-
export function getClient<C extends Client>(): C {
11-
const currentScope = getCurrentScope();
12-
13-
const client = currentScope.getClient();
14-
if (client) {
15-
return client as C;
16-
}
17-
18-
// TODO otherwise ensure we use a noop client
19-
return {} as C;
20-
}
21-
227
/**
238
* Returns a release dynamically from environment variables.
249
*/
@@ -55,14 +40,3 @@ export function getSentryRelease(fallback?: string): string | undefined {
5540

5641
/** Node.js stack parser */
5742
export const defaultStackParser: StackParser = createStackParser(nodeStackLineParser(createGetModuleFromFilename()));
58-
59-
/**
60-
* This method is a noop and only here to ensure vite-plugin v0.6.0 (which is used by Sveltekit) still works,
61-
* as that uses this.
62-
*
63-
* @deprecated This will be removed before v8 is finalized.
64-
*/
65-
export function makeMain(hub: Hub): Hub {
66-
// noop
67-
return hub;
68-
}

packages/node-experimental/src/sdk/globals.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/node-experimental/src/sdk/hub.ts

Lines changed: 0 additions & 103 deletions
This file was deleted.

packages/node-experimental/src/sdk/initOtel.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import { DiagLogLevel, diag } from '@opentelemetry/api';
22
import { Resource } from '@opentelemetry/resources';
33
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
44
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
5-
import { SDK_VERSION } from '@sentry/core';
5+
import { SDK_VERSION, getClient } from '@sentry/core';
66
import { SentryPropagator, SentrySampler, SentrySpanProcessor, setupEventContextTrace } from '@sentry/opentelemetry';
77
import { logger } from '@sentry/utils';
88

99
import { DEBUG_BUILD } from '../debug-build';
1010
import { SentryContextManager } from '../otel/contextManager';
11-
import { getClient } from './api';
1211
import type { NodeClient } from './client';
1312

1413
/**

packages/node-experimental/test/integration/breadcrumbs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addBreadcrumb, captureException, withIsolationScope, withScope } from '@sentry/core';
22
import { startSpan } from '@sentry/opentelemetry';
3-
import { getClient } from '../../src/sdk/api';
3+
import { getClient } from '../../src/';
44
import type { NodeClient } from '../../src/sdk/client';
55

66
import { cleanupOtel, mockSdkInit } from '../helpers/mockSdkInit';
@@ -74,7 +74,7 @@ describe('Integration | breadcrumbs', () => {
7474
addBreadcrumb({ timestamp: 123456, message: 'test3' });
7575
});
7676

77-
await client.flush();
77+
await client?.flush();
7878

7979
expect(beforeSend).toHaveBeenCalledTimes(1);
8080
expect(beforeBreadcrumb).toHaveBeenCalledTimes(4);

packages/node-experimental/test/integration/scope.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ describe('Integration | Scope', () => {
289289
const error = new Error('test error');
290290
Sentry.captureException(error);
291291

292-
await client.flush();
292+
await client?.flush();
293293

294294
expect(beforeSend).toHaveBeenCalledTimes(1);
295295
expect(beforeSend).toHaveBeenCalledWith(
@@ -347,7 +347,7 @@ describe('Integration | Scope', () => {
347347
const error = new Error('test error');
348348
Sentry.captureException(error);
349349

350-
await client.flush();
350+
await client?.flush();
351351

352352
expect(beforeSend).toHaveBeenCalledTimes(1);
353353
expect(beforeSend).toHaveBeenCalledWith(
@@ -396,7 +396,7 @@ describe('Integration | Scope', () => {
396396

397397
expect(initialIsolationScope.getScopeData().tags).toEqual({ tag1: 'val1', tag2: 'val2' });
398398

399-
await client.flush();
399+
await client?.flush();
400400

401401
expect(beforeSend).toHaveBeenCalledTimes(1);
402402
expect(beforeSend).toHaveBeenCalledWith(
@@ -439,7 +439,7 @@ describe('Integration | Scope', () => {
439439
});
440440
});
441441

442-
await client.flush();
442+
await client?.flush();
443443

444444
expect(beforeSend).toHaveBeenCalledTimes(1);
445445
expect(beforeSend).toHaveBeenCalledWith(
@@ -499,7 +499,7 @@ describe('Integration | Scope', () => {
499499
const error = new Error('test error');
500500
Sentry.captureException(error);
501501

502-
await client.flush();
502+
await client?.flush();
503503

504504
expect(beforeSend).toHaveBeenCalledTimes(1);
505505
expect(beforeSend).toHaveBeenCalledWith(
@@ -547,7 +547,7 @@ describe('Integration | Scope', () => {
547547

548548
expect(initialCurrentScope.getScopeData().tags).toEqual({ tag1: 'val1', tag2: 'val2' });
549549

550-
await client.flush();
550+
await client?.flush();
551551

552552
expect(beforeSend).toHaveBeenCalledTimes(1);
553553
expect(beforeSend).toHaveBeenCalledWith(
@@ -593,7 +593,7 @@ describe('Integration | Scope', () => {
593593
});
594594
});
595595

596-
await client.flush();
596+
await client?.flush();
597597

598598
expect(beforeSend).toHaveBeenCalledTimes(1);
599599
expect(beforeSend).toHaveBeenCalledWith(
@@ -636,7 +636,7 @@ describe('Integration | Scope', () => {
636636
});
637637
});
638638

639-
await client.flush();
639+
await client?.flush();
640640

641641
expect(beforeSend).toHaveBeenCalledTimes(1);
642642
expect(beforeSend).toHaveBeenCalledWith(
@@ -682,7 +682,7 @@ describe('Integration | Scope', () => {
682682
});
683683
});
684684

685-
await client.flush();
685+
await client?.flush();
686686

687687
expect(beforeSend).toHaveBeenCalledTimes(1);
688688
expect(beforeSend).toHaveBeenCalledWith(

packages/node-experimental/test/integration/transactions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ describe('Integration | Transactions', () => {
344344
Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 });
345345

346346
Sentry.withIsolationScope(() => {
347-
client.tracer.startActiveSpan('test name', span => {
347+
client?.tracer.startActiveSpan('test name', span => {
348348
Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 });
349349

350350
span.setAttributes({
@@ -371,7 +371,7 @@ describe('Integration | Transactions', () => {
371371
});
372372

373373
Sentry.withIsolationScope(() => {
374-
client.tracer.startActiveSpan('test name b', span => {
374+
client?.tracer.startActiveSpan('test name b', span => {
375375
Sentry.addBreadcrumb({ message: 'test breadcrumb 2b', timestamp: 123456 });
376376

377377
span.setAttributes({
@@ -397,7 +397,7 @@ describe('Integration | Transactions', () => {
397397
});
398398
});
399399

400-
await client.flush();
400+
await client?.flush();
401401

402402
expect(beforeSendTransaction).toHaveBeenCalledTimes(2);
403403
expect(beforeSendTransaction).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)