Skip to content
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

fix(node): Fix type definitions #10339

Merged
merged 10 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,32 @@ jobs:
cd packages/utils
yarn test:package

job_check_for_faulty_dts:
name: Check for faulty .d.ts files
needs: [job_get_metadata, job_build]
runs-on: ubuntu-20.04
timeout-minutes: 5
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v4
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check for dts files that reference stuff in the temporary build folder
run: |
if grep -r --include "*.d.ts" --exclude-dir ".nxcache" 'import("@sentry/.*/build' .; then
echo "Found illegal TypeScript import statement."
exit 1
fi


job_node_integration_tests:
name:
Node (${{ matrix.node }})${{ (matrix.typescript && format(' (TS {0})', matrix.typescript)) || '' }} Integration
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/src/server/httpIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Integrations } from '@sentry/node';
const { Http: OriginalHttp } = Integrations;

/**
* A custom HTTP integration where we always enable tracing.
*/
export class Http extends OriginalHttp {
public constructor(options?: ConstructorParameters<typeof OriginalHttp>[0]) {
export class Http extends Integrations.Http {
public constructor(options?: ConstructorParameters<typeof Integrations.Http>[0]) {
super({
...options,
tracing: true,
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/src/server/onUncaughtExceptionIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Integrations } from '@sentry/node';
const { OnUncaughtException: OriginalOnUncaughtException } = Integrations;

/**
* A custom OnUncaughtException integration that does not exit by default.
*/
export class OnUncaughtException extends OriginalOnUncaughtException {
public constructor(options?: ConstructorParameters<typeof OriginalOnUncaughtException>[0]) {
export class OnUncaughtException extends Integrations.OnUncaughtException {
public constructor(options?: ConstructorParameters<typeof Integrations.OnUncaughtException>[0]) {
super({
exitEvenIfOtherHandlersAreRegistered: false,
...options,
Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ const INTEGRATIONS = {
...TracingIntegrations,
};

export type { LocalVariablesIntegrationOptions } from './integrations/local-variables/common';
export type { DebugSession } from './integrations/local-variables/local-variables-sync';
export type { AnrIntegrationOptions } from './integrations/anr/common';

export { Undici } from './integrations/undici';

export { INTEGRATIONS as Integrations, Handlers };

export { hapiErrorPlugin } from './integrations/hapi';
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/anr/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Contexts, DsnComponents, Primitive, SdkMetadata } from '@sentry/types';

export interface Options {
export interface AnrIntegrationOptions {
/**
* Interval to send heartbeat messages to the ANR worker.
*
Expand Down Expand Up @@ -33,7 +33,7 @@ export interface Options {
appRootPath: string | undefined;
}

export interface WorkerStartData extends Options {
export interface WorkerStartData extends AnrIntegrationOptions {
debug: boolean;
sdkMetadata: SdkMetadata;
dsn: DsnComponents;
Expand Down
8 changes: 4 additions & 4 deletions packages/node/src/integrations/anr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dynamicRequire, logger } from '@sentry/utils';
import type { Worker, WorkerOptions } from 'worker_threads';
import type { NodeClient } from '../../client';
import { NODE_VERSION } from '../../nodeVersion';
import type { Options, WorkerStartData } from './common';
import type { AnrIntegrationOptions, WorkerStartData } from './common';
import { base64WorkerScript } from './worker-script';

const DEFAULT_INTERVAL = 50;
Expand Down Expand Up @@ -52,7 +52,7 @@ interface InspectorApi {

const INTEGRATION_NAME = 'Anr';

const anrIntegration = ((options: Partial<Options> = {}) => {
const anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
Expand All @@ -77,13 +77,13 @@ const anrIntegration = ((options: Partial<Options> = {}) => {
export const Anr = convertIntegrationFnToClass(INTEGRATION_NAME, anrIntegration) as IntegrationClass<
Integration & { setup: (client: NodeClient) => void }
> & {
new (options?: Partial<Options>): Integration & { setup(client: Client): void };
new (options?: Partial<AnrIntegrationOptions>): Integration & { setup(client: Client): void };
};

/**
* Starts the ANR worker thread
*/
async function _startWorker(client: NodeClient, _options: Partial<Options>): Promise<void> {
async function _startWorker(client: NodeClient, _options: Partial<AnrIntegrationOptions>): Promise<void> {
const contexts = await getContexts(client);
const dsn = client.getDsn();

Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/local-variables/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface FrameVariables {
vars?: Variables;
}

export interface Options {
export interface LocalVariablesIntegrationOptions {
/**
* Capture local variables for both caught and uncaught exceptions
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import type { Debugger, InspectorNotification, Runtime } from 'inspector';

import type { NodeClient } from '../../client';
import type { NodeClientOptions } from '../../types';
import type { FrameVariables, Options, PausedExceptionEvent, RateLimitIncrement, Variables } from './common';
import type {
FrameVariables,
LocalVariablesIntegrationOptions,
PausedExceptionEvent,
RateLimitIncrement,
Variables,
} from './common';
import { createRateLimiter, functionNamesMatch, hashFrames, hashFromStack } from './common';

async function unrollArray(session: Session, objectId: string, name: string, vars: Variables): Promise<void> {
Expand Down Expand Up @@ -70,7 +76,7 @@ const INTEGRATION_NAME = 'LocalVariablesAsync';
/**
* Adds local variables to exception frames
*/
const localVariablesAsyncIntegration = ((options: Options = {}) => {
const localVariablesAsyncIntegration = ((options: LocalVariablesIntegrationOptions = {}) => {
const cachedFrames: LRUMap<string, FrameVariables[]> = new LRUMap(20);
let rateLimiter: RateLimitIncrement | undefined;
let shouldProcessEvent = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import type { Debugger, InspectorNotification, Runtime, Session } from 'inspecto
import type { NodeClient } from '../../client';

import { NODE_VERSION } from '../../nodeVersion';
import type { FrameVariables, Options, PausedExceptionEvent, RateLimitIncrement, Variables } from './common';
import type {
FrameVariables,
LocalVariablesIntegrationOptions,
PausedExceptionEvent,
RateLimitIncrement,
Variables,
} from './common';
import { createRateLimiter, functionNamesMatch, hashFrames, hashFromStack } from './common';

type OnPauseEvent = InspectorNotification<Debugger.PausedEventDataType>;
Expand Down Expand Up @@ -214,7 +220,7 @@ const INTEGRATION_NAME = 'LocalVariables';
* Adds local variables to exception frames
*/
const localVariablesSyncIntegration = ((
options: Options = {},
options: LocalVariablesIntegrationOptions = {},
session: DebugSession | undefined = tryNewAsyncSession(),
) => {
const cachedFrames: LRUMap<string, FrameVariables[]> = new LRUMap(20);
Expand Down Expand Up @@ -394,5 +400,5 @@ export const LocalVariablesSync = convertIntegrationFnToClass(
INTEGRATION_NAME,
localVariablesSyncIntegration,
) as IntegrationClass<Integration & { processEvent: (event: Event) => Event; setup: (client: NodeClient) => void }> & {
new (options?: Options, session?: DebugSession): Integration;
new (options?: LocalVariablesIntegrationOptions, session?: DebugSession): Integration;
};