@sentry/cloudflare 11.6.0 → 11.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/dev/index.js +2 -0
- package/build/cjs/dev/index.js.map +1 -1
- package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js +21 -1
- package/build/cjs/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
- package/build/cjs/dev/integrations/cronTriggers.js +97 -0
- package/build/cjs/dev/integrations/cronTriggers.js.map +1 -0
- package/build/cjs/prod/index.js +2 -0
- package/build/cjs/prod/index.js.map +1 -1
- package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js +21 -1
- package/build/cjs/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
- package/build/cjs/prod/integrations/cronTriggers.js +97 -0
- package/build/cjs/prod/integrations/cronTriggers.js.map +1 -0
- package/build/esm/dev/index.js +1 -0
- package/build/esm/dev/index.js.map +1 -1
- package/build/esm/dev/instrumentations/worker/instrumentScheduled.js +22 -2
- package/build/esm/dev/instrumentations/worker/instrumentScheduled.js.map +1 -1
- package/build/esm/dev/integrations/cronTriggers.js +95 -0
- package/build/esm/dev/integrations/cronTriggers.js.map +1 -0
- package/build/esm/dev/package.json +1 -1
- package/build/esm/prod/index.js +1 -0
- package/build/esm/prod/index.js.map +1 -1
- package/build/esm/prod/instrumentations/worker/instrumentScheduled.js +22 -2
- package/build/esm/prod/instrumentations/worker/instrumentScheduled.js.map +1 -1
- package/build/esm/prod/integrations/cronTriggers.js +95 -0
- package/build/esm/prod/integrations/cronTriggers.js.map +1 -0
- package/build/esm/prod/package.json +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/instrumentations/worker/instrumentScheduled.d.ts.map +1 -1
- package/build/types/integrations/cronTriggers.d.ts +62 -0
- package/build/types/integrations/cronTriggers.d.ts.map +1 -0
- package/package.json +5 -5
package/build/cjs/dev/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const sdk = require('./sdk.js');
|
|
|
13
13
|
const httpServer = require('./integrations/httpServer.js');
|
|
14
14
|
const fetch = require('./integrations/fetch.js');
|
|
15
15
|
const spotlight = require('./integrations/spotlight.js');
|
|
16
|
+
const cronTriggers = require('./integrations/cronTriggers.js');
|
|
16
17
|
const workflows = require('./workflows.js');
|
|
17
18
|
const noDiagnosticChannels = require('@sentry/server-utils/no-diagnostic-channels');
|
|
18
19
|
|
|
@@ -132,6 +133,7 @@ exports.getDefaultIntegrations = sdk.getDefaultIntegrations;
|
|
|
132
133
|
exports.httpServerIntegration = httpServer.httpServerIntegration;
|
|
133
134
|
exports.fetchIntegration = fetch.fetchIntegration;
|
|
134
135
|
exports.spotlightIntegration = spotlight.spotlightIntegration;
|
|
136
|
+
exports.cronTriggersIntegration = cronTriggers.cronTriggersIntegration;
|
|
135
137
|
exports.instrumentWorkflowWithSentry = workflows.instrumentWorkflowWithSentry;
|
|
136
138
|
exports.setAsyncLocalStorageAsyncContextStrategy = noDiagnosticChannels.setAsyncLocalStorageAsyncContextStrategy;
|
|
137
139
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const attributes = require('@sentry/conventions/attributes');
|
|
4
4
|
const op = require('@sentry/conventions/op');
|
|
5
5
|
const core = require('@sentry/core');
|
|
6
|
+
const debugBuild = require('../../debug-build.js');
|
|
6
7
|
const flush = require('../../flush.js');
|
|
7
8
|
const instrument = require('../../instrument.js');
|
|
8
9
|
const options = require('../../options.js');
|
|
@@ -37,9 +38,28 @@ function wrapScheduledHandler(controller, options, context, fn) {
|
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
async () => {
|
|
41
|
+
let finishCheckIn;
|
|
40
42
|
try {
|
|
41
|
-
|
|
43
|
+
finishCheckIn = client?.getIntegrationByName("CronTriggers")?.startCheckIn(controller.cron);
|
|
44
|
+
if (finishCheckIn) {
|
|
45
|
+
waitUntil(Promise.resolve(client?.getTransport()?.flush(2e3)).catch(() => void 0));
|
|
46
|
+
}
|
|
42
47
|
} catch (e) {
|
|
48
|
+
debugBuild.DEBUG_BUILD && core.debug.warn("Failed to send the in_progress cron check-in", e);
|
|
49
|
+
}
|
|
50
|
+
const finish = (status) => {
|
|
51
|
+
try {
|
|
52
|
+
finishCheckIn?.(status);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
debugBuild.DEBUG_BUILD && core.debug.warn(`Failed to send the ${status} cron check-in`, e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
const result = await fn();
|
|
59
|
+
finish("ok");
|
|
60
|
+
return result;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
finish("error");
|
|
43
63
|
core.captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.scheduled" } });
|
|
44
64
|
throw e;
|
|
45
65
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n
|
|
1
|
+
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, debug, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport type { CronTriggersIntegration } from '../../integrations/cronTriggers';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n let finishCheckIn: ReturnType<CronTriggersIntegration['startCheckIn']>;\n try {\n finishCheckIn = client\n ?.getIntegrationByName<CronTriggersIntegration>('CronTriggers')\n ?.startCheckIn(controller.cron);\n // The transport holds envelopes until the flush after the handler, so a run that is longer than\n // the check-in margin would deliver its in_progress check-in too late and show as missed.\n if (finishCheckIn) {\n waitUntil(Promise.resolve(client?.getTransport()?.flush(2000)).catch(() => undefined));\n }\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to send the in_progress cron check-in', e);\n }\n\n const finish = (status: 'ok' | 'error'): void => {\n try {\n finishCheckIn?.(status);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`Failed to send the ${status} cron check-in`, e);\n }\n };\n\n try {\n const result = await fn();\n finish('ok');\n return result;\n } catch (e) {\n finish('error');\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments a scheduled handler for ExportedHandler (env/ctx come from args).\n */\nexport function instrumentExportedHandlerScheduled<T extends AnyExportedHandler>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('scheduled' in handler) || typeof handler.scheduled !== 'function') {\n return;\n }\n\n handler.scheduled = ensureInstrumented(\n handler.scheduled,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['scheduled']>>) {\n const [controller, env, ctx] = args;\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n args[1] = instrumentEnv(env, options);\n args[2] = context;\n\n return wrapScheduledHandler(controller, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n\n/**\n * Instruments a scheduled method for WorkerEntrypoint (options/context already available).\n */\nexport function instrumentWorkerEntrypointScheduled<T extends WorkerEntrypoint>(\n instance: T,\n options: CloudflareOptions,\n context: ExecutionContext,\n): void {\n if (!instance.scheduled) {\n return;\n }\n\n const original = instance.scheduled.bind(instance);\n instance.scheduled = new Proxy(original, {\n apply(target, thisArg, args: [ScheduledController]) {\n const [controller] = args;\n\n return wrapScheduledHandler(controller, options, context, () => Reflect.apply(target, thisArg, args));\n },\n });\n}\n"],"names":["withIsolationScope","setInvocationState","init","addCloudResourceContext","startSpan","hasSpanStreamingEnabled","SENTRY_OP","FUNCTION","SENTRY_DESCRIPTION","CODE_FUNCTION_NAME","FAAS_CRON","FAAS_TIME","FAAS_TRIGGER","SENTRY_ORIGIN","SENTRY_SEGMENT_NAME_SOURCE","DEBUG_BUILD","debug","captureException","flushAndDispose","ensureInstrumented","instrumentContext","options","getFinalOptions","instrumentEnv"],"mappings":";;;;;;;;;;;;;;;AA2BA,SAAS,oBAAA,CACP,UAAA,EACA,OAAA,EACA,OAAA,EACA,EAAA,EACS;AACT,EAAA,OAAOA,wBAAmB,CAAA,cAAA,KAAkB;AAC1C,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAEhD,IAAAC,oCAAA,CAAmB,cAAA,EAAgB,EAAE,GAAA,EAAK,OAAA,EAAS,CAAA;AAEnD,IAAA,MAAM,SAASC,QAAA,CAAK,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AAChD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,IAAAC,kCAAA,CAAwB,cAAc,CAAA;AAEtC,IAAA,MAAM,WAAA,GAAc,CAAA,eAAA,EAAkB,UAAA,CAAW,IAAI,CAAA,CAAA;AAErD,IAAA,OAAOC,cAAA;AAAA,MACL;AAAA,QACE,IAAA,EAAM,MAAA,IAAUC,4BAAA,CAAwB,MAAM,IAAI,WAAA,GAAc,WAAA;AAAA,QAChE,UAAA,EAAY;AAAA,UACV,CAACC,oBAAS,GAAGC,WAAA;AAAA;AAAA;AAAA,UAGb,CAACC,6BAAkB,GAAG,WAAA;AAAA,UACtB,CAACC,6BAAkB,GAAG,WAAA;AAAA,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AA,CAAS,SAAA,CAAU,IAAA,CAAK,QAAQ,CAAA;AACjD,EAAA,QAAA,CAAS,SAAA,GAAY,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,IACvC,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAA,EAA6B;AAClD,MAAA,MAAM,CAAC,UAAU,CAAA,GAAI,IAAA;AAErB,MAAA,OAAO,oBAAA,CAAqB,UAAA,EAAY,OAAA,EAAS,OAAA,EAAS,MAAM,QAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAC,CAAA;AAAA,IACtG;AAAA,GACD,CAAA;AACH;;;;;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const debugBuild = require('../debug-build.js');
|
|
5
|
+
|
|
6
|
+
const INTEGRATION_NAME = "CronTriggers";
|
|
7
|
+
const SLUG_TOKENS = { " ": "-", "*": "x", ",": "_", "-": "to", "/": "by" };
|
|
8
|
+
function cronToMonitorSlug(cron) {
|
|
9
|
+
const expression = cron.trim().toLowerCase().split(/\s+/).join(" ");
|
|
10
|
+
const slug = `cron-${expression.replace(/[ *,\-/]/g, (char) => SLUG_TOKENS[char])}`;
|
|
11
|
+
if (/^[a-z0-9_-]{1,50}$/.test(slug)) {
|
|
12
|
+
return slug;
|
|
13
|
+
}
|
|
14
|
+
let hash = 0;
|
|
15
|
+
for (let i = 0; i < expression.length; i++) {
|
|
16
|
+
hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;
|
|
17
|
+
}
|
|
18
|
+
return `${slug.replace(/[^a-z0-9_-]+/g, "-").slice(0, 43)}-${hash.toString(36)}`;
|
|
19
|
+
}
|
|
20
|
+
const WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
21
|
+
function weekdayIndex(value) {
|
|
22
|
+
return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());
|
|
23
|
+
}
|
|
24
|
+
function convertWeekdayItem(item) {
|
|
25
|
+
const match = item.match(/^(\*|\w+)(?:-(\w+))?(?:\/(\d+))?$/);
|
|
26
|
+
if (!match) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
const [, from, to, step] = match;
|
|
30
|
+
if (step && !(Number(step) > 0)) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
if (from === "*") {
|
|
34
|
+
return to ? void 0 : item;
|
|
35
|
+
}
|
|
36
|
+
const start = weekdayIndex(from);
|
|
37
|
+
const end = to ? weekdayIndex(to) : step ? 6 : start;
|
|
38
|
+
if (start < 0 || end < start) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
if (start === end) {
|
|
42
|
+
return WEEKDAYS[start];
|
|
43
|
+
}
|
|
44
|
+
const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;
|
|
45
|
+
return step ? `${days}/${step}` : days;
|
|
46
|
+
}
|
|
47
|
+
function cloudflareCronToCrontab(cron) {
|
|
48
|
+
const fields = cron.trim().split(/\s+/);
|
|
49
|
+
const [, , dayOfMonth = "", , dayOfWeek = ""] = fields;
|
|
50
|
+
if (fields.length !== 5 || /[w?]|l-/i.test(dayOfMonth) || dayOfMonth !== "*" && dayOfWeek !== "*" && (dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*"))) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const weekdays = dayOfWeek.split(",").map(convertWeekdayItem);
|
|
54
|
+
return weekdays.includes(void 0) ? void 0 : [...fields.slice(0, 4), weekdays.join(",")].join(" ");
|
|
55
|
+
}
|
|
56
|
+
const _cronTriggersIntegration = ((options = {}) => {
|
|
57
|
+
return {
|
|
58
|
+
name: INTEGRATION_NAME,
|
|
59
|
+
startCheckIn(cron) {
|
|
60
|
+
if (!cron) {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
let monitor;
|
|
64
|
+
try {
|
|
65
|
+
monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
debugBuild.DEBUG_BUILD && core.debug.warn(`[Cron Triggers] \`monitorSlug\` threw for "${cron}", sending no check-ins:`, e);
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
if (!monitor) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const { monitorSlug, ...monitorSettings } = typeof monitor === "string" ? { monitorSlug: monitor } : monitor;
|
|
74
|
+
if (!monitorSlug) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
const crontab = cloudflareCronToCrontab(cron);
|
|
78
|
+
if (!crontab) {
|
|
79
|
+
debugBuild.DEBUG_BUILD && core.debug.warn(
|
|
80
|
+
`[Cron Triggers] Can't convert "${cron}" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const checkInId = core.captureCheckIn(
|
|
84
|
+
{ monitorSlug, status: "in_progress" },
|
|
85
|
+
crontab ? { ...monitorSettings, schedule: { type: "crontab", value: crontab } } : void 0
|
|
86
|
+
);
|
|
87
|
+
const startTime = core.timestampInSeconds();
|
|
88
|
+
return (status) => {
|
|
89
|
+
core.captureCheckIn({ monitorSlug, status, checkInId, duration: core.timestampInSeconds() - startTime });
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
const cronTriggersIntegration = core.defineIntegration(_cronTriggersIntegration);
|
|
95
|
+
|
|
96
|
+
exports.cronTriggersIntegration = cronTriggersIntegration;
|
|
97
|
+
//# sourceMappingURL=cronTriggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronTriggers.js","sources":["../../../../src/integrations/cronTriggers.ts"],"sourcesContent":["import type { IntegrationFn, MonitorConfig } from '@sentry/core';\nimport { captureCheckIn, debug, defineIntegration, timestampInSeconds } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\nconst INTEGRATION_NAME = 'CronTriggers' as const;\n\n/**\n * The monitor slug and settings for a Cron Trigger, see `cronTriggersIntegration`.\n */\nexport type CronTriggerMonitorSettings = { monitorSlug: string } & Omit<MonitorConfig, 'schedule' | 'timezone'>;\n\nexport interface CronTriggersOptions {\n /**\n * Chooses the monitor slug for a cron expression. It can also return an object with the `monitorSlug`\n * and other monitor settings, such as `checkinMargin` or `maxRuntime`. Returning `undefined`\n * sends no check-ins for that trigger, and so does a function that throws.\n */\n monitorSlug?: (cron: string) => string | CronTriggerMonitorSettings | undefined;\n}\n\n/** @internal Used by the scheduled handler instrumentation. */\nexport interface CronTriggersIntegration {\n name: string;\n startCheckIn(cron: string): ((status: 'ok' | 'error') => void) | undefined;\n}\n\nconst SLUG_TOKENS: Record<string, string> = { ' ': '-', '*': 'x', ',': '_', '-': 'to', '/': 'by' };\n\n/**\n * Derives a monitor slug from a cron expression, e.g. `30 9 * * MON-FRI` -> `cron-30-9-x-x-montofri`.\n *\n * A hash of the expression is appended when it has any other characters or the slug would be\n * longer than 50 characters, so different expressions don't share a slug.\n */\nfunction cronToMonitorSlug(cron: string): string {\n const expression = cron.trim().toLowerCase().split(/\\s+/).join(' ');\n const slug = `cron-${expression.replace(/[ *,\\-/]/g, char => SLUG_TOKENS[char] as string)}`;\n if (/^[a-z0-9_-]{1,50}$/.test(slug)) {\n return slug;\n }\n\n // A polynomial string hash modulo 2^31 - 1, at most 6 characters in base 36.\n let hash = 0;\n for (let i = 0; i < expression.length; i++) {\n hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;\n }\n return `${slug.replace(/[^a-z0-9_-]+/g, '-').slice(0, 43)}-${hash.toString(36)}`;\n}\n\nconst WEEKDAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];\n\n// Cloudflare numbers weekdays from 1 = Sunday to 7 = Saturday. Returns -1 for anything else.\nfunction weekdayIndex(value: string): number {\n return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());\n}\n\nfunction convertWeekdayItem(item: string): string | undefined {\n const match = item.match(/^(\\*|\\w+)(?:-(\\w+))?(?:\\/(\\d+))?$/);\n if (!match) {\n return undefined;\n }\n const [, from, to, step] = match;\n if (step && !(Number(step) > 0)) {\n return undefined;\n }\n\n // `*` and `*/n` give the same days in both numberings, and keep their `*` meaning for Sentry.\n if (from === '*') {\n return to ? undefined : item;\n }\n\n const start = weekdayIndex(from as string);\n // A step without an end runs to Saturday, so it is written as a range.\n const end = to ? weekdayIndex(to) : step ? 6 : start;\n if (start < 0 || end < start) {\n return undefined;\n }\n\n // A step over a single day would run on to Sunday in Sentry's cron parser, so it is left out.\n if (start === end) {\n return WEEKDAYS[start];\n }\n const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;\n return step ? `${days}/${step}` : days;\n}\n\n/**\n * Converts a Cloudflare cron expression into a crontab Sentry accepts, which numbers weekdays from\n * 0 = Sunday. Returns `undefined` if the day fields can't be converted.\n */\nfunction cloudflareCronToCrontab(cron: string): string | undefined {\n const fields = cron.trim().split(/\\s+/);\n const [, , dayOfMonth = '', , dayOfWeek = ''] = fields;\n // Sentry rejects `W`, `?` and `L-n` in the day of month. When both day fields are set, Cloudflare and Sentry\n // run on the days that match either field, but Sentry requires both to match when one starts with `*`.\n if (\n fields.length !== 5 ||\n /[w?]|l-/i.test(dayOfMonth) ||\n (dayOfMonth !== '*' && dayOfWeek !== '*' && (dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*')))\n ) {\n return undefined;\n }\n\n const weekdays = dayOfWeek.split(',').map(convertWeekdayItem);\n return weekdays.includes(undefined) ? undefined : [...fields.slice(0, 4), weekdays.join(',')].join(' ');\n}\n\nconst _cronTriggersIntegration = ((options: CronTriggersOptions = {}): CronTriggersIntegration => {\n return {\n name: INTEGRATION_NAME,\n startCheckIn(cron) {\n // Manual runs, e.g. through `wrangler dev --test-scheduled`, can have no cron expression.\n if (!cron) {\n return undefined;\n }\n\n let monitor: string | CronTriggerMonitorSettings | undefined;\n try {\n monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`[Cron Triggers] \\`monitorSlug\\` threw for \"${cron}\", sending no check-ins:`, e);\n return undefined;\n }\n\n if (!monitor) {\n return undefined;\n }\n\n const { monitorSlug, ...monitorSettings } = typeof monitor === 'string' ? { monitorSlug: monitor } : monitor;\n if (!monitorSlug) {\n return undefined;\n }\n\n const crontab = cloudflareCronToCrontab(cron);\n if (!crontab) {\n DEBUG_BUILD &&\n debug.warn(\n `[Cron Triggers] Can't convert \"${cron}\" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`,\n );\n }\n\n // Check-ins are captured directly rather than through `withMonitor`, which would fork the\n // isolation scope and lose the invocation state attached to it.\n const checkInId = captureCheckIn(\n { monitorSlug, status: 'in_progress' },\n crontab ? { ...monitorSettings, schedule: { type: 'crontab', value: crontab } } : undefined,\n );\n const startTime = timestampInSeconds();\n\n return status => {\n captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - startTime });\n };\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Sends cron check-ins for every Cron Trigger run of the `scheduled` handler, with the trigger's\n * schedule, so Sentry creates the monitor on the first run.\n *\n * Cron Triggers have no names, so map each cron expression to a slug. Without `monitorSlug`, the slug is\n * derived from the expression (`30 9 * * MON-FRI` becomes `cron-30-9-x-x-montofri`) and changes with it.\n * Workers that send to the same project get the same slug for the same expression, so they share a monitor.\n *\n * @example\n * ```ts\n * // src/monitorSlugs.ts\n * export const monitorSlugs: Record<string, string> = {\n * '30 9 * * MON-FRI': 'daily-report',\n * };\n *\n * // src/instrument.server.ts\n * import { cronTriggersIntegration, defineCloudflareOptions } from '@sentry/cloudflare';\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default defineCloudflareOptions((env) => ({\n * dsn: env.SENTRY_DSN,\n * integrations: [cronTriggersIntegration({ monitorSlug: (cron) => monitorSlugs[cron] })],\n * }));\n *\n * // src/index.ts\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default {\n * async scheduled(controller, env) {\n * switch (monitorSlugs[controller.cron]) {\n * case 'daily-report':\n * // ...\n * break;\n * }\n * },\n * };\n * ```\n */\nexport const cronTriggersIntegration = defineIntegration(_cronTriggersIntegration);\n"],"names":["DEBUG_BUILD","debug","captureCheckIn","timestampInSeconds","defineIntegration"],"mappings":";;;;;AAIA,MAAM,gBAAA,GAAmB,cAAA;AAsBzB,MAAM,WAAA,GAAsC,EAAE,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,IAAA,EAAM,GAAA,EAAK,IAAA,EAAK;AAQjG,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,IAAA,EAAK,CAAE,WAAA,GAAc,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAClE,EAAA,MAAM,IAAA,GAAO,QAAQ,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA,IAAA,KAAQ,WAAA,CAAY,IAAI,CAAW,CAAC,CAAA,CAAA;AACzF,EAAA,IAAI,oBAAA,CAAqB,IAAA,CAAK,IAAI,CAAA,EAAG;AACnC,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAA,EAAA,EAAK;AAC1C,IAAA,IAAA,GAAA,CAAQ,IAAA,GAAO,EAAA,GAAK,UAAA,CAAW,UAAA,CAAW,CAAC,CAAA,IAAK,UAAA;AAAA,EAClD;AACA,EAAA,OAAO,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/build/cjs/prod/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const sdk = require('./sdk.js');
|
|
|
13
13
|
const httpServer = require('./integrations/httpServer.js');
|
|
14
14
|
const fetch = require('./integrations/fetch.js');
|
|
15
15
|
const spotlight = require('./integrations/spotlight.js');
|
|
16
|
+
const cronTriggers = require('./integrations/cronTriggers.js');
|
|
16
17
|
const workflows = require('./workflows.js');
|
|
17
18
|
const noDiagnosticChannels = require('@sentry/server-utils/no-diagnostic-channels');
|
|
18
19
|
|
|
@@ -132,6 +133,7 @@ exports.getDefaultIntegrations = sdk.getDefaultIntegrations;
|
|
|
132
133
|
exports.httpServerIntegration = httpServer.httpServerIntegration;
|
|
133
134
|
exports.fetchIntegration = fetch.fetchIntegration;
|
|
134
135
|
exports.spotlightIntegration = spotlight.spotlightIntegration;
|
|
136
|
+
exports.cronTriggersIntegration = cronTriggers.cronTriggersIntegration;
|
|
135
137
|
exports.instrumentWorkflowWithSentry = workflows.instrumentWorkflowWithSentry;
|
|
136
138
|
exports.setAsyncLocalStorageAsyncContextStrategy = noDiagnosticChannels.setAsyncLocalStorageAsyncContextStrategy;
|
|
137
139
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const attributes = require('@sentry/conventions/attributes');
|
|
4
4
|
const op = require('@sentry/conventions/op');
|
|
5
5
|
const core = require('@sentry/core');
|
|
6
|
+
const debugBuild = require('../../debug-build.js');
|
|
6
7
|
const flush = require('../../flush.js');
|
|
7
8
|
const instrument = require('../../instrument.js');
|
|
8
9
|
const options = require('../../options.js');
|
|
@@ -37,9 +38,28 @@ function wrapScheduledHandler(controller, options, context, fn) {
|
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
async () => {
|
|
41
|
+
let finishCheckIn;
|
|
40
42
|
try {
|
|
41
|
-
|
|
43
|
+
finishCheckIn = client?.getIntegrationByName("CronTriggers")?.startCheckIn(controller.cron);
|
|
44
|
+
if (finishCheckIn) {
|
|
45
|
+
waitUntil(Promise.resolve(client?.getTransport()?.flush(2e3)).catch(() => void 0));
|
|
46
|
+
}
|
|
42
47
|
} catch (e) {
|
|
48
|
+
debugBuild.DEBUG_BUILD && core.debug.warn("Failed to send the in_progress cron check-in", e);
|
|
49
|
+
}
|
|
50
|
+
const finish = (status) => {
|
|
51
|
+
try {
|
|
52
|
+
finishCheckIn?.(status);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
debugBuild.DEBUG_BUILD && core.debug.warn(`Failed to send the ${status} cron check-in`, e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
const result = await fn();
|
|
59
|
+
finish("ok");
|
|
60
|
+
return result;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
finish("error");
|
|
43
63
|
core.captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.scheduled" } });
|
|
44
64
|
throw e;
|
|
45
65
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n
|
|
1
|
+
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, debug, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport type { CronTriggersIntegration } from '../../integrations/cronTriggers';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n let finishCheckIn: ReturnType<CronTriggersIntegration['startCheckIn']>;\n try {\n finishCheckIn = client\n ?.getIntegrationByName<CronTriggersIntegration>('CronTriggers')\n ?.startCheckIn(controller.cron);\n // The transport holds envelopes until the flush after the handler, so a run that is longer than\n // the check-in margin would deliver its in_progress check-in too late and show as missed.\n if (finishCheckIn) {\n waitUntil(Promise.resolve(client?.getTransport()?.flush(2000)).catch(() => undefined));\n }\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to send the in_progress cron check-in', e);\n }\n\n const finish = (status: 'ok' | 'error'): void => {\n try {\n finishCheckIn?.(status);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`Failed to send the ${status} cron check-in`, e);\n }\n };\n\n try {\n const result = await fn();\n finish('ok');\n return result;\n } catch (e) {\n finish('error');\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments a scheduled handler for ExportedHandler (env/ctx come from args).\n */\nexport function instrumentExportedHandlerScheduled<T extends AnyExportedHandler>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('scheduled' in handler) || typeof handler.scheduled !== 'function') {\n return;\n }\n\n handler.scheduled = ensureInstrumented(\n handler.scheduled,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['scheduled']>>) {\n const [controller, env, ctx] = args;\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n args[1] = instrumentEnv(env, options);\n args[2] = context;\n\n return wrapScheduledHandler(controller, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n\n/**\n * Instruments a scheduled method for WorkerEntrypoint (options/context already available).\n */\nexport function instrumentWorkerEntrypointScheduled<T extends WorkerEntrypoint>(\n instance: T,\n options: CloudflareOptions,\n context: ExecutionContext,\n): void {\n if (!instance.scheduled) {\n return;\n }\n\n const original = instance.scheduled.bind(instance);\n instance.scheduled = new Proxy(original, {\n apply(target, thisArg, args: [ScheduledController]) {\n const [controller] = args;\n\n return wrapScheduledHandler(controller, options, context, () => Reflect.apply(target, thisArg, args));\n },\n });\n}\n"],"names":["withIsolationScope","setInvocationState","init","addCloudResourceContext","startSpan","hasSpanStreamingEnabled","SENTRY_OP","FUNCTION","SENTRY_DESCRIPTION","CODE_FUNCTION_NAME","FAAS_CRON","FAAS_TIME","FAAS_TRIGGER","SENTRY_ORIGIN","SENTRY_SEGMENT_NAME_SOURCE","DEBUG_BUILD","debug","captureException","flushAndDispose","ensureInstrumented","instrumentContext","options","getFinalOptions","instrumentEnv"],"mappings":";;;;;;;;;;;;;;;AA2BA,SAAS,oBAAA,CACP,UAAA,EACA,OAAA,EACA,OAAA,EACA,EAAA,EACS;AACT,EAAA,OAAOA,wBAAmB,CAAA,cAAA,KAAkB;AAC1C,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAEhD,IAAAC,oCAAA,CAAmB,cAAA,EAAgB,EAAE,GAAA,EAAK,OAAA,EAAS,CAAA;AAEnD,IAAA,MAAM,SAASC,QAAA,CAAK,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AAChD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,IAAAC,kCAAA,CAAwB,cAAc,CAAA;AAEtC,IAAA,MAAM,WAAA,GAAc,CAAA,eAAA,EAAkB,UAAA,CAAW,IAAI,CAAA,CAAA;AAErD,IAAA,OAAOC,cAAA;AAAA,MACL;AAAA,QACE,IAAA,EAAM,MAAA,IAAUC,4BAAA,CAAwB,MAAM,IAAI,WAAA,GAAc,WAAA;AAAA,QAChE,UAAA,EAAY;AAAA,UACV,CAACC,oBAAS,GAAGC,WAAA;AAAA;AAAA;AAAA,UAGb,CAACC,6BAAkB,GAAG,WAAA;AAAA,UACtB,C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AEA,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,SAAA,CAAU,IAAA,CAAK,QAAQ,CAAA;AACjD,EAAA,QAAA,CAAS,SAAA,GAAY,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,IACvC,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAA,EAA6B;AAClD,MAAA,MAAM,CAAC,UAAU,CAAA,GAAI,IAAA;AAErB,MAAA,OAAO,oBAAA,CAAqB,UAAA,EAAY,OAAA,EAAS,OAAA,EAAS,MAAM,QAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAC,CAAA;AAAA,IACtG;AAAA,GACD,CAAA;AACH;;;;;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const core = require('@sentry/core');
|
|
4
|
+
const debugBuild = require('../debug-build.js');
|
|
5
|
+
|
|
6
|
+
const INTEGRATION_NAME = "CronTriggers";
|
|
7
|
+
const SLUG_TOKENS = { " ": "-", "*": "x", ",": "_", "-": "to", "/": "by" };
|
|
8
|
+
function cronToMonitorSlug(cron) {
|
|
9
|
+
const expression = cron.trim().toLowerCase().split(/\s+/).join(" ");
|
|
10
|
+
const slug = `cron-${expression.replace(/[ *,\-/]/g, (char) => SLUG_TOKENS[char])}`;
|
|
11
|
+
if (/^[a-z0-9_-]{1,50}$/.test(slug)) {
|
|
12
|
+
return slug;
|
|
13
|
+
}
|
|
14
|
+
let hash = 0;
|
|
15
|
+
for (let i = 0; i < expression.length; i++) {
|
|
16
|
+
hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;
|
|
17
|
+
}
|
|
18
|
+
return `${slug.replace(/[^a-z0-9_-]+/g, "-").slice(0, 43)}-${hash.toString(36)}`;
|
|
19
|
+
}
|
|
20
|
+
const WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
21
|
+
function weekdayIndex(value) {
|
|
22
|
+
return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());
|
|
23
|
+
}
|
|
24
|
+
function convertWeekdayItem(item) {
|
|
25
|
+
const match = item.match(/^(\*|\w+)(?:-(\w+))?(?:\/(\d+))?$/);
|
|
26
|
+
if (!match) {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
const [, from, to, step] = match;
|
|
30
|
+
if (step && !(Number(step) > 0)) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
if (from === "*") {
|
|
34
|
+
return to ? void 0 : item;
|
|
35
|
+
}
|
|
36
|
+
const start = weekdayIndex(from);
|
|
37
|
+
const end = to ? weekdayIndex(to) : step ? 6 : start;
|
|
38
|
+
if (start < 0 || end < start) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
if (start === end) {
|
|
42
|
+
return WEEKDAYS[start];
|
|
43
|
+
}
|
|
44
|
+
const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;
|
|
45
|
+
return step ? `${days}/${step}` : days;
|
|
46
|
+
}
|
|
47
|
+
function cloudflareCronToCrontab(cron) {
|
|
48
|
+
const fields = cron.trim().split(/\s+/);
|
|
49
|
+
const [, , dayOfMonth = "", , dayOfWeek = ""] = fields;
|
|
50
|
+
if (fields.length !== 5 || /[w?]|l-/i.test(dayOfMonth) || dayOfMonth !== "*" && dayOfWeek !== "*" && (dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*"))) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
const weekdays = dayOfWeek.split(",").map(convertWeekdayItem);
|
|
54
|
+
return weekdays.includes(void 0) ? void 0 : [...fields.slice(0, 4), weekdays.join(",")].join(" ");
|
|
55
|
+
}
|
|
56
|
+
const _cronTriggersIntegration = ((options = {}) => {
|
|
57
|
+
return {
|
|
58
|
+
name: INTEGRATION_NAME,
|
|
59
|
+
startCheckIn(cron) {
|
|
60
|
+
if (!cron) {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
let monitor;
|
|
64
|
+
try {
|
|
65
|
+
monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
debugBuild.DEBUG_BUILD && core.debug.warn(`[Cron Triggers] \`monitorSlug\` threw for "${cron}", sending no check-ins:`, e);
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
if (!monitor) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const { monitorSlug, ...monitorSettings } = typeof monitor === "string" ? { monitorSlug: monitor } : monitor;
|
|
74
|
+
if (!monitorSlug) {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
const crontab = cloudflareCronToCrontab(cron);
|
|
78
|
+
if (!crontab) {
|
|
79
|
+
debugBuild.DEBUG_BUILD && core.debug.warn(
|
|
80
|
+
`[Cron Triggers] Can't convert "${cron}" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const checkInId = core.captureCheckIn(
|
|
84
|
+
{ monitorSlug, status: "in_progress" },
|
|
85
|
+
crontab ? { ...monitorSettings, schedule: { type: "crontab", value: crontab } } : void 0
|
|
86
|
+
);
|
|
87
|
+
const startTime = core.timestampInSeconds();
|
|
88
|
+
return (status) => {
|
|
89
|
+
core.captureCheckIn({ monitorSlug, status, checkInId, duration: core.timestampInSeconds() - startTime });
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
const cronTriggersIntegration = core.defineIntegration(_cronTriggersIntegration);
|
|
95
|
+
|
|
96
|
+
exports.cronTriggersIntegration = cronTriggersIntegration;
|
|
97
|
+
//# sourceMappingURL=cronTriggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronTriggers.js","sources":["../../../../src/integrations/cronTriggers.ts"],"sourcesContent":["import type { IntegrationFn, MonitorConfig } from '@sentry/core';\nimport { captureCheckIn, debug, defineIntegration, timestampInSeconds } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\nconst INTEGRATION_NAME = 'CronTriggers' as const;\n\n/**\n * The monitor slug and settings for a Cron Trigger, see `cronTriggersIntegration`.\n */\nexport type CronTriggerMonitorSettings = { monitorSlug: string } & Omit<MonitorConfig, 'schedule' | 'timezone'>;\n\nexport interface CronTriggersOptions {\n /**\n * Chooses the monitor slug for a cron expression. It can also return an object with the `monitorSlug`\n * and other monitor settings, such as `checkinMargin` or `maxRuntime`. Returning `undefined`\n * sends no check-ins for that trigger, and so does a function that throws.\n */\n monitorSlug?: (cron: string) => string | CronTriggerMonitorSettings | undefined;\n}\n\n/** @internal Used by the scheduled handler instrumentation. */\nexport interface CronTriggersIntegration {\n name: string;\n startCheckIn(cron: string): ((status: 'ok' | 'error') => void) | undefined;\n}\n\nconst SLUG_TOKENS: Record<string, string> = { ' ': '-', '*': 'x', ',': '_', '-': 'to', '/': 'by' };\n\n/**\n * Derives a monitor slug from a cron expression, e.g. `30 9 * * MON-FRI` -> `cron-30-9-x-x-montofri`.\n *\n * A hash of the expression is appended when it has any other characters or the slug would be\n * longer than 50 characters, so different expressions don't share a slug.\n */\nfunction cronToMonitorSlug(cron: string): string {\n const expression = cron.trim().toLowerCase().split(/\\s+/).join(' ');\n const slug = `cron-${expression.replace(/[ *,\\-/]/g, char => SLUG_TOKENS[char] as string)}`;\n if (/^[a-z0-9_-]{1,50}$/.test(slug)) {\n return slug;\n }\n\n // A polynomial string hash modulo 2^31 - 1, at most 6 characters in base 36.\n let hash = 0;\n for (let i = 0; i < expression.length; i++) {\n hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;\n }\n return `${slug.replace(/[^a-z0-9_-]+/g, '-').slice(0, 43)}-${hash.toString(36)}`;\n}\n\nconst WEEKDAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];\n\n// Cloudflare numbers weekdays from 1 = Sunday to 7 = Saturday. Returns -1 for anything else.\nfunction weekdayIndex(value: string): number {\n return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());\n}\n\nfunction convertWeekdayItem(item: string): string | undefined {\n const match = item.match(/^(\\*|\\w+)(?:-(\\w+))?(?:\\/(\\d+))?$/);\n if (!match) {\n return undefined;\n }\n const [, from, to, step] = match;\n if (step && !(Number(step) > 0)) {\n return undefined;\n }\n\n // `*` and `*/n` give the same days in both numberings, and keep their `*` meaning for Sentry.\n if (from === '*') {\n return to ? undefined : item;\n }\n\n const start = weekdayIndex(from as string);\n // A step without an end runs to Saturday, so it is written as a range.\n const end = to ? weekdayIndex(to) : step ? 6 : start;\n if (start < 0 || end < start) {\n return undefined;\n }\n\n // A step over a single day would run on to Sunday in Sentry's cron parser, so it is left out.\n if (start === end) {\n return WEEKDAYS[start];\n }\n const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;\n return step ? `${days}/${step}` : days;\n}\n\n/**\n * Converts a Cloudflare cron expression into a crontab Sentry accepts, which numbers weekdays from\n * 0 = Sunday. Returns `undefined` if the day fields can't be converted.\n */\nfunction cloudflareCronToCrontab(cron: string): string | undefined {\n const fields = cron.trim().split(/\\s+/);\n const [, , dayOfMonth = '', , dayOfWeek = ''] = fields;\n // Sentry rejects `W`, `?` and `L-n` in the day of month. When both day fields are set, Cloudflare and Sentry\n // run on the days that match either field, but Sentry requires both to match when one starts with `*`.\n if (\n fields.length !== 5 ||\n /[w?]|l-/i.test(dayOfMonth) ||\n (dayOfMonth !== '*' && dayOfWeek !== '*' && (dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*')))\n ) {\n return undefined;\n }\n\n const weekdays = dayOfWeek.split(',').map(convertWeekdayItem);\n return weekdays.includes(undefined) ? undefined : [...fields.slice(0, 4), weekdays.join(',')].join(' ');\n}\n\nconst _cronTriggersIntegration = ((options: CronTriggersOptions = {}): CronTriggersIntegration => {\n return {\n name: INTEGRATION_NAME,\n startCheckIn(cron) {\n // Manual runs, e.g. through `wrangler dev --test-scheduled`, can have no cron expression.\n if (!cron) {\n return undefined;\n }\n\n let monitor: string | CronTriggerMonitorSettings | undefined;\n try {\n monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`[Cron Triggers] \\`monitorSlug\\` threw for \"${cron}\", sending no check-ins:`, e);\n return undefined;\n }\n\n if (!monitor) {\n return undefined;\n }\n\n const { monitorSlug, ...monitorSettings } = typeof monitor === 'string' ? { monitorSlug: monitor } : monitor;\n if (!monitorSlug) {\n return undefined;\n }\n\n const crontab = cloudflareCronToCrontab(cron);\n if (!crontab) {\n DEBUG_BUILD &&\n debug.warn(\n `[Cron Triggers] Can't convert \"${cron}\" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`,\n );\n }\n\n // Check-ins are captured directly rather than through `withMonitor`, which would fork the\n // isolation scope and lose the invocation state attached to it.\n const checkInId = captureCheckIn(\n { monitorSlug, status: 'in_progress' },\n crontab ? { ...monitorSettings, schedule: { type: 'crontab', value: crontab } } : undefined,\n );\n const startTime = timestampInSeconds();\n\n return status => {\n captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - startTime });\n };\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Sends cron check-ins for every Cron Trigger run of the `scheduled` handler, with the trigger's\n * schedule, so Sentry creates the monitor on the first run.\n *\n * Cron Triggers have no names, so map each cron expression to a slug. Without `monitorSlug`, the slug is\n * derived from the expression (`30 9 * * MON-FRI` becomes `cron-30-9-x-x-montofri`) and changes with it.\n * Workers that send to the same project get the same slug for the same expression, so they share a monitor.\n *\n * @example\n * ```ts\n * // src/monitorSlugs.ts\n * export const monitorSlugs: Record<string, string> = {\n * '30 9 * * MON-FRI': 'daily-report',\n * };\n *\n * // src/instrument.server.ts\n * import { cronTriggersIntegration, defineCloudflareOptions } from '@sentry/cloudflare';\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default defineCloudflareOptions((env) => ({\n * dsn: env.SENTRY_DSN,\n * integrations: [cronTriggersIntegration({ monitorSlug: (cron) => monitorSlugs[cron] })],\n * }));\n *\n * // src/index.ts\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default {\n * async scheduled(controller, env) {\n * switch (monitorSlugs[controller.cron]) {\n * case 'daily-report':\n * // ...\n * break;\n * }\n * },\n * };\n * ```\n */\nexport const cronTriggersIntegration = defineIntegration(_cronTriggersIntegration);\n"],"names":["DEBUG_BUILD","debug","captureCheckIn","timestampInSeconds","defineIntegration"],"mappings":";;;;;AAIA,MAAM,gBAAA,GAAmB,cAAA;AAsBzB,MAAM,WAAA,GAAsC,EAAE,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,IAAA,EAAM,GAAA,EAAK,IAAA,EAAK;AAQjG,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,IAAA,EAAK,CAAE,WAAA,GAAc,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAClE,EAAA,MAAM,IAAA,GAAO,QAAQ,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA,IAAA,KAAQ,WAAA,CAAY,IAAI,CAAW,CAAC,CAAA,CAAA;AACzF,EAAA,IAAI,oBAAA,CAAqB,IAAA,CAAK,IAAI,CAAA,EAAG;AACnC,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAA,EAAA,EAAK;AAC1C,IAAA,IAAA,GAAA,CAAQ,IAAA,GAAO,EAAA,GAAK,UAAA,CAAW,UAAA,CAAW,CAAC,CAAA,IAAK,UAA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BC,uBAAkB,wBAAwB;;;;"}
|
package/build/esm/dev/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { _INTERNAL_wrapRequestHandler, getDefaultIntegrations } from './sdk.js';
|
|
|
11
11
|
export { httpServerIntegration } from './integrations/httpServer.js';
|
|
12
12
|
export { fetchIntegration } from './integrations/fetch.js';
|
|
13
13
|
export { spotlightIntegration } from './integrations/spotlight.js';
|
|
14
|
+
export { cronTriggersIntegration } from './integrations/cronTriggers.js';
|
|
14
15
|
export { instrumentWorkflowWithSentry } from './workflows.js';
|
|
15
16
|
export { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_ORIGIN, FAAS_TRIGGER, FAAS_TIME, FAAS_CRON, CODE_FUNCTION_NAME, SENTRY_DESCRIPTION, SENTRY_OP } from '@sentry/conventions/attributes';
|
|
2
2
|
import { FUNCTION } from '@sentry/conventions/op';
|
|
3
|
-
import { withIsolationScope, startSpan, hasSpanStreamingEnabled, captureException } from '@sentry/core';
|
|
3
|
+
import { withIsolationScope, startSpan, hasSpanStreamingEnabled, debug, captureException } from '@sentry/core';
|
|
4
|
+
import { DEBUG_BUILD } from '../../debug-build.js';
|
|
4
5
|
import { flushAndDispose } from '../../flush.js';
|
|
5
6
|
import { ensureInstrumented } from '../../instrument.js';
|
|
6
7
|
import { getFinalOptions } from '../../options.js';
|
|
@@ -35,9 +36,28 @@ function wrapScheduledHandler(controller, options, context, fn) {
|
|
|
35
36
|
}
|
|
36
37
|
},
|
|
37
38
|
async () => {
|
|
39
|
+
let finishCheckIn;
|
|
38
40
|
try {
|
|
39
|
-
|
|
41
|
+
finishCheckIn = client?.getIntegrationByName("CronTriggers")?.startCheckIn(controller.cron);
|
|
42
|
+
if (finishCheckIn) {
|
|
43
|
+
waitUntil(Promise.resolve(client?.getTransport()?.flush(2e3)).catch(() => void 0));
|
|
44
|
+
}
|
|
40
45
|
} catch (e) {
|
|
46
|
+
DEBUG_BUILD && debug.warn("Failed to send the in_progress cron check-in", e);
|
|
47
|
+
}
|
|
48
|
+
const finish = (status) => {
|
|
49
|
+
try {
|
|
50
|
+
finishCheckIn?.(status);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
DEBUG_BUILD && debug.warn(`Failed to send the ${status} cron check-in`, e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const result = await fn();
|
|
57
|
+
finish("ok");
|
|
58
|
+
return result;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
finish("error");
|
|
41
61
|
captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.scheduled" } });
|
|
42
62
|
throw e;
|
|
43
63
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n
|
|
1
|
+
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, debug, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport type { CronTriggersIntegration } from '../../integrations/cronTriggers';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n let finishCheckIn: ReturnType<CronTriggersIntegration['startCheckIn']>;\n try {\n finishCheckIn = client\n ?.getIntegrationByName<CronTriggersIntegration>('CronTriggers')\n ?.startCheckIn(controller.cron);\n // The transport holds envelopes until the flush after the handler, so a run that is longer than\n // the check-in margin would deliver its in_progress check-in too late and show as missed.\n if (finishCheckIn) {\n waitUntil(Promise.resolve(client?.getTransport()?.flush(2000)).catch(() => undefined));\n }\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to send the in_progress cron check-in', e);\n }\n\n const finish = (status: 'ok' | 'error'): void => {\n try {\n finishCheckIn?.(status);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`Failed to send the ${status} cron check-in`, e);\n }\n };\n\n try {\n const result = await fn();\n finish('ok');\n return result;\n } catch (e) {\n finish('error');\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments a scheduled handler for ExportedHandler (env/ctx come from args).\n */\nexport function instrumentExportedHandlerScheduled<T extends AnyExportedHandler>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('scheduled' in handler) || typeof handler.scheduled !== 'function') {\n return;\n }\n\n handler.scheduled = ensureInstrumented(\n handler.scheduled,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['scheduled']>>) {\n const [controller, env, ctx] = args;\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n args[1] = instrumentEnv(env, options);\n args[2] = context;\n\n return wrapScheduledHandler(controller, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n\n/**\n * Instruments a scheduled method for WorkerEntrypoint (options/context already available).\n */\nexport function instrumentWorkerEntrypointScheduled<T extends WorkerEntrypoint>(\n instance: T,\n options: CloudflareOptions,\n context: ExecutionContext,\n): void {\n if (!instance.scheduled) {\n return;\n }\n\n const original = instance.scheduled.bind(instance);\n instance.scheduled = new Proxy(original, {\n apply(target, thisArg, args: [ScheduledController]) {\n const [controller] = args;\n\n return wrapScheduledHandler(controller, options, context, () => Reflect.apply(target, thisArg, args));\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA2BA,SAAS,oBAAA,CACP,UAAA,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EBUG_BUILD } from '../debug-build.js';
|
|
3
|
+
|
|
4
|
+
const INTEGRATION_NAME = "CronTriggers";
|
|
5
|
+
const SLUG_TOKENS = { " ": "-", "*": "x", ",": "_", "-": "to", "/": "by" };
|
|
6
|
+
function cronToMonitorSlug(cron) {
|
|
7
|
+
const expression = cron.trim().toLowerCase().split(/\s+/).join(" ");
|
|
8
|
+
const slug = `cron-${expression.replace(/[ *,\-/]/g, (char) => SLUG_TOKENS[char])}`;
|
|
9
|
+
if (/^[a-z0-9_-]{1,50}$/.test(slug)) {
|
|
10
|
+
return slug;
|
|
11
|
+
}
|
|
12
|
+
let hash = 0;
|
|
13
|
+
for (let i = 0; i < expression.length; i++) {
|
|
14
|
+
hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;
|
|
15
|
+
}
|
|
16
|
+
return `${slug.replace(/[^a-z0-9_-]+/g, "-").slice(0, 43)}-${hash.toString(36)}`;
|
|
17
|
+
}
|
|
18
|
+
const WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
19
|
+
function weekdayIndex(value) {
|
|
20
|
+
return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
function convertWeekdayItem(item) {
|
|
23
|
+
const match = item.match(/^(\*|\w+)(?:-(\w+))?(?:\/(\d+))?$/);
|
|
24
|
+
if (!match) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
const [, from, to, step] = match;
|
|
28
|
+
if (step && !(Number(step) > 0)) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
if (from === "*") {
|
|
32
|
+
return to ? void 0 : item;
|
|
33
|
+
}
|
|
34
|
+
const start = weekdayIndex(from);
|
|
35
|
+
const end = to ? weekdayIndex(to) : step ? 6 : start;
|
|
36
|
+
if (start < 0 || end < start) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
if (start === end) {
|
|
40
|
+
return WEEKDAYS[start];
|
|
41
|
+
}
|
|
42
|
+
const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;
|
|
43
|
+
return step ? `${days}/${step}` : days;
|
|
44
|
+
}
|
|
45
|
+
function cloudflareCronToCrontab(cron) {
|
|
46
|
+
const fields = cron.trim().split(/\s+/);
|
|
47
|
+
const [, , dayOfMonth = "", , dayOfWeek = ""] = fields;
|
|
48
|
+
if (fields.length !== 5 || /[w?]|l-/i.test(dayOfMonth) || dayOfMonth !== "*" && dayOfWeek !== "*" && (dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*"))) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const weekdays = dayOfWeek.split(",").map(convertWeekdayItem);
|
|
52
|
+
return weekdays.includes(void 0) ? void 0 : [...fields.slice(0, 4), weekdays.join(",")].join(" ");
|
|
53
|
+
}
|
|
54
|
+
const _cronTriggersIntegration = ((options = {}) => {
|
|
55
|
+
return {
|
|
56
|
+
name: INTEGRATION_NAME,
|
|
57
|
+
startCheckIn(cron) {
|
|
58
|
+
if (!cron) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
let monitor;
|
|
62
|
+
try {
|
|
63
|
+
monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
DEBUG_BUILD && debug.warn(`[Cron Triggers] \`monitorSlug\` threw for "${cron}", sending no check-ins:`, e);
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
if (!monitor) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
const { monitorSlug, ...monitorSettings } = typeof monitor === "string" ? { monitorSlug: monitor } : monitor;
|
|
72
|
+
if (!monitorSlug) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
const crontab = cloudflareCronToCrontab(cron);
|
|
76
|
+
if (!crontab) {
|
|
77
|
+
DEBUG_BUILD && debug.warn(
|
|
78
|
+
`[Cron Triggers] Can't convert "${cron}" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const checkInId = captureCheckIn(
|
|
82
|
+
{ monitorSlug, status: "in_progress" },
|
|
83
|
+
crontab ? { ...monitorSettings, schedule: { type: "crontab", value: crontab } } : void 0
|
|
84
|
+
);
|
|
85
|
+
const startTime = timestampInSeconds();
|
|
86
|
+
return (status) => {
|
|
87
|
+
captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - startTime });
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
const cronTriggersIntegration = defineIntegration(_cronTriggersIntegration);
|
|
93
|
+
|
|
94
|
+
export { cronTriggersIntegration };
|
|
95
|
+
//# sourceMappingURL=cronTriggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronTriggers.js","sources":["../../../../src/integrations/cronTriggers.ts"],"sourcesContent":["import type { IntegrationFn, MonitorConfig } from '@sentry/core';\nimport { captureCheckIn, debug, defineIntegration, timestampInSeconds } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\nconst INTEGRATION_NAME = 'CronTriggers' as const;\n\n/**\n * The monitor slug and settings for a Cron Trigger, see `cronTriggersIntegration`.\n */\nexport type CronTriggerMonitorSettings = { monitorSlug: string } & Omit<MonitorConfig, 'schedule' | 'timezone'>;\n\nexport interface CronTriggersOptions {\n /**\n * Chooses the monitor slug for a cron expression. It can also return an object with the `monitorSlug`\n * and other monitor settings, such as `checkinMargin` or `maxRuntime`. Returning `undefined`\n * sends no check-ins for that trigger, and so does a function that throws.\n */\n monitorSlug?: (cron: string) => string | CronTriggerMonitorSettings | undefined;\n}\n\n/** @internal Used by the scheduled handler instrumentation. */\nexport interface CronTriggersIntegration {\n name: string;\n startCheckIn(cron: string): ((status: 'ok' | 'error') => void) | undefined;\n}\n\nconst SLUG_TOKENS: Record<string, string> = { ' ': '-', '*': 'x', ',': '_', '-': 'to', '/': 'by' };\n\n/**\n * Derives a monitor slug from a cron expression, e.g. `30 9 * * MON-FRI` -> `cron-30-9-x-x-montofri`.\n *\n * A hash of the expression is appended when it has any other characters or the slug would be\n * longer than 50 characters, so different expressions don't share a slug.\n */\nfunction cronToMonitorSlug(cron: string): string {\n const expression = cron.trim().toLowerCase().split(/\\s+/).join(' ');\n const slug = `cron-${expression.replace(/[ *,\\-/]/g, char => SLUG_TOKENS[char] as string)}`;\n if (/^[a-z0-9_-]{1,50}$/.test(slug)) {\n return slug;\n }\n\n // A polynomial string hash modulo 2^31 - 1, at most 6 characters in base 36.\n let hash = 0;\n for (let i = 0; i < expression.length; i++) {\n hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;\n }\n return `${slug.replace(/[^a-z0-9_-]+/g, '-').slice(0, 43)}-${hash.toString(36)}`;\n}\n\nconst WEEKDAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];\n\n// Cloudflare numbers weekdays from 1 = Sunday to 7 = Saturday. Returns -1 for anything else.\nfunction weekdayIndex(value: string): number {\n return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());\n}\n\nfunction convertWeekdayItem(item: string): string | undefined {\n const match = item.match(/^(\\*|\\w+)(?:-(\\w+))?(?:\\/(\\d+))?$/);\n if (!match) {\n return undefined;\n }\n const [, from, to, step] = match;\n if (step && !(Number(step) > 0)) {\n return undefined;\n }\n\n // `*` and `*/n` give the same days in both numberings, and keep their `*` meaning for Sentry.\n if (from === '*') {\n return to ? undefined : item;\n }\n\n const start = weekdayIndex(from as string);\n // A step without an end runs to Saturday, so it is written as a range.\n const end = to ? weekdayIndex(to) : step ? 6 : start;\n if (start < 0 || end < start) {\n return undefined;\n }\n\n // A step over a single day would run on to Sunday in Sentry's cron parser, so it is left out.\n if (start === end) {\n return WEEKDAYS[start];\n }\n const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;\n return step ? `${days}/${step}` : days;\n}\n\n/**\n * Converts a Cloudflare cron expression into a crontab Sentry accepts, which numbers weekdays from\n * 0 = Sunday. Returns `undefined` if the day fields can't be converted.\n */\nfunction cloudflareCronToCrontab(cron: string): string | undefined {\n const fields = cron.trim().split(/\\s+/);\n const [, , dayOfMonth = '', , dayOfWeek = ''] = fields;\n // Sentry rejects `W`, `?` and `L-n` in the day of month. When both day fields are set, Cloudflare and Sentry\n // run on the days that match either field, but Sentry requires both to match when one starts with `*`.\n if (\n fields.length !== 5 ||\n /[w?]|l-/i.test(dayOfMonth) ||\n (dayOfMonth !== '*' && dayOfWeek !== '*' && (dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*')))\n ) {\n return undefined;\n }\n\n const weekdays = dayOfWeek.split(',').map(convertWeekdayItem);\n return weekdays.includes(undefined) ? undefined : [...fields.slice(0, 4), weekdays.join(',')].join(' ');\n}\n\nconst _cronTriggersIntegration = ((options: CronTriggersOptions = {}): CronTriggersIntegration => {\n return {\n name: INTEGRATION_NAME,\n startCheckIn(cron) {\n // Manual runs, e.g. through `wrangler dev --test-scheduled`, can have no cron expression.\n if (!cron) {\n return undefined;\n }\n\n let monitor: string | CronTriggerMonitorSettings | undefined;\n try {\n monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`[Cron Triggers] \\`monitorSlug\\` threw for \"${cron}\", sending no check-ins:`, e);\n return undefined;\n }\n\n if (!monitor) {\n return undefined;\n }\n\n const { monitorSlug, ...monitorSettings } = typeof monitor === 'string' ? { monitorSlug: monitor } : monitor;\n if (!monitorSlug) {\n return undefined;\n }\n\n const crontab = cloudflareCronToCrontab(cron);\n if (!crontab) {\n DEBUG_BUILD &&\n debug.warn(\n `[Cron Triggers] Can't convert \"${cron}\" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`,\n );\n }\n\n // Check-ins are captured directly rather than through `withMonitor`, which would fork the\n // isolation scope and lose the invocation state attached to it.\n const checkInId = captureCheckIn(\n { monitorSlug, status: 'in_progress' },\n crontab ? { ...monitorSettings, schedule: { type: 'crontab', value: crontab } } : undefined,\n );\n const startTime = timestampInSeconds();\n\n return status => {\n captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - startTime });\n };\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Sends cron check-ins for every Cron Trigger run of the `scheduled` handler, with the trigger's\n * schedule, so Sentry creates the monitor on the first run.\n *\n * Cron Triggers have no names, so map each cron expression to a slug. Without `monitorSlug`, the slug is\n * derived from the expression (`30 9 * * MON-FRI` becomes `cron-30-9-x-x-montofri`) and changes with it.\n * Workers that send to the same project get the same slug for the same expression, so they share a monitor.\n *\n * @example\n * ```ts\n * // src/monitorSlugs.ts\n * export const monitorSlugs: Record<string, string> = {\n * '30 9 * * MON-FRI': 'daily-report',\n * };\n *\n * // src/instrument.server.ts\n * import { cronTriggersIntegration, defineCloudflareOptions } from '@sentry/cloudflare';\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default defineCloudflareOptions((env) => ({\n * dsn: env.SENTRY_DSN,\n * integrations: [cronTriggersIntegration({ monitorSlug: (cron) => monitorSlugs[cron] })],\n * }));\n *\n * // src/index.ts\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default {\n * async scheduled(controller, env) {\n * switch (monitorSlugs[controller.cron]) {\n * case 'daily-report':\n * // ...\n * break;\n * }\n * },\n * };\n * ```\n */\nexport const cronTriggersIntegration = defineIntegration(_cronTriggersIntegration);\n"],"names":[],"mappings":";;;AAIA,MAAM,gBAAA,GAAmB,cAAA;AAsBzB,MAAM,WAAA,GAAsC,EAAE,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,IAAA,EAAM,GAAA,EAAK,IAAA,EAAK;AAQjG,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA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CAAM,IAAA;AAAA,UACJ,kCAAkC,IAAI,CAAA,2FAAA;AAAA,SACxC;AAAA,MACJ;AAIA,MAAA,MAAM,SAAA,GAAY,cAAA;AAAA,QAChB,EAAE,WAAA,EAAa,MAAA,EAAQ,aAAA,EAAc;AAAA,QACrC,OAAA,GAAU,EAAE,GAAG,eAAA,EAAiB,QAAA,EAAU,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAO,OAAA,EAAQ,EAAE,GAAI;AAAA,OACpF;AACA,MAAA,MAAM,YAAY,kBAAA,EAAmB;AAErC,MAAA,OAAO,CAAA,MAAA,KAAU;AACf,QAAA,cAAA,CAAe,EAAE,aAAa,MAAA,EAAQ,SAAA,EAAW,UAAU,kBAAA,EAAmB,GAAI,WAAW,CAAA;AAAA,MAC/F,CAAA;AAAA,IACF;AAAA,GACF;AACF,CAAA,CAAA;AAwCO,MAAM,uBAAA,GAA0B,kBAAkB,wBAAwB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"11.
|
|
1
|
+
{"type":"module","version":"11.7.0","sideEffects":false}
|
package/build/esm/prod/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { _INTERNAL_wrapRequestHandler, getDefaultIntegrations } from './sdk.js';
|
|
|
11
11
|
export { httpServerIntegration } from './integrations/httpServer.js';
|
|
12
12
|
export { fetchIntegration } from './integrations/fetch.js';
|
|
13
13
|
export { spotlightIntegration } from './integrations/spotlight.js';
|
|
14
|
+
export { cronTriggersIntegration } from './integrations/cronTriggers.js';
|
|
14
15
|
export { instrumentWorkflowWithSentry } from './workflows.js';
|
|
15
16
|
export { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
|
|
16
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_ORIGIN, FAAS_TRIGGER, FAAS_TIME, FAAS_CRON, CODE_FUNCTION_NAME, SENTRY_DESCRIPTION, SENTRY_OP } from '@sentry/conventions/attributes';
|
|
2
2
|
import { FUNCTION } from '@sentry/conventions/op';
|
|
3
|
-
import { withIsolationScope, startSpan, hasSpanStreamingEnabled, captureException } from '@sentry/core';
|
|
3
|
+
import { withIsolationScope, startSpan, hasSpanStreamingEnabled, debug, captureException } from '@sentry/core';
|
|
4
|
+
import { DEBUG_BUILD } from '../../debug-build.js';
|
|
4
5
|
import { flushAndDispose } from '../../flush.js';
|
|
5
6
|
import { ensureInstrumented } from '../../instrument.js';
|
|
6
7
|
import { getFinalOptions } from '../../options.js';
|
|
@@ -35,9 +36,28 @@ function wrapScheduledHandler(controller, options, context, fn) {
|
|
|
35
36
|
}
|
|
36
37
|
},
|
|
37
38
|
async () => {
|
|
39
|
+
let finishCheckIn;
|
|
38
40
|
try {
|
|
39
|
-
|
|
41
|
+
finishCheckIn = client?.getIntegrationByName("CronTriggers")?.startCheckIn(controller.cron);
|
|
42
|
+
if (finishCheckIn) {
|
|
43
|
+
waitUntil(Promise.resolve(client?.getTransport()?.flush(2e3)).catch(() => void 0));
|
|
44
|
+
}
|
|
40
45
|
} catch (e) {
|
|
46
|
+
DEBUG_BUILD && debug.warn("Failed to send the in_progress cron check-in", e);
|
|
47
|
+
}
|
|
48
|
+
const finish = (status) => {
|
|
49
|
+
try {
|
|
50
|
+
finishCheckIn?.(status);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
DEBUG_BUILD && debug.warn(`Failed to send the ${status} cron check-in`, e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
try {
|
|
56
|
+
const result = await fn();
|
|
57
|
+
finish("ok");
|
|
58
|
+
return result;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
finish("error");
|
|
41
61
|
captureException(e, { mechanism: { handled: false, type: "auto.faas.cloudflare.scheduled" } });
|
|
42
62
|
throw e;
|
|
43
63
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n try {\n
|
|
1
|
+
{"version":3,"file":"instrumentScheduled.js","sources":["../../../../../src/instrumentations/worker/instrumentScheduled.ts"],"sourcesContent":["import type { ScheduledController } from '@cloudflare/workers-types';\nimport type { AnyExportedHandler } from '../../types';\nimport type { env as cloudflareEnv, WorkerEntrypoint } from 'cloudflare:workers';\nimport {\n SENTRY_SEGMENT_NAME_SOURCE,\n CODE_FUNCTION_NAME,\n SENTRY_OP,\n FAAS_CRON,\n FAAS_TIME,\n FAAS_TRIGGER,\n SENTRY_DESCRIPTION,\n SENTRY_ORIGIN,\n} from '@sentry/conventions/attributes';\nimport { FUNCTION } from '@sentry/conventions/op';\nimport { captureException, debug, hasSpanStreamingEnabled, startSpan, withIsolationScope } from '@sentry/core';\nimport type { CloudflareOptions } from '../../client';\nimport { DEBUG_BUILD } from '../../debug-build';\nimport { flushAndDispose } from '../../flush';\nimport { ensureInstrumented } from '../../instrument';\nimport type { CronTriggersIntegration } from '../../integrations/cronTriggers';\nimport { getFinalOptions } from '../../options';\nimport { addCloudResourceContext } from '../../scope-utils';\nimport { init } from '../../sdk';\nimport { instrumentContext } from '../../utils/instrumentContext';\nimport { setInvocationState } from '../../utils/invocationContext';\nimport { instrumentEnv } from './instrumentEnv';\n\nfunction wrapScheduledHandler(\n controller: ScheduledController,\n options: CloudflareOptions,\n context: ExecutionContext,\n fn: () => unknown,\n): unknown {\n return withIsolationScope(isolationScope => {\n const waitUntil = context.waitUntil.bind(context);\n\n setInvocationState(isolationScope, { ctx: context });\n\n const client = init({ ...options, ctx: context });\n isolationScope.setClient(client);\n\n addCloudResourceContext(isolationScope);\n\n const description = `Scheduled Cron ${controller.cron}`;\n\n return startSpan(\n {\n name: client && hasSpanStreamingEnabled(client) ? 'scheduled' : description,\n attributes: {\n [SENTRY_OP]: FUNCTION,\n // override description inference by Relay to preserve the original (transaction-based) description.\n // sentry-conventions can't map the special case for the \"Scheduled Cron\" prefix and the chron string.\n [SENTRY_DESCRIPTION]: description,\n [CODE_FUNCTION_NAME]: 'scheduled',\n [FAAS_CRON]: controller.cron,\n [FAAS_TIME]: new Date(controller.scheduledTime).toISOString(),\n [FAAS_TRIGGER]: 'timer',\n [SENTRY_ORIGIN]: 'auto.faas.cloudflare.scheduled',\n [SENTRY_SEGMENT_NAME_SOURCE]: 'task',\n },\n },\n async () => {\n let finishCheckIn: ReturnType<CronTriggersIntegration['startCheckIn']>;\n try {\n finishCheckIn = client\n ?.getIntegrationByName<CronTriggersIntegration>('CronTriggers')\n ?.startCheckIn(controller.cron);\n // The transport holds envelopes until the flush after the handler, so a run that is longer than\n // the check-in margin would deliver its in_progress check-in too late and show as missed.\n if (finishCheckIn) {\n waitUntil(Promise.resolve(client?.getTransport()?.flush(2000)).catch(() => undefined));\n }\n } catch (e) {\n DEBUG_BUILD && debug.warn('Failed to send the in_progress cron check-in', e);\n }\n\n const finish = (status: 'ok' | 'error'): void => {\n try {\n finishCheckIn?.(status);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`Failed to send the ${status} cron check-in`, e);\n }\n };\n\n try {\n const result = await fn();\n finish('ok');\n return result;\n } catch (e) {\n finish('error');\n captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' } });\n throw e;\n } finally {\n waitUntil(flushAndDispose(client));\n }\n },\n );\n });\n}\n\n/**\n * Instruments a scheduled handler for ExportedHandler (env/ctx come from args).\n */\nexport function instrumentExportedHandlerScheduled<T extends AnyExportedHandler>(\n handler: T,\n optionsCallback: (env: typeof cloudflareEnv) => CloudflareOptions | undefined,\n): void {\n if (!('scheduled' in handler) || typeof handler.scheduled !== 'function') {\n return;\n }\n\n handler.scheduled = ensureInstrumented(\n handler.scheduled,\n original =>\n new Proxy(original, {\n apply(target, thisArg, args: Parameters<NonNullable<T['scheduled']>>) {\n const [controller, env, ctx] = args;\n const context = instrumentContext(ctx);\n const options = getFinalOptions(optionsCallback(env), env);\n args[1] = instrumentEnv(env, options);\n args[2] = context;\n\n return wrapScheduledHandler(controller, options, context, () => target.apply(thisArg, args));\n },\n }),\n );\n}\n\n/**\n * Instruments a scheduled method for WorkerEntrypoint (options/context already available).\n */\nexport function instrumentWorkerEntrypointScheduled<T extends WorkerEntrypoint>(\n instance: T,\n options: CloudflareOptions,\n context: ExecutionContext,\n): void {\n if (!instance.scheduled) {\n return;\n }\n\n const original = instance.scheduled.bind(instance);\n instance.scheduled = new Proxy(original, {\n apply(target, thisArg, args: [ScheduledController]) {\n const [controller] = args;\n\n return wrapScheduledHandler(controller, options, context, () => Reflect.apply(target, thisArg, args));\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AA2BA,SAAS,oBAAA,CACP,UAAA,EACA,OAAA,EACA,OAAA,EACA,EAAA,EACS;AACT,EAAA,OAAO,mBAAmB,CAAA,cAAA,KAAkB;AAC1C,IAAA,MAAM,SAAA,GAAY,OAAA,CAAQ,SAAA,CAAU,IAAA,CAAK,OAAO,CAAA;AAEhD,IAAA,kBAAA,CAAmB,cAAA,EAAgB,EAAE,GAAA,EAAK,OAAA,EAAS,CAAA;AAEnD,IAAA,MAAM,SAAS,IAAA,CAAK,EAAE,GAAG,OAAA,EAAS,GAAA,EAAK,SAAS,CAAA;AAChD,IAAA,cAAA,CAAe,UAAU,MAAM,CAAA;AAE/B,IAAA,uBAAA,CAAwB,cAAc,CAAA;AAEtC,IAAA,MAAM,WAAA,GAAc,CAAA,eAAA,EAAkB,UAAA,CAAW,IAAI,CAAA,CAAA;AAErD,IAAA,OAAO,SAAA;AAAA,MACL;AAAA,QACE,IAAA,EAAM,MAAA,IAAU,uBAAA,CAAwB,MAAM,I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KO,SAAS,mCAAA,CACd,QAAA,EACA,OAAA,EACA,OAAA,EACM;AACN,EAAA,IAAI,CAAC,SAAS,SAAA,EAAW;AACvB,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,SAAA,CAAU,IAAA,CAAK,QAAQ,CAAA;AACjD,EAAA,QAAA,CAAS,SAAA,GAAY,IAAI,KAAA,CAAM,QAAA,EAAU;AAAA,IACvC,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAA,EAA6B;AAClD,MAAA,MAAM,CAAC,UAAU,CAAA,GAAI,IAAA;AAErB,MAAA,OAAO,oBAAA,CAAqB,UAAA,EAAY,OAAA,EAAS,OAAA,EAAS,MAAM,QAAQ,KAAA,CAAM,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAC,CAAA;AAAA,IACtG;AAAA,GACD,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { defineIntegration, debug, captureCheckIn, timestampInSeconds } from '@sentry/core';
|
|
2
|
+
import { DEBUG_BUILD } from '../debug-build.js';
|
|
3
|
+
|
|
4
|
+
const INTEGRATION_NAME = "CronTriggers";
|
|
5
|
+
const SLUG_TOKENS = { " ": "-", "*": "x", ",": "_", "-": "to", "/": "by" };
|
|
6
|
+
function cronToMonitorSlug(cron) {
|
|
7
|
+
const expression = cron.trim().toLowerCase().split(/\s+/).join(" ");
|
|
8
|
+
const slug = `cron-${expression.replace(/[ *,\-/]/g, (char) => SLUG_TOKENS[char])}`;
|
|
9
|
+
if (/^[a-z0-9_-]{1,50}$/.test(slug)) {
|
|
10
|
+
return slug;
|
|
11
|
+
}
|
|
12
|
+
let hash = 0;
|
|
13
|
+
for (let i = 0; i < expression.length; i++) {
|
|
14
|
+
hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;
|
|
15
|
+
}
|
|
16
|
+
return `${slug.replace(/[^a-z0-9_-]+/g, "-").slice(0, 43)}-${hash.toString(36)}`;
|
|
17
|
+
}
|
|
18
|
+
const WEEKDAYS = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
|
|
19
|
+
function weekdayIndex(value) {
|
|
20
|
+
return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());
|
|
21
|
+
}
|
|
22
|
+
function convertWeekdayItem(item) {
|
|
23
|
+
const match = item.match(/^(\*|\w+)(?:-(\w+))?(?:\/(\d+))?$/);
|
|
24
|
+
if (!match) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
const [, from, to, step] = match;
|
|
28
|
+
if (step && !(Number(step) > 0)) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
if (from === "*") {
|
|
32
|
+
return to ? void 0 : item;
|
|
33
|
+
}
|
|
34
|
+
const start = weekdayIndex(from);
|
|
35
|
+
const end = to ? weekdayIndex(to) : step ? 6 : start;
|
|
36
|
+
if (start < 0 || end < start) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
if (start === end) {
|
|
40
|
+
return WEEKDAYS[start];
|
|
41
|
+
}
|
|
42
|
+
const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;
|
|
43
|
+
return step ? `${days}/${step}` : days;
|
|
44
|
+
}
|
|
45
|
+
function cloudflareCronToCrontab(cron) {
|
|
46
|
+
const fields = cron.trim().split(/\s+/);
|
|
47
|
+
const [, , dayOfMonth = "", , dayOfWeek = ""] = fields;
|
|
48
|
+
if (fields.length !== 5 || /[w?]|l-/i.test(dayOfMonth) || dayOfMonth !== "*" && dayOfWeek !== "*" && (dayOfMonth.startsWith("*") || dayOfWeek.startsWith("*"))) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
const weekdays = dayOfWeek.split(",").map(convertWeekdayItem);
|
|
52
|
+
return weekdays.includes(void 0) ? void 0 : [...fields.slice(0, 4), weekdays.join(",")].join(" ");
|
|
53
|
+
}
|
|
54
|
+
const _cronTriggersIntegration = ((options = {}) => {
|
|
55
|
+
return {
|
|
56
|
+
name: INTEGRATION_NAME,
|
|
57
|
+
startCheckIn(cron) {
|
|
58
|
+
if (!cron) {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
let monitor;
|
|
62
|
+
try {
|
|
63
|
+
monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);
|
|
64
|
+
} catch (e) {
|
|
65
|
+
DEBUG_BUILD && debug.warn(`[Cron Triggers] \`monitorSlug\` threw for "${cron}", sending no check-ins:`, e);
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
if (!monitor) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
const { monitorSlug, ...monitorSettings } = typeof monitor === "string" ? { monitorSlug: monitor } : monitor;
|
|
72
|
+
if (!monitorSlug) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
const crontab = cloudflareCronToCrontab(cron);
|
|
76
|
+
if (!crontab) {
|
|
77
|
+
DEBUG_BUILD && debug.warn(
|
|
78
|
+
`[Cron Triggers] Can't convert "${cron}" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const checkInId = captureCheckIn(
|
|
82
|
+
{ monitorSlug, status: "in_progress" },
|
|
83
|
+
crontab ? { ...monitorSettings, schedule: { type: "crontab", value: crontab } } : void 0
|
|
84
|
+
);
|
|
85
|
+
const startTime = timestampInSeconds();
|
|
86
|
+
return (status) => {
|
|
87
|
+
captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - startTime });
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
const cronTriggersIntegration = defineIntegration(_cronTriggersIntegration);
|
|
93
|
+
|
|
94
|
+
export { cronTriggersIntegration };
|
|
95
|
+
//# sourceMappingURL=cronTriggers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronTriggers.js","sources":["../../../../src/integrations/cronTriggers.ts"],"sourcesContent":["import type { IntegrationFn, MonitorConfig } from '@sentry/core';\nimport { captureCheckIn, debug, defineIntegration, timestampInSeconds } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\nconst INTEGRATION_NAME = 'CronTriggers' as const;\n\n/**\n * The monitor slug and settings for a Cron Trigger, see `cronTriggersIntegration`.\n */\nexport type CronTriggerMonitorSettings = { monitorSlug: string } & Omit<MonitorConfig, 'schedule' | 'timezone'>;\n\nexport interface CronTriggersOptions {\n /**\n * Chooses the monitor slug for a cron expression. It can also return an object with the `monitorSlug`\n * and other monitor settings, such as `checkinMargin` or `maxRuntime`. Returning `undefined`\n * sends no check-ins for that trigger, and so does a function that throws.\n */\n monitorSlug?: (cron: string) => string | CronTriggerMonitorSettings | undefined;\n}\n\n/** @internal Used by the scheduled handler instrumentation. */\nexport interface CronTriggersIntegration {\n name: string;\n startCheckIn(cron: string): ((status: 'ok' | 'error') => void) | undefined;\n}\n\nconst SLUG_TOKENS: Record<string, string> = { ' ': '-', '*': 'x', ',': '_', '-': 'to', '/': 'by' };\n\n/**\n * Derives a monitor slug from a cron expression, e.g. `30 9 * * MON-FRI` -> `cron-30-9-x-x-montofri`.\n *\n * A hash of the expression is appended when it has any other characters or the slug would be\n * longer than 50 characters, so different expressions don't share a slug.\n */\nfunction cronToMonitorSlug(cron: string): string {\n const expression = cron.trim().toLowerCase().split(/\\s+/).join(' ');\n const slug = `cron-${expression.replace(/[ *,\\-/]/g, char => SLUG_TOKENS[char] as string)}`;\n if (/^[a-z0-9_-]{1,50}$/.test(slug)) {\n return slug;\n }\n\n // A polynomial string hash modulo 2^31 - 1, at most 6 characters in base 36.\n let hash = 0;\n for (let i = 0; i < expression.length; i++) {\n hash = (hash * 31 + expression.charCodeAt(i)) % 2147483647;\n }\n return `${slug.replace(/[^a-z0-9_-]+/g, '-').slice(0, 43)}-${hash.toString(36)}`;\n}\n\nconst WEEKDAYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];\n\n// Cloudflare numbers weekdays from 1 = Sunday to 7 = Saturday. Returns -1 for anything else.\nfunction weekdayIndex(value: string): number {\n return /^[1-7]$/.test(value) ? Number(value) - 1 : WEEKDAYS.indexOf(value.toUpperCase());\n}\n\nfunction convertWeekdayItem(item: string): string | undefined {\n const match = item.match(/^(\\*|\\w+)(?:-(\\w+))?(?:\\/(\\d+))?$/);\n if (!match) {\n return undefined;\n }\n const [, from, to, step] = match;\n if (step && !(Number(step) > 0)) {\n return undefined;\n }\n\n // `*` and `*/n` give the same days in both numberings, and keep their `*` meaning for Sentry.\n if (from === '*') {\n return to ? undefined : item;\n }\n\n const start = weekdayIndex(from as string);\n // A step without an end runs to Saturday, so it is written as a range.\n const end = to ? weekdayIndex(to) : step ? 6 : start;\n if (start < 0 || end < start) {\n return undefined;\n }\n\n // A step over a single day would run on to Sunday in Sentry's cron parser, so it is left out.\n if (start === end) {\n return WEEKDAYS[start];\n }\n const days = `${WEEKDAYS[start]}-${WEEKDAYS[end]}`;\n return step ? `${days}/${step}` : days;\n}\n\n/**\n * Converts a Cloudflare cron expression into a crontab Sentry accepts, which numbers weekdays from\n * 0 = Sunday. Returns `undefined` if the day fields can't be converted.\n */\nfunction cloudflareCronToCrontab(cron: string): string | undefined {\n const fields = cron.trim().split(/\\s+/);\n const [, , dayOfMonth = '', , dayOfWeek = ''] = fields;\n // Sentry rejects `W`, `?` and `L-n` in the day of month. When both day fields are set, Cloudflare and Sentry\n // run on the days that match either field, but Sentry requires both to match when one starts with `*`.\n if (\n fields.length !== 5 ||\n /[w?]|l-/i.test(dayOfMonth) ||\n (dayOfMonth !== '*' && dayOfWeek !== '*' && (dayOfMonth.startsWith('*') || dayOfWeek.startsWith('*')))\n ) {\n return undefined;\n }\n\n const weekdays = dayOfWeek.split(',').map(convertWeekdayItem);\n return weekdays.includes(undefined) ? undefined : [...fields.slice(0, 4), weekdays.join(',')].join(' ');\n}\n\nconst _cronTriggersIntegration = ((options: CronTriggersOptions = {}): CronTriggersIntegration => {\n return {\n name: INTEGRATION_NAME,\n startCheckIn(cron) {\n // Manual runs, e.g. through `wrangler dev --test-scheduled`, can have no cron expression.\n if (!cron) {\n return undefined;\n }\n\n let monitor: string | CronTriggerMonitorSettings | undefined;\n try {\n monitor = options.monitorSlug ? options.monitorSlug(cron) : cronToMonitorSlug(cron);\n } catch (e) {\n DEBUG_BUILD && debug.warn(`[Cron Triggers] \\`monitorSlug\\` threw for \"${cron}\", sending no check-ins:`, e);\n return undefined;\n }\n\n if (!monitor) {\n return undefined;\n }\n\n const { monitorSlug, ...monitorSettings } = typeof monitor === 'string' ? { monitorSlug: monitor } : monitor;\n if (!monitorSlug) {\n return undefined;\n }\n\n const crontab = cloudflareCronToCrontab(cron);\n if (!crontab) {\n DEBUG_BUILD &&\n debug.warn(\n `[Cron Triggers] Can't convert \"${cron}\" to a Sentry schedule, sending check-ins without a schedule or the other monitor settings.`,\n );\n }\n\n // Check-ins are captured directly rather than through `withMonitor`, which would fork the\n // isolation scope and lose the invocation state attached to it.\n const checkInId = captureCheckIn(\n { monitorSlug, status: 'in_progress' },\n crontab ? { ...monitorSettings, schedule: { type: 'crontab', value: crontab } } : undefined,\n );\n const startTime = timestampInSeconds();\n\n return status => {\n captureCheckIn({ monitorSlug, status, checkInId, duration: timestampInSeconds() - startTime });\n };\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Sends cron check-ins for every Cron Trigger run of the `scheduled` handler, with the trigger's\n * schedule, so Sentry creates the monitor on the first run.\n *\n * Cron Triggers have no names, so map each cron expression to a slug. Without `monitorSlug`, the slug is\n * derived from the expression (`30 9 * * MON-FRI` becomes `cron-30-9-x-x-montofri`) and changes with it.\n * Workers that send to the same project get the same slug for the same expression, so they share a monitor.\n *\n * @example\n * ```ts\n * // src/monitorSlugs.ts\n * export const monitorSlugs: Record<string, string> = {\n * '30 9 * * MON-FRI': 'daily-report',\n * };\n *\n * // src/instrument.server.ts\n * import { cronTriggersIntegration, defineCloudflareOptions } from '@sentry/cloudflare';\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default defineCloudflareOptions((env) => ({\n * dsn: env.SENTRY_DSN,\n * integrations: [cronTriggersIntegration({ monitorSlug: (cron) => monitorSlugs[cron] })],\n * }));\n *\n * // src/index.ts\n * import { monitorSlugs } from './monitorSlugs';\n *\n * export default {\n * async scheduled(controller, env) {\n * switch (monitorSlugs[controller.cron]) {\n * case 'daily-report':\n * // ...\n * break;\n * }\n * },\n * };\n * ```\n */\nexport const cronTriggersIntegration = defineIntegration(_cronTriggersIntegration);\n"],"names":[],"mappings":";;;AAIA,MAAM,gBAAA,GAAmB,cAAA;AAsBzB,MAAM,WAAA,GAAsC,EAAE,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,IAAA,EAAM,GAAA,EAAK,IAAA,EAAK;AAQjG,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA,MAAM,UAAA,GAAa,IAAA,CAAK,IAAA,EAAK,CAAE,WAAA,GAAc,KAAA,CAAM,KAAK,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAClE,EAAA,MAAM,IAAA,GAAO,QAAQ,UAAA,CAAW,OAAA,CAAQ,aAAa,CAAA,IAAA,KAAQ,WAAA,CAAY,IAAI,CAAW,CAAC,CAAA,CAAA;AACzF,EAAA,IAAI,oBAAA,CAAqB,IAAA,CAAK,IAAI,CAAA,EAAG;AACnC,IAAA,OAAO,IAAA;AAAA,EACT;AAGA,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,UAAA,CAAW,QAAQ,CAAA,EAAA,EAAK;AAC1C,IAAA,IAAA,GAAA,CAAQ,IAAA,GAAO,EAAA,GAAK,UAAA,CAAW,UAAA,CAAW,CAAC,CAAA,IAAK,UAAA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wB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"11.
|
|
1
|
+
{"type":"module","version":"11.7.0","sideEffects":false}
|
package/build/types/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export { httpServerIntegration } from './integrations/httpServer';
|
|
|
15
15
|
export { fetchIntegration } from './integrations/fetch';
|
|
16
16
|
export type { FetchIntegrationOptions } from '@sentry/core';
|
|
17
17
|
export { spotlightIntegration } from './integrations/spotlight';
|
|
18
|
+
export { cronTriggersIntegration } from './integrations/cronTriggers';
|
|
19
|
+
export type { CronTriggerMonitorSettings, CronTriggersOptions } from './integrations/cronTriggers';
|
|
18
20
|
export { openTelemetryIntegration, getOtlpTracesEndpoint, prismaIntegration, instrumentMistralAiClient, instrumentTypeSafeClient, instrumentOpenAiClient, instrumentAnthropicAiClient, instrumentGoogleGenAIClient, instrumentWorkersAiClient, createLangChainCallbackHandler, instrumentLangChainEmbeddings, instrumentStateGraph, instrumentCreateReactAgent, vercelAIIntegration, honoIntegration, honoMiddleware, eveConversationHook, eveIntegration, getInstrumentedModuleNames, } from '@sentry/server-utils';
|
|
19
21
|
export { instrumentWorkflowWithSentry } from './workflows';
|
|
20
22
|
export { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/server-utils/no-diagnostic-channels';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACP,KAAK,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,uBAAuB,EACvB,OAAO,EACP,aAAa,EACb,IAAI,EACJ,UAAU,EACV,UAAU,EACV,MAAM,EACN,IAAI,EACJ,MAAM,EACN,kCAAkC,EAClC,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO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EAAE,wCAAwC,EAAE,MAAM,6CAA6C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentScheduled.d.ts","sourceRoot":"","sources":["../../../../src/instrumentations/worker/instrumentScheduled.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,GAAG,IAAI,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAajF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"instrumentScheduled.d.ts","sourceRoot":"","sources":["../../../../src/instrumentations/worker/instrumentScheduled.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,GAAG,IAAI,aAAa,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAajF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAqFtD;;GAEG;AACH,wBAAgB,kCAAkC,CAAC,CAAC,SAAS,kBAAkB,EAC7E,OAAO,EAAE,CAAC,EACV,eAAe,EAAE,CAAC,GAAG,EAAE,OAAO,aAAa,KAAK,iBAAiB,GAAG,SAAS,GAC5E,IAAI,CAoBN;AAED;;GAEG;AACH,wBAAgB,mCAAmC,CAAC,CAAC,SAAS,gBAAgB,EAC5E,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,gBAAgB,GACxB,IAAI,CAaN"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { MonitorConfig } from '@sentry/core';
|
|
2
|
+
/**
|
|
3
|
+
* The monitor slug and settings for a Cron Trigger, see `cronTriggersIntegration`.
|
|
4
|
+
*/
|
|
5
|
+
export type CronTriggerMonitorSettings = {
|
|
6
|
+
monitorSlug: string;
|
|
7
|
+
} & Omit<MonitorConfig, 'schedule' | 'timezone'>;
|
|
8
|
+
export interface CronTriggersOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Chooses the monitor slug for a cron expression. It can also return an object with the `monitorSlug`
|
|
11
|
+
* and other monitor settings, such as `checkinMargin` or `maxRuntime`. Returning `undefined`
|
|
12
|
+
* sends no check-ins for that trigger, and so does a function that throws.
|
|
13
|
+
*/
|
|
14
|
+
monitorSlug?: (cron: string) => string | CronTriggerMonitorSettings | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** @internal Used by the scheduled handler instrumentation. */
|
|
17
|
+
export interface CronTriggersIntegration {
|
|
18
|
+
name: string;
|
|
19
|
+
startCheckIn(cron: string): ((status: 'ok' | 'error') => void) | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sends cron check-ins for every Cron Trigger run of the `scheduled` handler, with the trigger's
|
|
23
|
+
* schedule, so Sentry creates the monitor on the first run.
|
|
24
|
+
*
|
|
25
|
+
* Cron Triggers have no names, so map each cron expression to a slug. Without `monitorSlug`, the slug is
|
|
26
|
+
* derived from the expression (`30 9 * * MON-FRI` becomes `cron-30-9-x-x-montofri`) and changes with it.
|
|
27
|
+
* Workers that send to the same project get the same slug for the same expression, so they share a monitor.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // src/monitorSlugs.ts
|
|
32
|
+
* export const monitorSlugs: Record<string, string> = {
|
|
33
|
+
* '30 9 * * MON-FRI': 'daily-report',
|
|
34
|
+
* };
|
|
35
|
+
*
|
|
36
|
+
* // src/instrument.server.ts
|
|
37
|
+
* import { cronTriggersIntegration, defineCloudflareOptions } from '@sentry/cloudflare';
|
|
38
|
+
* import { monitorSlugs } from './monitorSlugs';
|
|
39
|
+
*
|
|
40
|
+
* export default defineCloudflareOptions((env) => ({
|
|
41
|
+
* dsn: env.SENTRY_DSN,
|
|
42
|
+
* integrations: [cronTriggersIntegration({ monitorSlug: (cron) => monitorSlugs[cron] })],
|
|
43
|
+
* }));
|
|
44
|
+
*
|
|
45
|
+
* // src/index.ts
|
|
46
|
+
* import { monitorSlugs } from './monitorSlugs';
|
|
47
|
+
*
|
|
48
|
+
* export default {
|
|
49
|
+
* async scheduled(controller, env) {
|
|
50
|
+
* switch (monitorSlugs[controller.cron]) {
|
|
51
|
+
* case 'daily-report':
|
|
52
|
+
* // ...
|
|
53
|
+
* break;
|
|
54
|
+
* }
|
|
55
|
+
* },
|
|
56
|
+
* };
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const cronTriggersIntegration: (options?: CronTriggersOptions | undefined) => import("@sentry/core").Integration & {
|
|
60
|
+
name: string;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=cronTriggers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronTriggers.d.ts","sourceRoot":"","sources":["../../../src/integrations/cronTriggers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,cAAc,CAAC;AAMjE;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,UAAU,CAAC,CAAC;AAEhH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,0BAA0B,GAAG,SAAS,CAAC;CACjF;AAED,+DAA+D;AAC/D,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,GAAG,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAC5E;AAoID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,uBAAuB;;CAA8C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/cloudflare",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.0",
|
|
4
4
|
"description": "Official Sentry SDK for Cloudflare Workers and Pages",
|
|
5
5
|
"repository": "git://github.com/getsentry/sentry-javascript.git",
|
|
6
6
|
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@opentelemetry/api": "^1.9.1",
|
|
56
|
-
"@sentry/conventions": "^0.
|
|
57
|
-
"@sentry/core": "11.
|
|
58
|
-
"@sentry/opentelemetry": "11.
|
|
59
|
-
"@sentry/server-utils": "11.
|
|
56
|
+
"@sentry/conventions": "^0.27.0",
|
|
57
|
+
"@sentry/core": "11.7.0",
|
|
58
|
+
"@sentry/opentelemetry": "11.7.0",
|
|
59
|
+
"@sentry/server-utils": "11.7.0",
|
|
60
60
|
"magic-string": "~0.30.21"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|