Skip to content

feat(deno): Expose functional integrations to replace classes #10355

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 1 commit into from
Jan 25, 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
7 changes: 5 additions & 2 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ The following list shows how integrations should be migrated:
| `new RewriteFrames()` | `rewriteFramesIntegration()` | `@sentry/integrations` |
| `new SessionTiming()` | `sessionTimingIntegration()` | `@sentry/integrations` |
| `new HttpClient()` | `httpClientIntegration()` | `@sentry/integrations` |
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/browser` |
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/browser`, `@sentry/deno` |
| `new Breadcrumbs()` | `breadcrumbsIntegration()` | `@sentry/browser`, `@sentry/deno` |
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` |
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` , `@sentry/deno` |
| `new HttpContext()` | `httpContextIntegration()` | `@sentry/browser` |
| `new TryCatch()` | `browserApiErrorsIntegration()` | `@sentry/browser`, `@sentry/deno` |
| `new VueIntegration()` | `vueIntegration()` | `@sentry/vue` |
| `new DenoContext()` | `denoContextIntegration()` | `@sentry/deno` |
| `new DenoCron()` | `denoCronIntegration()` | `@sentry/deno` |
| `new NormalizePaths()` | `normalizePathsIntegration()` | `@sentry/deno` |

## Deprecate `hub.bindClient()` and `makeMain()`

