diff --git a/packages/core/src/hub.ts b/packages/core/src/hub.ts index a60b3af506fc..ce3f974f735f 100644 --- a/packages/core/src/hub.ts +++ b/packages/core/src/hub.ts @@ -530,20 +530,6 @@ export class Hub implements HubInterface { client.captureSession(session); } } - - /** - * Calls global extension method and binding current instance to the function call - */ - // @ts-expect-error Function lacks ending return statement and return type does not include 'undefined'. ts(2366) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private _callExtensionMethod(method: string, ...args: any[]): T { - const carrier = getMainCarrier(); - const sentry = getSentryCarrier(carrier); - if (sentry.extensions && typeof sentry.extensions[method] === 'function') { - return sentry.extensions[method].apply(this, args); - } - DEBUG_BUILD && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`); - } } /** diff --git a/packages/node-experimental/src/index.ts b/packages/node-experimental/src/index.ts index a8d511702189..2c5b198a7b66 100644 --- a/packages/node-experimental/src/index.ts +++ b/packages/node-experimental/src/index.ts @@ -25,18 +25,10 @@ export { spotlightIntegration } from './integrations/spotlight'; export { init, getDefaultIntegrations } from './sdk/init'; export { getAutoPerformanceIntegrations } from './integrations/tracing'; -export { - getClient, - getSentryRelease, - defaultStackParser, - // eslint-disable-next-line deprecation/deprecation - makeMain, -} from './sdk/api'; +export { getSentryRelease, defaultStackParser } from './sdk/api'; export { createGetModuleFromFilename } from './utils/module'; export { makeNodeTransport } from './transports'; export { NodeClient } from './sdk/client'; -// eslint-disable-next-line deprecation/deprecation -export { getCurrentHub } from './sdk/hub'; export { cron } from './cron'; export type { NodeOptions } from './types'; @@ -84,6 +76,9 @@ export { setMeasurement, getSpanDescendants, parameterize, + getClient, + // eslint-disable-next-line deprecation/deprecation + getCurrentHub, getCurrentScope, getIsolationScope, withScope, diff --git a/packages/node-experimental/src/integrations/anr/index.ts b/packages/node-experimental/src/integrations/anr/index.ts index 1d4cffc1e8c6..40aeafcf08ed 100644 --- a/packages/node-experimental/src/integrations/anr/index.ts +++ b/packages/node-experimental/src/integrations/anr/index.ts @@ -3,7 +3,7 @@ import type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/types'; import { logger } from '@sentry/utils'; import * as inspector from 'inspector'; import { Worker } from 'worker_threads'; -import { NODE_MAJOR, NODE_VERSION } from '../../nodeVersion'; +import { NODE_VERSION } from '../../nodeVersion'; import type { NodeClient } from '../../sdk/client'; import type { AnrIntegrationOptions, WorkerStartData } from './common'; import { base64WorkerScript } from './worker-script'; @@ -36,7 +36,7 @@ const _anrIntegration = ((options: Partial = {}) => { return { name: INTEGRATION_NAME, setup(client: NodeClient) { - if (NODE_MAJOR < 16 || (NODE_MAJOR === 16 && (NODE_VERSION.minor || 0) < 17)) { + if (NODE_VERSION.major < 16 || (NODE_VERSION.major === 16 && NODE_VERSION.minor < 17)) { throw new Error('ANR detection requires Node 16.17.0 or later'); } diff --git a/packages/node-experimental/src/nodeVersion.ts b/packages/node-experimental/src/nodeVersion.ts index 792037ece168..1f07883b771b 100644 --- a/packages/node-experimental/src/nodeVersion.ts +++ b/packages/node-experimental/src/nodeVersion.ts @@ -1,7 +1,4 @@ import { parseSemver } from '@sentry/utils'; -export const NODE_VERSION = parseSemver(process.versions.node) as { - major: number | undefined; - minor: number | undefined; -}; -export const NODE_MAJOR = NODE_VERSION.major || 0; +export const NODE_VERSION = parseSemver(process.versions.node) as { major: number; minor: number; patch: number }; +export const NODE_MAJOR = NODE_VERSION.major; diff --git a/packages/node-experimental/src/sdk/api.ts b/packages/node-experimental/src/sdk/api.ts index 735766e994f1..ec1a81a3b4f0 100644 --- a/packages/node-experimental/src/sdk/api.ts +++ b/packages/node-experimental/src/sdk/api.ts @@ -1,24 +1,9 @@ // PUBLIC APIS -import { getCurrentScope } from '@sentry/core'; -import type { Client, StackParser } from '@sentry/types'; -import type { Hub } from '@sentry/types'; +import type { StackParser } from '@sentry/types'; import { GLOBAL_OBJ, createStackParser, nodeStackLineParser } from '@sentry/utils'; import { createGetModuleFromFilename } from '../utils/module'; -/** Get the currently active client. */ -export function getClient(): C { - const currentScope = getCurrentScope(); - - const client = currentScope.getClient(); - if (client) { - return client as C; - } - - // TODO otherwise ensure we use a noop client - return {} as C; -} - /** * Returns a release dynamically from environment variables. */ @@ -55,14 +40,3 @@ export function getSentryRelease(fallback?: string): string | undefined { /** Node.js stack parser */ export const defaultStackParser: StackParser = createStackParser(nodeStackLineParser(createGetModuleFromFilename())); - -/** - * This method is a noop and only here to ensure vite-plugin v0.6.0 (which is used by Sveltekit) still works, - * as that uses this. - * - * @deprecated This will be removed before v8 is finalized. - */ -export function makeMain(hub: Hub): Hub { - // noop - return hub; -} diff --git a/packages/node-experimental/src/sdk/globals.ts b/packages/node-experimental/src/sdk/globals.ts deleted file mode 100644 index 27428960bcf0..000000000000 --- a/packages/node-experimental/src/sdk/globals.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { getMainCarrier } from '@sentry/core'; -import type { Hub } from '@sentry/types'; -import { logger } from '@sentry/utils'; -import { DEBUG_BUILD } from '../debug-build'; - -/** - * Calls global extension method and binding current instance to the function call - */ -// @ts-expect-error Function lacks ending return statement and return type does not include 'undefined'. ts(2366) -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function callExtensionMethod(hub: Hub, method: string, ...args: any[]): T { - const carrier = getMainCarrier(); - const sentry = carrier.__SENTRY__ || {}; - - if (sentry.extensions && typeof sentry.extensions[method] === 'function') { - return sentry.extensions[method].apply(hub, args); - } - DEBUG_BUILD && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`); -} diff --git a/packages/node-experimental/src/sdk/hub.ts b/packages/node-experimental/src/sdk/hub.ts deleted file mode 100644 index 0ab3e0cd320c..000000000000 --- a/packages/node-experimental/src/sdk/hub.ts +++ /dev/null @@ -1,103 +0,0 @@ -import type { Client, EventHint, Hub, Integration, IntegrationClass, Scope, SeverityLevel } from '@sentry/types'; - -import { - addBreadcrumb, - captureEvent, - endSession, - getCurrentScope, - getIsolationScope, - setContext, - setExtra, - setExtras, - setTag, - setTags, - setUser, - startSession, - withScope, -} from '@sentry/core'; -import { getClient } from './api'; - -/** - * This is for legacy reasons, and returns a proxy object instead of a hub to be used. - * @deprecated Use the methods directly. - */ -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: () => getClient() as C | undefined, - getScope: getCurrentScope, - getIsolationScope, - captureException: (exception: unknown, hint?: EventHint) => { - return getCurrentScope().captureException(exception, hint); - }, - captureMessage: (message: string, level?: SeverityLevel, hint?: EventHint) => { - return getCurrentScope().captureMessage(message, level, hint); - }, - captureEvent, - addBreadcrumb, - setUser, - setTags, - setTag, - setExtra, - setExtras, - setContext, - - getIntegration(integration: IntegrationClass): T | null { - // eslint-disable-next-line deprecation/deprecation - return getClient().getIntegration(integration); - }, - - 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); - }, - }; -} - -/** - * Sends the current Session on the scope - */ -function _sendSessionUpdate(): void { - const scope = getCurrentScope(); - const client = getClient(); - - const session = scope.getSession(); - if (session) { - client.captureSession(session); - } -} diff --git a/packages/node-experimental/src/sdk/initOtel.ts b/packages/node-experimental/src/sdk/initOtel.ts index dd8d78382616..f328801e3967 100644 --- a/packages/node-experimental/src/sdk/initOtel.ts +++ b/packages/node-experimental/src/sdk/initOtel.ts @@ -2,13 +2,12 @@ import { DiagLogLevel, diag } from '@opentelemetry/api'; import { Resource } from '@opentelemetry/resources'; import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; -import { SDK_VERSION } from '@sentry/core'; +import { SDK_VERSION, getClient } from '@sentry/core'; import { SentryPropagator, SentrySampler, SentrySpanProcessor, setupEventContextTrace } from '@sentry/opentelemetry'; import { logger } from '@sentry/utils'; import { DEBUG_BUILD } from '../debug-build'; import { SentryContextManager } from '../otel/contextManager'; -import { getClient } from './api'; import type { NodeClient } from './client'; /** diff --git a/packages/node-experimental/test/integration/breadcrumbs.test.ts b/packages/node-experimental/test/integration/breadcrumbs.test.ts index d6741b017764..5105a9ff50df 100644 --- a/packages/node-experimental/test/integration/breadcrumbs.test.ts +++ b/packages/node-experimental/test/integration/breadcrumbs.test.ts @@ -1,6 +1,6 @@ import { addBreadcrumb, captureException, withIsolationScope, withScope } from '@sentry/core'; import { startSpan } from '@sentry/opentelemetry'; -import { getClient } from '../../src/sdk/api'; +import { getClient } from '../../src/'; import type { NodeClient } from '../../src/sdk/client'; import { cleanupOtel, mockSdkInit } from '../helpers/mockSdkInit'; @@ -74,7 +74,7 @@ describe('Integration | breadcrumbs', () => { addBreadcrumb({ timestamp: 123456, message: 'test3' }); }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeBreadcrumb).toHaveBeenCalledTimes(4); diff --git a/packages/node-experimental/test/integration/scope.test.ts b/packages/node-experimental/test/integration/scope.test.ts index e740ca0584f7..db3f61d251ba 100644 --- a/packages/node-experimental/test/integration/scope.test.ts +++ b/packages/node-experimental/test/integration/scope.test.ts @@ -289,7 +289,7 @@ describe('Integration | Scope', () => { const error = new Error('test error'); Sentry.captureException(error); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -347,7 +347,7 @@ describe('Integration | Scope', () => { const error = new Error('test error'); Sentry.captureException(error); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -396,7 +396,7 @@ describe('Integration | Scope', () => { expect(initialIsolationScope.getScopeData().tags).toEqual({ tag1: 'val1', tag2: 'val2' }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -439,7 +439,7 @@ describe('Integration | Scope', () => { }); }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -499,7 +499,7 @@ describe('Integration | Scope', () => { const error = new Error('test error'); Sentry.captureException(error); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -547,7 +547,7 @@ describe('Integration | Scope', () => { expect(initialCurrentScope.getScopeData().tags).toEqual({ tag1: 'val1', tag2: 'val2' }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -593,7 +593,7 @@ describe('Integration | Scope', () => { }); }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -636,7 +636,7 @@ describe('Integration | Scope', () => { }); }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( @@ -682,7 +682,7 @@ describe('Integration | Scope', () => { }); }); - await client.flush(); + await client?.flush(); expect(beforeSend).toHaveBeenCalledTimes(1); expect(beforeSend).toHaveBeenCalledWith( diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index ea368a7b2fb8..f86e8049f71e 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -344,7 +344,7 @@ describe('Integration | Transactions', () => { Sentry.addBreadcrumb({ message: 'test breadcrumb 1', timestamp: 123456 }); Sentry.withIsolationScope(() => { - client.tracer.startActiveSpan('test name', span => { + client?.tracer.startActiveSpan('test name', span => { Sentry.addBreadcrumb({ message: 'test breadcrumb 2', timestamp: 123456 }); span.setAttributes({ @@ -371,7 +371,7 @@ describe('Integration | Transactions', () => { }); Sentry.withIsolationScope(() => { - client.tracer.startActiveSpan('test name b', span => { + client?.tracer.startActiveSpan('test name b', span => { Sentry.addBreadcrumb({ message: 'test breadcrumb 2b', timestamp: 123456 }); span.setAttributes({ @@ -397,7 +397,7 @@ describe('Integration | Transactions', () => { }); }); - await client.flush(); + await client?.flush(); expect(beforeSendTransaction).toHaveBeenCalledTimes(2); expect(beforeSendTransaction).toHaveBeenCalledWith( diff --git a/packages/node-experimental/test/sdk/api.test.ts b/packages/node-experimental/test/sdk/api.test.ts index 6ad2d0700108..84755566d096 100644 --- a/packages/node-experimental/test/sdk/api.test.ts +++ b/packages/node-experimental/test/sdk/api.test.ts @@ -34,7 +34,7 @@ describe('withActiveSpan()', () => { inactiveSpan.end(); - await client.flush(); + await client?.flush(); // The child span should be a child of the inactive span expect(beforeSendTransaction).toHaveBeenCalledWith( @@ -74,7 +74,7 @@ describe('withActiveSpan()', () => { }); }); - await client.flush(); + await client?.flush(); expect(beforeSendTransaction).toHaveBeenCalledTimes(2); diff --git a/packages/node-experimental/test/sdk/init.test.ts b/packages/node-experimental/test/sdk/init.test.ts index d6e9bc7ee81d..d1c3788caa2f 100644 --- a/packages/node-experimental/test/sdk/init.test.ts +++ b/packages/node-experimental/test/sdk/init.test.ts @@ -1,7 +1,7 @@ import type { Integration } from '@sentry/types'; +import { getClient } from '../../src/'; import * as auto from '../../src/integrations/tracing'; -import { getClient } from '../../src/sdk/api'; import type { NodeClient } from '../../src/sdk/client'; import { init } from '../../src/sdk/init'; import { cleanupOtel } from '../helpers/mockSdkInit'; @@ -39,7 +39,7 @@ describe('init()', () => { const client = getClient(); - expect(client.getOptions()).toEqual( + expect(client?.getOptions()).toEqual( expect.objectContaining({ integrations: [], }), @@ -114,7 +114,7 @@ describe('init()', () => { expect(mockAutoPerformanceIntegrations).toHaveBeenCalledTimes(1); const client = getClient(); - expect(client.getOptions()).toEqual( + expect(client?.getOptions()).toEqual( expect.objectContaining({ integrations: expect.arrayContaining([mockIntegrations[0], mockIntegrations[1], autoPerformanceIntegration]), }), @@ -126,7 +126,7 @@ describe('init()', () => { const client = getClient(); - expect(client.traceProvider).toBeDefined(); + expect(client?.traceProvider).toBeDefined(); }); it('allows to opt-out of OpenTelemetry setup', () => { @@ -134,6 +134,6 @@ describe('init()', () => { const client = getClient(); - expect(client.traceProvider).not.toBeDefined(); + expect(client?.traceProvider).not.toBeDefined(); }); }); diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index fcdf56eb2a57..e31c0b29fbd8 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -26,8 +26,6 @@ export { getGlobalScope, getIsolationScope, Hub, - // eslint-disable-next-line deprecation/deprecation - makeMain, setCurrentClient, NodeClient, Scope,