-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathsdk.ts
More file actions
34 lines (30 loc) · 1.52 KB
/
sdk.ts
File metadata and controls
34 lines (30 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { Client, Integration } from '@sentry/core';
import { applySdkMetadata, getIntegrationsToSetup } from '@sentry/core';
import { init as initNode } from '@sentry/node';
import type { HonoNodeOptions } from './middleware';
import { filterHonoIntegration } from '../shared/filterHonoIntegration';
/**
* Initializes Sentry for Hono running in a Node runtime environment.
*
* In general, it is recommended to initialize Sentry via the `sentry()` middleware, as it sets up everything by default and calls `init` internally.
*
* When manually calling `init`, add the `honoIntegration` to the `integrations` array to set up the Hono integration.
*/
export function init(options: HonoNodeOptions): Client | undefined {
applySdkMetadata(options, 'hono', ['hono', 'node']);
const { integrations: userIntegrations } = options;
// Remove Hono from the SDK defaults to prevent double instrumentation: @sentry/node
const filteredOptions: HonoNodeOptions = {
...options,
integrations: Array.isArray(userIntegrations)
? (defaults: Integration[]) =>
getIntegrationsToSetup({
defaultIntegrations: defaults.filter(filterHonoIntegration),
integrations: userIntegrations, // user's explicit Hono integration is preserved
})
: typeof userIntegrations === 'function'
? (defaults: Integration[]) => userIntegrations(defaults.filter(filterHonoIntegration))
: (defaults: Integration[]) => defaults.filter(filterHonoIntegration),
};
return initNode(filteredOptions);
}