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

feat(core): Add cron monitor wrapper helper #9395

Merged
merged 2 commits into from
Oct 27, 2023
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Oct 27, 2023

In #8039 we added functionality for Sentry.captureCheckIn as part of Sentry's cron monitoring product.

This PR adds Sentry.withMonitor, a wrapping function similar to Sentry.startSpan that wraps a callback with a cron monitor. Under the hood it uses Sentry.captureCheckIn, but having this as a callback means that users don't have to think about passing checkInId around.

import * as Sentry from '@sentry/node';

// with monitor will send checkin when callback is started/finished
// works with async and sync callbacks.
const result = Sentry.withMonitor(
  'dailyEmail',
  () => {
    // withCheckIn return value is same return value here
    return sendEmail();
  },
  {
    schedule: {
      type: 'crontab',
      value: '0 * * * *',
    },
    // 🇨🇦🫡
    timezone: 'Canada/Eastern',
  },
);

@AbhiPrasad AbhiPrasad self-assigned this Oct 27, 2023
@AbhiPrasad AbhiPrasad requested review from a team, mydea, lforst and gaprl and removed request for a team October 27, 2023 13:40
Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some sort of test would be cool!

@AbhiPrasad
Copy link
Member Author

Based on some feedback in slack I renamed this to withMonitor. This all matches what the Python SDK does with a wrapping API.

I will add some tests!

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) October 27, 2023 14:22
@AbhiPrasad AbhiPrasad merged commit 697f406 into develop Oct 27, 2023
87 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-add-cron-wrapper branch October 27, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants