From 6bbc0848b4dd8a88798934141e5dbe7d143812d8 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Sat, 4 May 2024 03:55:37 +0100 Subject: [PATCH 1/3] feat(node): Use `node:` prefix for node built-ins --- packages/node/src/integrations/anr/index.ts | 4 ++-- packages/node/src/integrations/anr/worker.ts | 2 +- packages/node/src/integrations/console.ts | 2 +- packages/node/src/integrations/context.ts | 10 +++++----- packages/node/src/integrations/contextlines.ts | 2 +- packages/node/src/integrations/http.ts | 2 +- .../node/src/integrations/local-variables/common.ts | 2 +- .../local-variables/local-variables-async.ts | 2 +- .../local-variables/local-variables-sync.ts | 4 ++-- .../node/src/integrations/local-variables/worker.ts | 4 ++-- packages/node/src/integrations/modules.ts | 4 ++-- packages/node/src/integrations/spotlight.ts | 2 +- packages/node/src/integrations/tracing/express.ts | 2 +- packages/node/src/proxy/base.ts | 8 ++++---- packages/node/src/proxy/helpers.ts | 2 +- packages/node/src/proxy/index.ts | 8 ++++---- packages/node/src/proxy/parse-proxy-response.ts | 4 ++-- packages/node/src/sdk/client.ts | 2 +- packages/node/src/transports/http.ts | 4 ++-- packages/node/src/utils/getRequestUrl.ts | 2 +- packages/node/src/utils/module.ts | 2 +- packages/profiling-node/src/cpu_profiler.ts | 8 ++++---- packages/profiling-node/src/utils.ts | 6 +++--- 23 files changed, 44 insertions(+), 44 deletions(-) diff --git a/packages/node/src/integrations/anr/index.ts b/packages/node/src/integrations/anr/index.ts index 2cf32289f082..4cbec46300c2 100644 --- a/packages/node/src/integrations/anr/index.ts +++ b/packages/node/src/integrations/anr/index.ts @@ -1,8 +1,8 @@ +import * as inspector from 'node:inspector'; +import { Worker } from 'node:worker_threads'; import { defineIntegration, mergeScopeData } from '@sentry/core'; import type { Contexts, Event, EventHint, Integration, IntegrationFn, ScopeData } from '@sentry/types'; import { GLOBAL_OBJ, logger } from '@sentry/utils'; -import * as inspector from 'inspector'; -import { Worker } from 'worker_threads'; import { getCurrentScope, getGlobalScope, getIsolationScope } from '../..'; import { NODE_VERSION } from '../../nodeVersion'; import type { NodeClient } from '../../sdk/client'; diff --git a/packages/node/src/integrations/anr/worker.ts b/packages/node/src/integrations/anr/worker.ts index 6acbbe507b01..6f701919c531 100644 --- a/packages/node/src/integrations/anr/worker.ts +++ b/packages/node/src/integrations/anr/worker.ts @@ -1,3 +1,4 @@ +import { parentPort, workerData } from 'node:worker_threads'; import { applyScopeDataToEvent, createEventEnvelope, @@ -15,7 +16,6 @@ import { watchdogTimer, } from '@sentry/utils'; import { Session as InspectorSession } from 'inspector'; -import { parentPort, workerData } from 'worker_threads'; import { makeNodeTransport } from '../../transports'; import { createGetModuleFromFilename } from '../../utils/module'; diff --git a/packages/node/src/integrations/console.ts b/packages/node/src/integrations/console.ts index 0b3d27fe8510..5cd2eb2ce98a 100644 --- a/packages/node/src/integrations/console.ts +++ b/packages/node/src/integrations/console.ts @@ -1,4 +1,4 @@ -import * as util from 'util'; +import * as util from 'node:util'; import { addBreadcrumb, defineIntegration, getClient } from '@sentry/core'; import type { IntegrationFn } from '@sentry/types'; import { addConsoleInstrumentationHandler, severityLevelFromString } from '@sentry/utils'; diff --git a/packages/node/src/integrations/context.ts b/packages/node/src/integrations/context.ts index c33d97e79044..35410effa528 100644 --- a/packages/node/src/integrations/context.ts +++ b/packages/node/src/integrations/context.ts @@ -1,8 +1,8 @@ -import { execFile } from 'child_process'; -import { readFile, readdir } from 'fs'; -import * as os from 'os'; -import { join } from 'path'; -import { promisify } from 'util'; +import { execFile } from 'node:child_process'; +import { readFile, readdir } from 'node:fs'; +import * as os from 'node:os'; +import { join } from 'node:path'; +import { promisify } from 'node:util'; import { defineIntegration } from '@sentry/core'; import type { AppContext, diff --git a/packages/node/src/integrations/contextlines.ts b/packages/node/src/integrations/contextlines.ts index 3755e164e5ea..7f4b78653b6a 100644 --- a/packages/node/src/integrations/contextlines.ts +++ b/packages/node/src/integrations/contextlines.ts @@ -1,4 +1,4 @@ -import { promises } from 'fs'; +import { promises } from 'node:fs'; import { defineIntegration } from '@sentry/core'; import type { Event, IntegrationFn, StackFrame } from '@sentry/types'; import { LRUMap, addContextToFrame } from '@sentry/utils'; diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index ce6916da4dcd..82d202d56787 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -1,4 +1,4 @@ -import type { ClientRequest, IncomingMessage, ServerResponse } from 'http'; +import type { ClientRequest, IncomingMessage, ServerResponse } from 'node:http'; import type { Span } from '@opentelemetry/api'; import { SpanKind } from '@opentelemetry/api'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; diff --git a/packages/node/src/integrations/local-variables/common.ts b/packages/node/src/integrations/local-variables/common.ts index 990a3d71b061..67c8d6d43d81 100644 --- a/packages/node/src/integrations/local-variables/common.ts +++ b/packages/node/src/integrations/local-variables/common.ts @@ -1,5 +1,5 @@ +import type { Debugger } from 'node:inspector'; import type { StackFrame, StackParser } from '@sentry/types'; -import type { Debugger } from 'inspector'; export type Variables = Record; diff --git a/packages/node/src/integrations/local-variables/local-variables-async.ts b/packages/node/src/integrations/local-variables/local-variables-async.ts index b8e827909ea8..d97f93e21f52 100644 --- a/packages/node/src/integrations/local-variables/local-variables-async.ts +++ b/packages/node/src/integrations/local-variables/local-variables-async.ts @@ -1,7 +1,7 @@ +import { Worker } from 'node:worker_threads'; import { defineIntegration } from '@sentry/core'; import type { Event, Exception, IntegrationFn } from '@sentry/types'; import { LRUMap, logger } from '@sentry/utils'; -import { Worker } from 'worker_threads'; import type { NodeClient } from '../../sdk/client'; import type { FrameVariables, LocalVariablesIntegrationOptions, LocalVariablesWorkerArgs } from './common'; diff --git a/packages/node/src/integrations/local-variables/local-variables-sync.ts b/packages/node/src/integrations/local-variables/local-variables-sync.ts index 91fb9005b4c3..66e8eca4d32f 100644 --- a/packages/node/src/integrations/local-variables/local-variables-sync.ts +++ b/packages/node/src/integrations/local-variables/local-variables-sync.ts @@ -1,8 +1,8 @@ +import type { Debugger, InspectorNotification, Runtime } from 'node:inspector'; +import { Session } from 'node:inspector'; import { defineIntegration, getClient } from '@sentry/core'; import type { Event, Exception, IntegrationFn, StackParser } from '@sentry/types'; import { LRUMap, logger } from '@sentry/utils'; -import type { Debugger, InspectorNotification, Runtime } from 'inspector'; -import { Session } from 'inspector'; import { NODE_MAJOR } from '../../nodeVersion'; import type { NodeClient } from '../../sdk/client'; diff --git a/packages/node/src/integrations/local-variables/worker.ts b/packages/node/src/integrations/local-variables/worker.ts index 5a104ce74f5b..fee92b10106c 100644 --- a/packages/node/src/integrations/local-variables/worker.ts +++ b/packages/node/src/integrations/local-variables/worker.ts @@ -1,8 +1,8 @@ +import type { Debugger, InspectorNotification, Runtime } from 'node:inspector'; import { Session } from 'node:inspector/promises'; +import { parentPort, workerData } from 'node:worker_threads'; import type { StackParser } from '@sentry/types'; import { createStackParser, nodeStackLineParser } from '@sentry/utils'; -import type { Debugger, InspectorNotification, Runtime } from 'inspector'; -import { parentPort, workerData } from 'worker_threads'; import { createGetModuleFromFilename } from '../../utils/module'; import type { LocalVariablesWorkerArgs, PausedExceptionEvent, RateLimitIncrement, Variables } from './common'; import { createRateLimiter, hashFromStack } from './common'; diff --git a/packages/node/src/integrations/modules.ts b/packages/node/src/integrations/modules.ts index ad30bb4d7a3b..b1b56c6c1fda 100644 --- a/packages/node/src/integrations/modules.ts +++ b/packages/node/src/integrations/modules.ts @@ -1,5 +1,5 @@ -import { existsSync, readFileSync } from 'fs'; -import { dirname, join } from 'path'; +import { existsSync, readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; import { defineIntegration } from '@sentry/core'; import type { IntegrationFn } from '@sentry/types'; diff --git a/packages/node/src/integrations/spotlight.ts b/packages/node/src/integrations/spotlight.ts index 21629ad340ac..bfb9559958f9 100644 --- a/packages/node/src/integrations/spotlight.ts +++ b/packages/node/src/integrations/spotlight.ts @@ -1,4 +1,4 @@ -import * as http from 'http'; +import * as http from 'node:http'; import { defineIntegration } from '@sentry/core'; import type { Client, Envelope, IntegrationFn } from '@sentry/types'; import { logger, serializeEnvelope } from '@sentry/utils'; diff --git a/packages/node/src/integrations/tracing/express.ts b/packages/node/src/integrations/tracing/express.ts index 8f0e93771403..5b819188d362 100644 --- a/packages/node/src/integrations/tracing/express.ts +++ b/packages/node/src/integrations/tracing/express.ts @@ -1,4 +1,4 @@ -import type * as http from 'http'; +import type * as http from 'node:http'; import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; import { defineIntegration, getDefaultIsolationScope } from '@sentry/core'; import { captureException, getClient, getIsolationScope } from '@sentry/core'; diff --git a/packages/node/src/proxy/base.ts b/packages/node/src/proxy/base.ts index e1ef24c3092e..4787538c17bb 100644 --- a/packages/node/src/proxy/base.ts +++ b/packages/node/src/proxy/base.ts @@ -29,10 +29,10 @@ /* eslint-disable @typescript-eslint/explicit-member-accessibility */ /* eslint-disable @typescript-eslint/member-ordering */ /* eslint-disable jsdoc/require-jsdoc */ -import * as http from 'http'; -import type * as net from 'net'; -import type { Duplex } from 'stream'; -import type * as tls from 'tls'; +import * as http from 'node:http'; +import type * as net from 'node:net'; +import type { Duplex } from 'node:stream'; +import type * as tls from 'node:tls'; export * from './helpers'; diff --git a/packages/node/src/proxy/helpers.ts b/packages/node/src/proxy/helpers.ts index 031878511f6c..cb9a37b13305 100644 --- a/packages/node/src/proxy/helpers.ts +++ b/packages/node/src/proxy/helpers.ts @@ -29,7 +29,7 @@ /* eslint-disable jsdoc/require-jsdoc */ import * as http from 'node:http'; import * as https from 'node:https'; -import type { Readable } from 'stream'; +import type { Readable } from 'node:stream'; export type ThenableRequest = http.ClientRequest & { then: Promise['then']; diff --git a/packages/node/src/proxy/index.ts b/packages/node/src/proxy/index.ts index 83f72d56fb4e..07674895379e 100644 --- a/packages/node/src/proxy/index.ts +++ b/packages/node/src/proxy/index.ts @@ -28,10 +28,10 @@ /* eslint-disable @typescript-eslint/explicit-member-accessibility */ /* eslint-disable @typescript-eslint/no-unused-vars */ -import type * as http from 'http'; -import type { OutgoingHttpHeaders } from 'http'; -import * as net from 'net'; -import * as tls from 'tls'; +import type * as http from 'node:http'; +import type { OutgoingHttpHeaders } from 'node:http'; +import * as net from 'node:net'; +import * as tls from 'node:tls'; import { logger } from '@sentry/utils'; import { Agent } from './base'; import type { AgentConnectOpts } from './base'; diff --git a/packages/node/src/proxy/parse-proxy-response.ts b/packages/node/src/proxy/parse-proxy-response.ts index e351945e3c0f..a01e6675b765 100644 --- a/packages/node/src/proxy/parse-proxy-response.ts +++ b/packages/node/src/proxy/parse-proxy-response.ts @@ -28,8 +28,8 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable jsdoc/require-jsdoc */ -import type { IncomingHttpHeaders } from 'http'; -import type { Readable } from 'stream'; +import type { IncomingHttpHeaders } from 'node:http'; +import type { Readable } from 'node:stream'; import { logger } from '@sentry/utils'; function debug(...args: unknown[]): void { diff --git a/packages/node/src/sdk/client.ts b/packages/node/src/sdk/client.ts index b2d23ea31cc2..31758d182dfc 100644 --- a/packages/node/src/sdk/client.ts +++ b/packages/node/src/sdk/client.ts @@ -1,4 +1,4 @@ -import * as os from 'os'; +import * as os from 'node:os'; import type { Tracer } from '@opentelemetry/api'; import { trace } from '@opentelemetry/api'; import type { BasicTracerProvider } from '@opentelemetry/sdk-trace-base'; diff --git a/packages/node/src/transports/http.ts b/packages/node/src/transports/http.ts index d4d7435bdc6d..d8ae6dd57865 100644 --- a/packages/node/src/transports/http.ts +++ b/packages/node/src/transports/http.ts @@ -1,7 +1,7 @@ import * as http from 'node:http'; import * as https from 'node:https'; -import { Readable } from 'stream'; -import { createGzip } from 'zlib'; +import { Readable } from 'node:stream'; +import { createGzip } from 'node:zlib'; import { createTransport, suppressTracing } from '@sentry/core'; import type { BaseTransportOptions, diff --git a/packages/node/src/utils/getRequestUrl.ts b/packages/node/src/utils/getRequestUrl.ts index 1e4dcfb71232..5005224f59e0 100644 --- a/packages/node/src/utils/getRequestUrl.ts +++ b/packages/node/src/utils/getRequestUrl.ts @@ -1,4 +1,4 @@ -import type { RequestOptions } from 'http'; +import type { RequestOptions } from 'node:http'; /** Build a full URL from request options. */ export function getRequestUrl(requestOptions: RequestOptions): string { diff --git a/packages/node/src/utils/module.ts b/packages/node/src/utils/module.ts index d873bf9b2f2e..aad8195d1b1f 100644 --- a/packages/node/src/utils/module.ts +++ b/packages/node/src/utils/module.ts @@ -1,4 +1,4 @@ -import { posix, sep } from 'path'; +import { posix, sep } from 'node:path'; import { dirname } from '@sentry/utils'; /** normalizes Windows paths */ diff --git a/packages/profiling-node/src/cpu_profiler.ts b/packages/profiling-node/src/cpu_profiler.ts index b31e6f4d25d0..433ade1d4b46 100644 --- a/packages/profiling-node/src/cpu_profiler.ts +++ b/packages/profiling-node/src/cpu_profiler.ts @@ -1,9 +1,9 @@ -import { arch as _arch, platform as _platform } from 'os'; -import { join, resolve } from 'path'; +import { arch as _arch, platform as _platform } from 'node:os'; +import { join, resolve } from 'node:path'; +import { env, versions } from 'node:process'; +import { threadId } from 'node:worker_threads'; import { familySync } from 'detect-libc'; import { getAbi } from 'node-abi'; -import { env, versions } from 'process'; -import { threadId } from 'worker_threads'; import { GLOBAL_OBJ, logger } from '@sentry/utils'; import { DEBUG_BUILD } from './debug-build'; diff --git a/packages/profiling-node/src/utils.ts b/packages/profiling-node/src/utils.ts index ce61fdeef5d9..884e71c3d10e 100644 --- a/packages/profiling-node/src/utils.ts +++ b/packages/profiling-node/src/utils.ts @@ -1,7 +1,7 @@ -import * as os from 'os'; +import * as os from 'node:os'; +import { env, versions } from 'node:process'; +import { isMainThread, threadId } from 'node:worker_threads'; import type { Client, Context, Envelope, Event, StackFrame, StackParser } from '@sentry/types'; -import { env, versions } from 'process'; -import { isMainThread, threadId } from 'worker_threads'; import { GLOBAL_OBJ, forEachEnvelopeItem, logger } from '@sentry/utils'; From e16b5a9757f252d61c12ede16bc1c678b5aa2efb Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Sat, 4 May 2024 04:18:19 +0100 Subject: [PATCH 2/3] Fix tests --- packages/node/test/integrations/contextlines.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/node/test/integrations/contextlines.test.ts b/packages/node/test/integrations/contextlines.test.ts index c4ef1efaa292..3c6394f9ac52 100644 --- a/packages/node/test/integrations/contextlines.test.ts +++ b/packages/node/test/integrations/contextlines.test.ts @@ -1,4 +1,4 @@ -import { promises } from 'fs'; +import { promises } from 'node:fs'; import type { StackFrame } from '@sentry/types'; import { parseStackFrames } from '@sentry/utils'; @@ -6,8 +6,8 @@ import { _contextLinesIntegration, resetFileContentCache } from '../../src/integ import { defaultStackParser } from '../../src/sdk/api'; import { getError } from '../helpers/error'; -jest.mock('fs', () => { - const actual = jest.requireActual('fs'); +jest.mock('node:fs', () => { + const actual = jest.requireActual('node:fs'); return { ...actual, promises: { From c6004e4181c48a0f721dcb18b526c4b14e76ebf5 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 6 May 2024 16:54:27 +0100 Subject: [PATCH 3/3] ignore more node built-ins --- .size-limit.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.size-limit.js b/.size-limit.js index 9ead34df50f0..3fc0ea704888 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -194,6 +194,19 @@ module.exports = [ 'node:http', 'node:https', 'node:diagnostics_channel', + 'node:perf_hooks', + 'node:worker_threads', + 'node:inspector', + 'node:path', + 'node:fs', + 'node:stream', + 'node:os', + 'node:net', + 'node:zlib', + 'node:child_process', + 'node:tls', + 'node:async_hooks', + 'node:util', 'async_hooks', 'child_process', 'fs',