-
Notifications
You must be signed in to change notification settings - Fork 2
/
sentry.ts
35 lines (29 loc) · 1.1 KB
/
sentry.ts
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
35
import * as Sentry from '@sentry/node';
import type { CrawleeOneTelemetry } from './types';
import type { CrawleeOneCtx } from '../actor/types';
/**
* Sentry configuration common to all crawlers.
*
* By default, sentry is enabled only on the server.
* In Apify, whis is when `process.env.APIFY_IS_AT_HOME` is true.
*/
const setupSentry = async (sentryOptions?: Sentry.NodeOptions) => {
// As default, enable sentry only on Apify server
const enabled = sentryOptions?.enabled != null && sentryOptions.enabled;
if (!enabled) return;
// We use this field for identification in UI, so it's required.
if (!sentryOptions?.serverName) throw Error('Sentry setup is missing "serverName" property.'); // prettier-ignore
Sentry.init(sentryOptions);
};
export const createSentryTelemetry = <T extends CrawleeOneTelemetry<CrawleeOneCtx>>(
sentryOptions?: Sentry.NodeOptions
) => {
return {
setup: async (actor) => {
await setupSentry(sentryOptions);
},
onSendErrorToTelemetry: (error, report, options, ctx) => {
Sentry.captureException(error, { extra: report as any });
},
} as T;
};