Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic instrumentation of Deno crons #9700

Closed
AbhiPrasad opened this issue Nov 29, 2023 · 3 comments · Fixed by #9808
Closed

Add automatic instrumentation of Deno crons #9700

AbhiPrasad opened this issue Nov 29, 2023 · 3 comments · Fixed by #9808

Comments

@AbhiPrasad
Copy link
Member

AbhiPrasad commented Nov 29, 2023

Problem Statement

https://deno.com/blog/cron

https://docs.sentry.io/platforms/node/crons/

Solution Brainstorm

Add instrumentation around Deno.cron

@AbhiPrasad
Copy link
Member Author

Here's a super WIP impl I made - have to double check if we can Proxy the Deno.cron global like this.

/* eslint-disable deprecation/deprecation */
import { withMonitor } from '@sentry/core';
import type { Integration } from '@sentry/types';

/** Creates cron . */
export class DenoCron implements Integration {
  /** @inheritDoc */
  public static id = 'DenoCron';

  /** @inheritDoc */
  public name: string = DenoCron.id;

  /** @inheritDoc */
  public setupOnce(): void {
    if ('cron' in Deno && typeof Deno.cron === 'function') {
      Deno.cron = new Proxy(Deno.cron, {
        apply: (cronTarget, cronThisArg, cronArgs: Parameters<typeof Deno.cron>) => {
          const [name, schedule] = cronArgs;
          withMonitor(name, () => cronTarget.apply(cronThisArg, cronArgs), {
            // (minutes) so 12 hours - just a very high arbitrary number since we don't know the actual duration of the users cron job
            maxRuntime: 60 * 12,
            schedule: {
              type: 'crontab',
              value: schedule,
            },
          });
        },
      });
    }
  }
}

@AbhiPrasad
Copy link
Member Author

https://discord.com/channels/684898665143206084/1179489397947760661/1179500002951831703

The API is unstable, so it could change in the future. I don't expect major changes though, other than adding more fields to options (which is non-breaking).

@AbhiPrasad
Copy link
Member Author

docs: getsentry/sentry-docs#8733

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants