12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import { withMonitor } from '@sentry/core';
- import { replaceCronNames } from './common.js';
- function instrumentNodeSchedule(lib) {
- return new Proxy(lib, {
- get(target, prop) {
- if (prop === 'scheduleJob') {
-
- return new Proxy(target.scheduleJob, {
- apply(target, thisArg, argArray) {
- const [nameOrExpression, expressionOrCallback] = argArray;
- if (typeof nameOrExpression !== 'string' || typeof expressionOrCallback !== 'string') {
- throw new Error(
- "Automatic instrumentation of 'node-schedule' requires the first parameter of 'scheduleJob' to be a job name string and the second parameter to be a crontab string",
- );
- }
- const monitorSlug = nameOrExpression;
- const expression = expressionOrCallback;
- return withMonitor(
- monitorSlug,
- () => {
- return target.apply(thisArg, argArray);
- },
- {
- schedule: { type: 'crontab', value: replaceCronNames(expression) },
- },
- );
- },
- });
- }
- return target[prop];
- },
- });
- }
- export { instrumentNodeSchedule };
|