Skip to content

Commit 2879478

Browse files
authored
feat(deno): Expose functional integrations to replace classes (#10355)
Refactor deno integrations to functional style.
1 parent e0869ab commit 2879478

File tree

9 files changed

+80
-28
lines changed

9 files changed

+80
-28
lines changed

MIGRATION.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ The following list shows how integrations should be migrated:
5353
| `new RewriteFrames()` | `rewriteFramesIntegration()` | `@sentry/integrations` |
5454
| `new SessionTiming()` | `sessionTimingIntegration()` | `@sentry/integrations` |
5555
| `new HttpClient()` | `httpClientIntegration()` | `@sentry/integrations` |
56-
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/browser` |
56+
| `new ContextLines()` | `contextLinesIntegration()` | `@sentry/browser`, `@sentry/deno` |
5757
| `new Breadcrumbs()` | `breadcrumbsIntegration()` | `@sentry/browser`, `@sentry/deno` |
58-
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` |
58+
| `new GlobalHandlers()` | `globalHandlersIntegration()` | `@sentry/browser` , `@sentry/deno` |
5959
| `new HttpContext()` | `httpContextIntegration()` | `@sentry/browser` |
6060
| `new TryCatch()` | `browserApiErrorsIntegration()` | `@sentry/browser`, `@sentry/deno` |
6161
| `new VueIntegration()` | `vueIntegration()` | `@sentry/vue` |
62+
| `new DenoContext()` | `denoContextIntegration()` | `@sentry/deno` |
63+
| `new DenoCron()` | `denoCronIntegration()` | `@sentry/deno` |
64+
| `new NormalizePaths()` | `normalizePathsIntegration()` | `@sentry/deno` |
6265

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

packages/deno/src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ export {
9797
export { breadcrumbsIntegration, dedupeIntegration } from '@sentry/browser';
9898
import { Integrations as CoreIntegrations } from '@sentry/core';
9999

100+
export { denoContextIntegration } from './integrations/context';
101+
export { globalHandlersIntegration } from './integrations/globalhandlers';
102+
export { normalizePathsIntegration } from './integrations/normalizepaths';
103+
export { contextLinesIntegration } from './integrations/contextlines';
104+
export { denoCronIntegration } from './integrations/deno-cron';
105+
100106
import * as DenoIntegrations from './integrations';
101107

102-
const INTEGRATIONS = {
108+
/** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
109+
export const Integrations = {
103110
// eslint-disable-next-line deprecation/deprecation
104111
...CoreIntegrations,
105112
...DenoIntegrations,
106113
};
107-
108-
export { INTEGRATIONS as Integrations };

packages/deno/src/integrations/context.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33

44
const INTEGRATION_NAME = 'DenoContext';
@@ -52,7 +52,7 @@ async function addDenoRuntimeContext(event: Event): Promise<Event> {
5252
return event;
5353
}
5454

55-
const denoContextIntegration = (() => {
55+
const _denoContextIntegration = (() => {
5656
return {
5757
name: INTEGRATION_NAME,
5858
// TODO v8: Remove this
@@ -63,8 +63,16 @@ const denoContextIntegration = (() => {
6363
};
6464
}) satisfies IntegrationFn;
6565

66-
/** Adds Deno context to events. */
66+
export const denoContextIntegration = defineIntegration(_denoContextIntegration);
67+
68+
/**
69+
* Adds Deno context to events.
70+
* @deprecated Use `denoContextintegration()` instead.
71+
*/
6772
// eslint-disable-next-line deprecation/deprecation
6873
export const DenoContext = convertIntegrationFnToClass(INTEGRATION_NAME, denoContextIntegration) as IntegrationClass<
6974
Integration & { processEvent: (event: Event) => Promise<Event> }
7075
>;
76+
77+
// eslint-disable-next-line deprecation/deprecation
78+
export type DenoContext = typeof DenoContext;

packages/deno/src/integrations/contextlines.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Integration, IntegrationClass, IntegrationFn, StackFrame } from '@sentry/types';
33
import { LRUMap, addContextToFrame } from '@sentry/utils';
44

@@ -47,7 +47,7 @@ interface ContextLinesOptions {
4747
frameContextLines?: number;
4848
}
4949

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

5353
return {
@@ -60,12 +60,19 @@ const denoContextLinesIntegration = ((options: ContextLinesOptions = {}) => {
6060
};
6161
}) satisfies IntegrationFn;
6262

63-
/** Add node modules / packages to the event */
63+
export const contextLinesIntegration = defineIntegration(_contextLinesIntegration);
64+
65+
/**
66+
* Add node modules / packages to the event.
67+
* @deprecated Use `contextLinesIntegration()` instead.
68+
*/
69+
// eslint-disable-next-line deprecation/deprecation
70+
export const ContextLines = convertIntegrationFnToClass(INTEGRATION_NAME, contextLinesIntegration) as IntegrationClass<
71+
Integration & { processEvent: (event: Event) => Promise<Event> }
72+
>;
73+
6474
// eslint-disable-next-line deprecation/deprecation
65-
export const ContextLines = convertIntegrationFnToClass(
66-
INTEGRATION_NAME,
67-
denoContextLinesIntegration,
68-
) as IntegrationClass<Integration & { processEvent: (event: Event) => Promise<Event> }>;
75+
export type ContextLines = typeof ContextLines;
6976

7077
/** Processes an event and adds context lines */
7178
async function addSourceContext(event: Event, contextLines: number): Promise<Event> {

packages/deno/src/integrations/deno-cron.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass, getClient, withMonitor } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration, getClient, withMonitor } from '@sentry/core';
22
import type { Client, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33
import { parseScheduleToString } from './deno-cron-format';
44

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

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

14-
const denoCronIntegration = (() => {
14+
const _denoCronIntegration = (() => {
1515
return {
1616
name: INTEGRATION_NAME,
1717
setupOnce() {
@@ -60,8 +60,16 @@ const denoCronIntegration = (() => {
6060
};
6161
}) satisfies IntegrationFn;
6262

63-
/** Instruments Deno.cron to automatically capture cron check-ins */
63+
export const denoCronIntegration = defineIntegration(_denoCronIntegration);
64+
65+
/**
66+
* Instruments Deno.cron to automatically capture cron check-ins.
67+
* @deprecated Use `denoCronIntegration()` instead.
68+
*/
6469
// eslint-disable-next-line deprecation/deprecation
6570
export const DenoCron = convertIntegrationFnToClass(INTEGRATION_NAME, denoCronIntegration) as IntegrationClass<
6671
Integration & { setup: (client: Client) => void }
6772
>;
73+
74+
// eslint-disable-next-line deprecation/deprecation
75+
export type DenoCron = typeof DenoCron;

packages/deno/src/integrations/globalhandlers.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ServerRuntimeClient } from '@sentry/core';
2+
import { defineIntegration } from '@sentry/core';
23
import { convertIntegrationFnToClass } from '@sentry/core';
34
import { captureEvent } from '@sentry/core';
45
import { getClient } from '@sentry/core';
@@ -21,7 +22,7 @@ type GlobalHandlersIntegrations = Record<GlobalHandlersIntegrationsOptionKeys, b
2122
const INTEGRATION_NAME = 'GlobalHandlers';
2223
let isExiting = false;
2324

24-
const globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {
25+
const _globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {
2526
const _options = {
2627
error: true,
2728
unhandledrejection: true,
@@ -43,13 +44,21 @@ const globalHandlersIntegration = ((options?: GlobalHandlersIntegrations) => {
4344
};
4445
}) satisfies IntegrationFn;
4546

46-
/** Global handlers */
47+
export const globalHandlersIntegration = defineIntegration(_globalHandlersIntegration);
48+
49+
/**
50+
* Global handlers.
51+
* @deprecated Use `globalHandlersIntergation()` instead.
52+
*/
4753
// eslint-disable-next-line deprecation/deprecation
4854
export const GlobalHandlers = convertIntegrationFnToClass(
4955
INTEGRATION_NAME,
5056
globalHandlersIntegration,
5157
) as IntegrationClass<Integration & { setup: (client: Client) => void }>;
5258

59+
// eslint-disable-next-line deprecation/deprecation
60+
export type GlobalHandlers = typeof GlobalHandlers;
61+
5362
function installGlobalErrorHandler(client: Client): void {
5463
globalThis.addEventListener('error', data => {
5564
if (getClient() !== client || isExiting) {

packages/deno/src/integrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable deprecation/deprecation */
12
export { DenoContext } from './context';
23
export { GlobalHandlers } from './globalhandlers';
34
export { NormalizePaths } from './normalizepaths';

packages/deno/src/integrations/normalizepaths.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertIntegrationFnToClass } from '@sentry/core';
1+
import { convertIntegrationFnToClass, defineIntegration } from '@sentry/core';
22
import type { Event, Integration, IntegrationClass, IntegrationFn } from '@sentry/types';
33
import { createStackParser, dirname, nodeStackLineParser } from '@sentry/utils';
44

@@ -55,7 +55,7 @@ function getCwd(): string | undefined {
5555
return undefined;
5656
}
5757

58-
const normalizePathsIntegration = (() => {
58+
const _normalizePathsIntegration = (() => {
5959
// Cached here
6060
let appRoot: string | undefined;
6161

@@ -98,9 +98,17 @@ const normalizePathsIntegration = (() => {
9898
};
9999
}) satisfies IntegrationFn;
100100

101-
/** Normalises paths to the app root directory. */
101+
export const normalizePathsIntegration = defineIntegration(_normalizePathsIntegration);
102+
103+
/**
104+
* Normalises paths to the app root directory.
105+
* @deprecated Use `normalizePathsIntegration()` instead.
106+
*/
102107
// eslint-disable-next-line deprecation/deprecation
103108
export const NormalizePaths = convertIntegrationFnToClass(
104109
INTEGRATION_NAME,
105110
normalizePathsIntegration,
106111
) as IntegrationClass<Integration & { processEvent: (event: Event) => Event }>;
112+
113+
// eslint-disable-next-line deprecation/deprecation
114+
export type NormalizePaths = typeof NormalizePaths;

packages/deno/src/sdk.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import type { Integration, Options, StackParser } from '@sentry/types';
66
import { createStackParser, nodeStackLineParser, stackParserFromStackParserOptions } from '@sentry/utils';
77

88
import { DenoClient } from './client';
9-
import { ContextLines, DenoContext, GlobalHandlers, NormalizePaths } from './integrations';
9+
import { denoContextIntegration } from './integrations/context';
10+
import { contextLinesIntegration } from './integrations/contextlines';
11+
import { globalHandlersIntegration } from './integrations/globalhandlers';
12+
import { normalizePathsIntegration } from './integrations/normalizepaths';
1013
import { makeFetchTransport } from './transports';
1114
import type { DenoOptions } from './types';
1215

@@ -24,10 +27,10 @@ export const defaultIntegrations = [
2427
xhr: false,
2528
}),
2629
// Deno Specific
27-
new DenoContext(),
28-
new ContextLines(),
29-
new NormalizePaths(),
30-
new GlobalHandlers(),
30+
denoContextIntegration(),
31+
contextLinesIntegration(),
32+
normalizePathsIntegration(),
33+
globalHandlersIntegration(),
3134
];
3235

3336
/** Get the default integrations for the Deno SDK. */

0 commit comments

Comments
 (0)