Skip to content

feat(node): Remove deprecated/duplicate/unused definitions #11120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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.`);
}
}

/**
Expand Down
13 changes: 4 additions & 9 deletions packages/node-experimental/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -84,6 +76,9 @@ export {
setMeasurement,
getSpanDescendants,
parameterize,
getClient,
// eslint-disable-next-line deprecation/deprecation
getCurrentHub,
getCurrentScope,
getIsolationScope,
withScope,
Expand Down
4 changes: 2 additions & 2 deletions packages/node-experimental/src/integrations/anr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -36,7 +36,7 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gives me the reminder we need to clean up GLOBAL_OBJ usage soon.

throw new Error('ANR detection requires Node 16.17.0 or later');
}

Expand Down
7 changes: 2 additions & 5 deletions packages/node-experimental/src/nodeVersion.ts
Original file line number Diff line number Diff line change
@@ -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;
28 changes: 1 addition & 27 deletions packages/node-experimental/src/sdk/api.ts
Original file line number Diff line number Diff line change
@@ -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 extends Client>(): 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.
*/
Expand Down Expand Up @@ -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;
}
19 changes: 0 additions & 19 deletions packages/node-experimental/src/sdk/globals.ts

This file was deleted.

103 changes: 0 additions & 103 deletions packages/node-experimental/src/sdk/hub.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/node-experimental/src/sdk/initOtel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions packages/node-experimental/test/integration/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('Integration | Scope', () => {
});
});

await client.flush();
await client?.flush();

expect(beforeSend).toHaveBeenCalledTimes(1);
expect(beforeSend).toHaveBeenCalledWith(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -593,7 +593,7 @@ describe('Integration | Scope', () => {
});
});

await client.flush();
await client?.flush();

expect(beforeSend).toHaveBeenCalledTimes(1);
expect(beforeSend).toHaveBeenCalledWith(
Expand Down Expand Up @@ -636,7 +636,7 @@ describe('Integration | Scope', () => {
});
});

await client.flush();
await client?.flush();

expect(beforeSend).toHaveBeenCalledTimes(1);
expect(beforeSend).toHaveBeenCalledWith(
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('Integration | Scope', () => {
});
});

await client.flush();
await client?.flush();

expect(beforeSend).toHaveBeenCalledTimes(1);
expect(beforeSend).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -397,7 +397,7 @@ describe('Integration | Transactions', () => {
});
});

await client.flush();
await client?.flush();

expect(beforeSendTransaction).toHaveBeenCalledTimes(2);
expect(beforeSendTransaction).toHaveBeenCalledWith(
Expand Down
Loading