Expand Down
11 changes: 8 additions & 3 deletions packages/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ export {
export { breadcrumbsIntegration, dedupeIntegration } from '@sentry/browser';
import { Integrations as CoreIntegrations } from '@sentry/core';

export { denoContextIntegration } from './integrations/context';
export { globalHandlersIntegration } from './integrations/globalhandlers';
export { normalizePathsIntegration } from './integrations/normalizepaths';
export { contextLinesIntegration } from './integrations/contextlines';
export { denoCronIntegration } from './integrations/deno-cron';

import * as DenoIntegrations from './integrations';

const INTEGRATIONS = {
/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
export const Integrations = {
// eslint-disable-next-line deprecation/deprecation
...CoreIntegrations,
...DenoIntegrations,
};

export { INTEGRATIONS as Integrations };
14 changes: 11 additions & 3 deletions packages/deno/src/integrations/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';

const INTEGRATION_NAME = 'DenoContext';
Expand Down Expand Up @@ -52,7 +52,7 @@ async function addDenoRuntimeContext(event: Event): Promise<Event> {
return event;
}

const denoContextIntegration = (() => {
const _denoContextIntegration = (() => {
return {
name: INTEGRATION_NAME,
// TODO v8: Remove this
Expand All @@ -63,8 +63,16 @@ const denoContextIntegration = (() => {
};
}) satisfies IntegrationFn;

/** Adds Deno context to events. */
export const denoContextIntegration = defineIntegration(_denoContextIntegration);

/**
* Adds Deno context to events.
* @deprecated Use `denoContextintegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const DenoContext = convertIntegrationFnToClass(INTEGRATION_NAME, denoContextIntegration) as IntegrationClass<
Integration & { processEvent: (event: Event) => Promise<Event> }
>;

// eslint-disable-next-line deprecation/deprecation
export type DenoContext = typeof DenoContext;
21 changes: 14 additions & 7 deletions packages/deno/src/integrations/contextlines.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
import { LRUMap, addContextToFrame } from '@sentry/utils';

Expand Down Expand Up @@ -47,7 +47,7 @@ interface ContextLinesOptions {
frameContextLines?: number;
}

const denoContextLinesIntegration = ((options: ContextLinesOptions = {}) => {
const _contextLinesIntegration = ((options: ContextLinesOptions = {}) => {
const contextLines = options.frameContextLines !== undefined ? options.frameContextLines : DEFAULT_LINES_OF_CONTEXT;

return {
Expand All @@ -60,12 +60,19 @@ const denoContextLinesIntegration = ((options: ContextLinesOptions = {}) => {
};
}) satisfies IntegrationFn;

/** Add node modules / packages to the event */
export const contextLinesIntegration = defineIntegration(_contextLinesIntegration);

/**
* Add node modules / packages to the event.
* @deprecated Use `contextLinesIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const ContextLines = convertIntegrationFnToClass(INTEGRATION_NAME, contextLinesIntegration) as IntegrationClass<
Integration & { processEvent: (event: Event) => Promise<Event> }
>;

// eslint-disable-next-line deprecation/deprecation
export const ContextLines = convertIntegrationFnToClass(
INTEGRATION_NAME,
denoContextLinesIntegration,
) as IntegrationClass<Integration & { processEvent: (event: Event) => Promise<Event> }>;
export type ContextLines = typeof ContextLines;

/** Processes an event and adds context lines */
async function addSourceContext(event: Event, contextLines: number): Promise<Event> {
Expand Down
14 changes: 11 additions & 3 deletions packages/deno/src/integrations/deno-cron.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass, getClient, withMonitor } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration, getClient, withMonitor } from '@sentry/core';
import type { Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import { parseScheduleToString } from './deno-cron-format';

Expand All @@ -11,7 +11,7 @@ const INTEGRATION_NAME = 'DenoCron';

const SETUP_CLIENTS = new WeakMap<Client, boolean>();

const denoCronIntegration = (() => {
const _denoCronIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
Expand Down Expand Up @@ -60,8 +60,16 @@ const denoCronIntegration = (() => {
};
}) satisfies IntegrationFn;

/** Instruments Deno.cron to automatically capture cron check-ins */
export const denoCronIntegration = defineIntegration(_denoCronIntegration);

/**
* Instruments Deno.cron to automatically capture cron check-ins.
* @deprecated Use `denoCronIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const DenoCron = convertIntegrationFnToClass(INTEGRATION_NAME, denoCronIntegration) as IntegrationClass<
Integration & { setup: (client: Client) => void }
>;

// eslint-disable-next-line deprecation/deprecation
export type DenoCron = typeof DenoCron;
13 changes: 11 additions & 2 deletions packages/deno/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ServerRuntimeClient } from '@sentry/core';
import { defineIntegration } from '@sentry/core';
import { convertIntegrationFnToClass } from '@sentry/core';
import { captureEvent } from '@sentry/core';
import { getClient } from '@sentry/core';
Expand All @@ -21,7 +22,7 @@ type GlobalHandlersIntegrations = Record<GlobalHandlersIntegrationsOptionKeys, b
const INTEGRATION_NAME = 'GlobalHandlers';
let isExiting = false;

const globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {
const _globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {
const _options = {
error: true,
unhandledrejection: true,
Expand All @@ -43,13 +44,21 @@ const globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {
};
}) satisfies IntegrationFn;

/** Global handlers */
export const globalHandlersIntegration = defineIntegration(_globalHandlersIntegration);

/**
* Global handlers.
* @deprecated Use `globalHandlersIntergation()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const GlobalHandlers = convertIntegrationFnToClass(
INTEGRATION_NAME,
globalHandlersIntegration,
) as IntegrationClass<Integration & { setup: (client: Client) => void }>;

// eslint-disable-next-line deprecation/deprecation
export type GlobalHandlers = typeof GlobalHandlers;

function installGlobalErrorHandler(client: Client): void {
globalThis.addEventListener('error', data => {
if (getClient() !== client || isExiting) {
Expand Down
1 change: 1 addition & 0 deletions packages/deno/src/integrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable deprecation/deprecation */
export { DenoContext } from './context';
export { GlobalHandlers } from './globalhandlers';
export { NormalizePaths } from './normalizepaths';
Expand Down
14 changes: 11 additions & 3 deletions packages/deno/src/integrations/normalizepaths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
import type { Event, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
import { createStackParser, dirname, nodeStackLineParser } from '@sentry/utils';

Expand Down Expand Up @@ -55,7 +55,7 @@ function getCwd(): string | undefined {
return undefined;
}

const normalizePathsIntegration = (() => {
const _normalizePathsIntegration = (() => {
// Cached here
let appRoot: string | undefined;

Expand Down Expand Up @@ -98,9 +98,17 @@ const normalizePathsIntegration = (() => {
};
}) satisfies IntegrationFn;

/** Normalises paths to the app root directory. */
export const normalizePathsIntegration = defineIntegration(_normalizePathsIntegration);

/**
* Normalises paths to the app root directory.
* @deprecated Use `normalizePathsIntegration()` instead.
*/
// eslint-disable-next-line deprecation/deprecation
export const NormalizePaths = convertIntegrationFnToClass(
INTEGRATION_NAME,
normalizePathsIntegration,
) as IntegrationClass<Integration & { processEvent: (event: Event) => Event }>;

// eslint-disable-next-line deprecation/deprecation
export type NormalizePaths = typeof NormalizePaths;
13 changes: 8 additions & 5 deletions packages/deno/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import type { Integration, Options, StackParser } from '@sentry/types';
import { createStackParser, nodeStackLineParser, stackParserFromStackParserOptions } from '@sentry/utils';

import { DenoClient } from './client';
import { ContextLines, DenoContext, GlobalHandlers, NormalizePaths } from './integrations';
import { denoContextIntegration } from './integrations/context';
import { contextLinesIntegration } from './integrations/contextlines';
import { globalHandlersIntegration } from './integrations/globalhandlers';
import { normalizePathsIntegration } from './integrations/normalizepaths';
import { makeFetchTransport } from './transports';
import type { DenoOptions } from './types';

Expand All @@ -24,10 +27,10 @@ export const defaultIntegrations = [
xhr: false,
}),
// Deno Specific
new DenoContext(),
new ContextLines(),
new NormalizePaths(),
new GlobalHandlers(),
denoContextIntegration(),
contextLinesIntegration(),
normalizePathsIntegration(),
globalHandlersIntegration(),
];

/** Get the default integrations for the Deno SDK. */
Expand Down