Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ export {
wrap,
} from './sdk';
export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';
export * from './integrations/index-functions';
2 changes: 1 addition & 1 deletion packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ export type { SpanStatusType } from '@sentry/core';
export type { Span } from '@sentry/types';
export { makeBrowserOfflineTransport } from './transports/offline';
export { onProfilingStartRouteTransaction } from './profiling/hubextensions';
export { BrowserProfilingIntegration } from './profiling/integration';
export { BrowserProfilingIntegration, browserProfilingIntegration } from './profiling/integration';
27 changes: 24 additions & 3 deletions packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
HandlerDataFetch,
HandlerDataHistory,
HandlerDataXhr,
Integration,
IntegrationClass,
IntegrationFn,
} from '@sentry/types';
import type {
Expand Down Expand Up @@ -55,7 +57,7 @@ const MAX_ALLOWED_STRING_LENGTH = 1024;

const INTEGRATION_NAME = 'Breadcrumbs';

const breadcrumbsIntegration: IntegrationFn = (options: Partial<BreadcrumbsOptions> = {}) => {
export const breadcrumbsIntegration = ((options: Partial<BreadcrumbsOptions> = {}) => {
const _options = {
console: true,
dom: true,
Expand Down Expand Up @@ -91,13 +93,32 @@ const breadcrumbsIntegration: IntegrationFn = (options: Partial<BreadcrumbsOptio
}
},
};
};
}) satisfies IntegrationFn;

/**
* Default Breadcrumbs instrumentations
*/
// eslint-disable-next-line deprecation/deprecation
export const Breadcrumbs = convertIntegrationFnToClass(INTEGRATION_NAME, breadcrumbsIntegration);
export const Breadcrumbs = convertIntegrationFnToClass(
INTEGRATION_NAME,
breadcrumbsIntegration,
) as IntegrationClass<Integration> & {
new (
options?: Partial<{
console: boolean;
dom:
| boolean
| {
serializeAttribute?: string | string[];
maxStringLength?: number;
};
fetch: boolean;
history: boolean;
sentry: boolean;
xhr: boolean;
}>,
): Integration;
};

/**
* Adds a breadcrumb for Sentry events or transactions if this option is enabled.
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DEBUG_BUILD } from '../debug-build';

const INTEGRATION_NAME = 'Dedupe';

const dedupeIntegration: IntegrationFn = () => {
export const dedupeIntegration = (() => {
let previousEvent: Event | undefined;

return {
Expand All @@ -31,7 +31,7 @@ const dedupeIntegration: IntegrationFn = () => {
return (previousEvent = currentEvent);
},
};
};
}) satisfies IntegrationFn;

/** Deduplication filter */
// eslint-disable-next-line deprecation/deprecation
Expand Down
19 changes: 15 additions & 4 deletions packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { captureEvent, convertIntegrationFnToClass, getClient } from '@sentry/core';
import type { Client, Event, IntegrationFn, Primitive, StackParser } from '@sentry/types';
import type {
Client,
Event,
Integration,
IntegrationClass,
IntegrationFn,
Primitive,
StackParser,
} from '@sentry/types';
import {
addGlobalErrorInstrumentationHandler,
addGlobalUnhandledRejectionInstrumentationHandler,
Expand All @@ -22,7 +30,7 @@ type GlobalHandlersIntegrations = Record<GlobalHandlersIntegrationsOptionKeys, b

const INTEGRATION_NAME = 'GlobalHandlers';

const globalHandlersIntegrations: IntegrationFn = (options: Partial<GlobalHandlersIntegrations> = {}) => {
export const globalHandlersIntegration = ((options: Partial<GlobalHandlersIntegrations> = {}) => {
const _options = {
onerror: true,
onunhandledrejection: true,
Expand All @@ -45,11 +53,14 @@ const globalHandlersIntegrations: IntegrationFn = (options: Partial<GlobalHandle
}
},
};
};
}) satisfies IntegrationFn;

/** Global handlers */
// eslint-disable-next-line deprecation/deprecation
export const GlobalHandlers = convertIntegrationFnToClass(INTEGRATION_NAME, globalHandlersIntegrations);
export const GlobalHandlers = convertIntegrationFnToClass(
INTEGRATION_NAME,
globalHandlersIntegration,
) as IntegrationClass<Integration> & { new (options?: Partial<GlobalHandlersIntegrations>): Integration };

function _installGlobalOnErrorHandler(client: Client): void {
addGlobalErrorInstrumentationHandler(data => {
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/integrations/httpcontext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WINDOW } from '../helpers';

const INTEGRATION_NAME = 'HttpContext';

const httpContextIntegration: IntegrationFn = () => {
export const httpContextIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
Expand All @@ -31,7 +31,7 @@ const httpContextIntegration: IntegrationFn = () => {
event.request = request;
},
};
};
}) satisfies IntegrationFn;

/** HttpContext integration collects information about HTTP request headers */
// eslint-disable-next-line deprecation/deprecation
Expand Down
6 changes: 6 additions & 0 deletions packages/browser/src/integrations/index-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { globalHandlersIntegration } from './globalhandlers';
export { browserApiErrorsIntegration } from './trycatch';
export { breadcrumbsIntegration } from './breadcrumbs';
export { linkedErrorsIntegration } from './linkederrors';
export { httpContextIntegration } from './httpcontext';
export { dedupeIntegration } from './dedupe';
11 changes: 7 additions & 4 deletions packages/browser/src/integrations/linkederrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import type { IntegrationFn } from '@sentry/types';
import type { Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import { applyAggregateErrorsToEvent } from '@sentry/utils';
import { exceptionFromError } from '../eventbuilder';

Expand All @@ -13,7 +13,7 @@ const DEFAULT_LIMIT = 5;

const INTEGRATION_NAME = 'LinkedErrors';

const linkedErrorsIntegration: IntegrationFn = (options: LinkedErrorsOptions = {}) => {
export const linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
const limit = options.limit || DEFAULT_LIMIT;
const key = options.key || DEFAULT_KEY;

Expand All @@ -36,8 +36,11 @@ const linkedErrorsIntegration: IntegrationFn = (options: LinkedErrorsOptions = {
);
},
};
};
}) satisfies IntegrationFn;

/** Aggregrate linked errors in an event. */
// eslint-disable-next-line deprecation/deprecation
export const LinkedErrors = convertIntegrationFnToClass(INTEGRATION_NAME, linkedErrorsIntegration);
export const LinkedErrors = convertIntegrationFnToClass(
INTEGRATION_NAME,
linkedErrorsIntegration,
) as IntegrationClass<Integration> & { new (options?: { key?: string; limit?: number }): Integration };
19 changes: 15 additions & 4 deletions packages/browser/src/integrations/trycatch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import type { IntegrationFn, WrappedFunction } from '@sentry/types';
import type { Integration, IntegrationClass, IntegrationFn, WrappedFunction } from '@sentry/types';
import { fill, getFunctionName, getOriginalFunction } from '@sentry/utils';

import { WINDOW, wrap } from '../helpers';
Expand Down Expand Up @@ -50,7 +50,7 @@ interface TryCatchOptions {
eventTarget: boolean | string[];
}

const tryCatchIntegration: IntegrationFn = (options: Partial<TryCatchOptions> = {}) => {
export const browserApiErrorsIntegration = ((options: Partial<TryCatchOptions> = {}) => {
const _options = {
XMLHttpRequest: true,
eventTarget: true,
Expand Down Expand Up @@ -88,11 +88,22 @@ const tryCatchIntegration: IntegrationFn = (options: Partial<TryCatchOptions> =
}
},
};
};
}) satisfies IntegrationFn;

/** Wrap timer functions and event targets to catch errors and provide better meta data */
// eslint-disable-next-line deprecation/deprecation
export const TryCatch = convertIntegrationFnToClass(INTEGRATION_NAME, tryCatchIntegration);
export const TryCatch = convertIntegrationFnToClass(
INTEGRATION_NAME,
browserApiErrorsIntegration,
) as IntegrationClass<Integration> & {
new (options?: {
setTimeout: boolean;
setInterval: boolean;
requestAnimationFrame: boolean;
XMLHttpRequest: boolean;
eventTarget: boolean | string[];
}): Integration;
};

function _wrapTimeFunction(original: () => void): () => number {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/profiling/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

const INTEGRATION_NAME = 'BrowserProfiling';

const browserProfilingIntegration: IntegrationFn = () => {
export const browserProfilingIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
Expand Down Expand Up @@ -100,7 +100,7 @@ const browserProfilingIntegration: IntegrationFn = () => {
});
},
};
};
}) satisfies IntegrationFn;

/**
* Browser profiling integration. Stores any event that has contexts["profile"]["profile_id"]
Expand Down
1 change: 0 additions & 1 deletion packages/browser/test/unit/profiling/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('BrowserProfilingIntegration', () => {
Sentry.init({
tracesSampleRate: 1,
profilesSampleRate: 1,
debug: true,
environment: 'test-environment',
dsn: 'https://[email protected]/6625302',
transport: _opts => {
Expand Down
2 changes: 2 additions & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ const INTEGRATIONS = {
};

export { INTEGRATIONS as Integrations };

export { bunServerIntegration } from './integrations/bunserver';
4 changes: 2 additions & 2 deletions packages/bun/src/integrations/bunserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { getSanitizedUrlString, parseUrl } from '@sentry/utils';

const INTEGRATION_NAME = 'BunServer';

const bunServerIntegration: IntegrationFn = () => {
export const bunServerIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentBunServe();
},
};
};
}) satisfies IntegrationFn;

/**
* Instruments `Bun.serve` to automatically create transactions and capture errors.
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export {
convertIntegrationFnToClass,
} from './integration';
export { FunctionToString, InboundFilters, LinkedErrors } from './integrations';
export { inboundFiltersIntegration } from './integrations/inboundfilters';
export { linkedErrorsIntegration } from './integrations/linkederrors';
export { functionToStringIntegration } from './integrations/functiontostring';
export { requestDataIntegration } from './integrations/requestdata';
export { moduleMetadataIntegration } from './integrations/metadata';
export { applyScopeDataToEvent, mergeScopeData } from './utils/applyScopeDataToEvent';
export { prepareEvent } from './utils/prepareEvent';
export { createCheckInEnvelope } from './checkin';
Expand Down
20 changes: 5 additions & 15 deletions packages/core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Client, Event, EventHint, Integration, IntegrationFn, Options } from '@sentry/types';
import type { Client, Event, EventHint, Integration, IntegrationClass, IntegrationFn, Options } from '@sentry/types';
import { arrayify, logger } from '@sentry/utils';

import { DEBUG_BUILD } from './debug-build';
Expand Down Expand Up @@ -166,21 +166,11 @@ function findIndex<T>(arr: T[], callback: (item: T) => boolean): number {
*
* @deprecated This will be removed in v8!
*/
export function convertIntegrationFnToClass<Fn extends IntegrationFn>(
name: string,
fn: Fn,
): Integration & {
id: string;
new (...args: Parameters<Fn>): Integration & ReturnType<Fn>;
} {
export function convertIntegrationFnToClass(name: string, fn: IntegrationFn): IntegrationClass<Integration> {
return Object.assign(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function ConvertedIntegration(...rest: Parameters<Fn>) {
return fn(...rest);
function ConvertedIntegration(options?: Options) {
return fn(options);
},
{ id: name },
) as unknown as Integration & {
id: string;
new (...args: Parameters<Fn>): Integration & ReturnType<Fn>;
};
) as unknown as IntegrationClass<Integration>;
}
4 changes: 2 additions & 2 deletions packages/core/src/integrations/functiontostring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let originalFunctionToString: () => void;

const INTEGRATION_NAME = 'FunctionToString';

const functionToStringIntegration: IntegrationFn = () => {
export const functionToStringIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
Expand All @@ -26,7 +26,7 @@ const functionToStringIntegration: IntegrationFn = () => {
}
},
};
};
}) satisfies IntegrationFn;

/** Patch toString calls to return proper name for wrapped functions */
// eslint-disable-next-line deprecation/deprecation
Expand Down
23 changes: 19 additions & 4 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Event, IntegrationFn, StackFrame } from '@sentry/types';
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
import { getEventDescription, logger, stringMatchesSomePattern } from '@sentry/utils';

import { DEBUG_BUILD } from '../debug-build';
Expand Down Expand Up @@ -30,7 +30,7 @@ export interface InboundFiltersOptions {
}

const INTEGRATION_NAME = 'InboundFilters';
const inboundFiltersIntegration: IntegrationFn = (options: Partial<InboundFiltersOptions>) => {
export const inboundFiltersIntegration = ((options: Partial<InboundFiltersOptions> = {}) => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
Expand All @@ -41,11 +41,26 @@ const inboundFiltersIntegration: IntegrationFn = (options: Partial<InboundFilter
return _shouldDropEvent(event, mergedOptions) ? null : event;
},
};
};
}) satisfies IntegrationFn;

/** Inbound filters configurable by the user */
// eslint-disable-next-line deprecation/deprecation
export const InboundFilters = convertIntegrationFnToClass(INTEGRATION_NAME, inboundFiltersIntegration);
export const InboundFilters = convertIntegrationFnToClass(
INTEGRATION_NAME,
inboundFiltersIntegration,
) as IntegrationClass<Integration> & {
new (
options?: Partial<{
allowUrls: Array<string | RegExp>;
denyUrls: Array<string | RegExp>;
ignoreErrors: Array<string | RegExp>;
ignoreTransactions: Array<string | RegExp>;
ignoreInternal: boolean;
disableErrorDefaults: boolean;
disableTransactionDefaults: boolean;
}>,
): Integration;
};

function _mergeOptions(
internalOptions: Partial<InboundFiltersOptions> = {},
Expand Down
Loading