quickStartEntries.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. import {Fragment} from 'react';
  2. import merge from 'lodash/merge';
  3. import {CodeSnippet} from 'sentry/components/codeSnippet';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {t, tct} from 'sentry/locale';
  6. export interface QuickStartProps {
  7. dsnKey?: string;
  8. orgId?: string;
  9. orgSlug?: string;
  10. projectId?: string;
  11. publicKey?: string;
  12. slug?: string;
  13. }
  14. const VALUE_DEFAULTS = {
  15. dsnKey: '<my-dsn-key>',
  16. orgId: '<my-organziation-id>',
  17. orgSlug: '<my-organization-slug>',
  18. projectId: '<my-project-id>',
  19. publicKey: '<my-dsn-public-key>',
  20. slug: '<my-monitor-slug>',
  21. };
  22. function withDefaultProps(props: QuickStartProps): Required<QuickStartProps> {
  23. return merge(VALUE_DEFAULTS, props);
  24. }
  25. export function PythonCronQuickStart(props: QuickStartProps) {
  26. const {slug} = withDefaultProps(props);
  27. const code = `import sentry_sdk
  28. from sentry_sdk.crons import monitor
  29. # Add this decorator to instrument your python function
  30. @monitor(monitor_slug='${slug}')
  31. def tell_the_world(msg):
  32. print(msg)`;
  33. return (
  34. <Fragment>
  35. <div>
  36. {tct(
  37. '[installLink:Install and configure] the Sentry Python SDK (min v1.17.0), then instrument your monitor:',
  38. {
  39. installLink: <ExternalLink href="https://docs.sentry.io/platforms/python/" />,
  40. }
  41. )}
  42. </div>
  43. <CodeSnippet language="python">{code}</CodeSnippet>
  44. </Fragment>
  45. );
  46. }
  47. export function PythonCeleryCronQuickStart(props: QuickStartProps) {
  48. const {slug, dsnKey} = withDefaultProps(props);
  49. const setupCode = `import sentry_sdk
  50. from sentry_sdk.crons import monitor
  51. from sentry_sdk.integrations.celery import CeleryIntegration
  52. # @signals.celeryd_init.connect
  53. @signals.beat_init.connect
  54. def init_sentry(**kwargs):
  55. sentry_sdk.init(
  56. dsn='${dsnKey}',
  57. integrations=[CeleryIntegration()],
  58. )
  59. `;
  60. const linkTaskCode = `@app.task
  61. @monitor(monitor_slug='${slug}')
  62. def tell_the_world(msg):
  63. print(msg)
  64. `;
  65. return (
  66. <Fragment>
  67. <div>
  68. {tct(
  69. '[installLink:Install and configure] the Sentry Python SDK (min v1.17.0), then initialize Sentry either in [celerydInit:celeryd_init] or [beatInit:beat_init] signal:',
  70. {
  71. celerydInit: <code />,
  72. beatInit: <code />,
  73. installLink: (
  74. <ExternalLink href="https://docs.sentry.io/platforms/python/guides/celery/" />
  75. ),
  76. }
  77. )}
  78. </div>
  79. <CodeSnippet language="python">{setupCode}</CodeSnippet>
  80. <div>{t('Link your Celery task to your Monitor:')}</div>
  81. <CodeSnippet language="python">{linkTaskCode}</CodeSnippet>
  82. </Fragment>
  83. );
  84. }
  85. export function CLICronQuickStart(props: QuickStartProps) {
  86. const {slug, dsnKey} = withDefaultProps(props);
  87. const script = `# Example for a Python script:
  88. export SENTRY_DSN=${dsnKey}
  89. sentry-cli monitors run ${slug} -- python path/to/file`;
  90. return (
  91. <Fragment>
  92. <div>
  93. {tct(
  94. 'Make sure to [installLink:install the Sentry CLI] (min v2.16.1), then instrument your monitor:',
  95. {
  96. installLink: (
  97. <ExternalLink href="https://docs.sentry.io/product/cli/installation/" />
  98. ),
  99. }
  100. )}
  101. </div>
  102. <CodeSnippet language="bash">{script}</CodeSnippet>
  103. </Fragment>
  104. );
  105. }
  106. export function CurlCronQuickStart(props: QuickStartProps) {
  107. const {projectId, orgId, slug, publicKey} = withDefaultProps(props);
  108. const checkInSuccessCode = `SENTRY_INGEST="https://o${orgId}.ingest.sentry.io"
  109. SENTRY_CRONS="\${SENTRY_INGEST}/api/${projectId}/cron/${slug}/${publicKey}/"
  110. # 🟑 Notify Sentry your job is running:
  111. curl "\${SENTRY_CRONS}?status=in_progress"
  112. # Execute your scheduled task here...
  113. # 🟒 Notify Sentry your job has completed successfully:
  114. curl "\${SENTRY_CRONS}?status=ok"`;
  115. const checkInFailCode = `# πŸ”΄ Notify Sentry your job has failed:
  116. curl "\${SENTRY_CRONS}?status=error"`;
  117. return (
  118. <Fragment>
  119. <CodeSnippet language="bash">{checkInSuccessCode}</CodeSnippet>
  120. <div>{t('To notify Sentry if your job execution fails')}</div>
  121. <CodeSnippet language="bash">{checkInFailCode}</CodeSnippet>
  122. </Fragment>
  123. );
  124. }
  125. export function PHPCronQuickStart(props: QuickStartProps) {
  126. const {slug} = withDefaultProps(props);
  127. const checkInSuccessCode = `// 🟑 Notify Sentry your job is running:
  128. $event = Event::createCheckIn();
  129. $checkIn = new CheckIn(
  130. monitorSlug: '${slug}',
  131. status: CheckInStatus::inProgress(),
  132. );
  133. $event->setCheckIn($checkIn);
  134. SentrySdk::getCurrentHub()->captureEvent($event);
  135. // Execute your scheduled task here...
  136. // 🟒 Notify Sentry your job has completed successfully:
  137. $event = Event::createCheckIn();
  138. $event->setCheckIn(new CheckIn(
  139. id: $checkIn->getId(),
  140. monitorSlug: '${slug}',
  141. status: CheckInStatus::ok(),
  142. ));
  143. SentrySdk::getCurrentHub()->captureEvent($event);`;
  144. const checkInFailCode = `// πŸ”΄ Notify Sentry your job has failed:
  145. $event = Event::createCheckIn();
  146. $event->setCheckIn(new CheckIn(
  147. id: $checkIn->getId(),
  148. monitorSlug: '${slug}',
  149. status: CheckInStatus::error(),
  150. ));
  151. SentrySdk::getCurrentHub()->captureEvent($event);`;
  152. return (
  153. <Fragment>
  154. <div>
  155. {tct(
  156. '[installLink:Install and configure] the Sentry PHP SDK (min v3.16.0), then instrument your monitor:',
  157. {
  158. installLink: <ExternalLink href="https://docs.sentry.io/platforms/php/" />,
  159. }
  160. )}
  161. </div>
  162. <CodeSnippet language="php">{checkInSuccessCode}</CodeSnippet>
  163. <div>{t('To notify Sentry if your job execution fails')}</div>
  164. <CodeSnippet language="php">{checkInFailCode}</CodeSnippet>
  165. </Fragment>
  166. );
  167. }
  168. export function PHPLaravelCronQuickStart(props: QuickStartProps) {
  169. const {slug} = withDefaultProps(props);
  170. const code = `protected function schedule(Schedule $schedule)
  171. {
  172. $schedule->command('emails:send')
  173. ->everyHour()
  174. ->sentryMonitor('${slug}'); // add this line
  175. }`;
  176. return (
  177. <Fragment>
  178. <div>
  179. {tct(
  180. '[installLink:Install and configure] the Sentry PHP Laravel SDK (min v3.3.1), then add the [sentryMonitor:sentryMonitor()] call to your scheduled tasks defined in your [kernel:app/Console/Kernel.php] file:',
  181. {
  182. sentryMonitor: <code />,
  183. kernel: <code />,
  184. installLink: (
  185. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/" />
  186. ),
  187. }
  188. )}
  189. </div>
  190. <CodeSnippet language="php">{code}</CodeSnippet>
  191. </Fragment>
  192. );
  193. }
  194. export function NodeJSCronQuickStart(props: QuickStartProps) {
  195. const {slug} = withDefaultProps(props);
  196. const checkInSuccessCode = `// 🟑 Notify Sentry your job is running:
  197. const checkInId = Sentry.captureCheckIn({
  198. monitorSlug: "${slug}",
  199. status: "in_progress",
  200. });
  201. // Execute your scheduled task here...
  202. // 🟒 Notify Sentry your job has completed successfully:
  203. Sentry.captureCheckIn({
  204. checkInId,
  205. monitorSlug: "${slug}",
  206. status: "ok",
  207. });`;
  208. const checkInFailCode = `// πŸ”΄ Notify Sentry your job has failed:
  209. Sentry.captureCheckIn({
  210. checkInId,
  211. monitorSlug: "${slug}",
  212. status: "error",
  213. });`;
  214. return (
  215. <Fragment>
  216. <div>
  217. {tct(
  218. '[installLink:Install and configure] the Sentry Node SDK (min v7.52), then instrument your monitor:',
  219. {
  220. installLink: <ExternalLink href="https://docs.sentry.io/platforms/node/" />,
  221. }
  222. )}
  223. </div>
  224. <CodeSnippet language="javascript">{checkInSuccessCode}</CodeSnippet>
  225. <div>{t('To notify Sentry if your job execution fails')}</div>
  226. <CodeSnippet language="javascript">{checkInFailCode}</CodeSnippet>
  227. </Fragment>
  228. );
  229. }
  230. export function GoCronQuickStart(props: QuickStartProps) {
  231. const {slug} = withDefaultProps(props);
  232. const checkInSuccessCode = `// 🟑 Notify Sentry your job is running:
  233. checkinId := sentry.CaptureCheckIn(
  234. &sentry.CheckIn{
  235. MonitorSlug: "${slug}",
  236. Status: sentry.CheckInStatusInProgress,
  237. },
  238. nil,
  239. )
  240. // Execute your scheduled task here...
  241. // 🟒 Notify Sentry your job has completed successfully:
  242. sentry.CaptureCheckIn(
  243. &sentry.CheckIn{
  244. ID: *checkinId,
  245. MonitorSlug: "${slug}",
  246. Status: sentry.CheckInStatusOK,
  247. },
  248. nil,
  249. )`;
  250. const checkInFailCode = `// πŸ”΄ Notify Sentry your job has failed:
  251. sentry.CaptureCheckIn(
  252. &sentry.CheckIn{
  253. ID: *checkinId,
  254. MonitorSlug: "${slug}",
  255. Status: sentry.CheckInStatusError,
  256. },
  257. nil,
  258. )`;
  259. return (
  260. <Fragment>
  261. <div>
  262. {tct(
  263. '[installLink:Install and configure] the Sentry Go SDK (min v0.23.0), then instrument your monitor:',
  264. {
  265. installLink: <ExternalLink href="https://docs.sentry.io/platforms/go/" />,
  266. }
  267. )}
  268. </div>
  269. <CodeSnippet language="go">{checkInSuccessCode}</CodeSnippet>
  270. <div>{t('To notify Sentry if your job execution fails')}</div>
  271. <CodeSnippet language="go">{checkInFailCode}</CodeSnippet>
  272. </Fragment>
  273. );
  274. }
  275. export function JavaCronQuickStart(props: QuickStartProps) {
  276. const {slug} = withDefaultProps(props);
  277. const checkInSuccessCode = `import io.sentry.CheckIn;
  278. import io.sentry.CheckInStatus;
  279. import io.sentry.Sentry;
  280. import io.sentry.protocol.SentryId;
  281. // 🟑 Notify Sentry your job is running:
  282. SentryId checkInId = Sentry.captureCheckIn(
  283. new CheckIn(
  284. "${slug}",
  285. CheckInStatus.IN_PROGRESS
  286. )
  287. );
  288. // Execute your scheduled task here...
  289. // 🟒 Notify Sentry your job has completed successfully:
  290. Sentry.captureCheckIn(
  291. new CheckIn(
  292. checkInId,
  293. "${slug}",
  294. CheckInStatus.OK
  295. )
  296. );`;
  297. const checkInFailCode = `// πŸ”΄ Notify Sentry your job has failed:
  298. Sentry.captureCheckIn(
  299. new CheckIn(
  300. checkInId,
  301. "${slug}",
  302. CheckInStatus.ERROR
  303. )
  304. );`;
  305. return (
  306. <Fragment>
  307. <div>
  308. {tct(
  309. '[installLink:Install and configure] the Sentry Java SDK (min v6.30.0), then instrument your monitor:',
  310. {
  311. installLink: <ExternalLink href="https://docs.sentry.io/platforms/java/" />,
  312. }
  313. )}
  314. </div>
  315. <CodeSnippet language="java">{checkInSuccessCode}</CodeSnippet>
  316. <div>{t('To notify Sentry if your job execution fails')}</div>
  317. <CodeSnippet language="java">{checkInFailCode}</CodeSnippet>
  318. </Fragment>
  319. );
  320. }
  321. export function JavaSpringBootCronQuickStart(props: QuickStartProps) {
  322. const {slug} = withDefaultProps(props);
  323. const code = `import io.sentry.spring.jakarta.checkin.SentryCheckIn;
  324. @Component
  325. public class CustomJob {
  326. @Scheduled(fixedRate = 3 * 60 * 1000L)
  327. @SentryCheckIn("${slug}") // πŸ‘ˆ
  328. void execute() throws InterruptedException {
  329. // your task code
  330. }
  331. }`;
  332. return (
  333. <Fragment>
  334. <div>
  335. {tct(
  336. '[installLink:Install and configure] the Sentry Spring Boot SDK (min v6.30.0), then instrument your monitor:',
  337. {
  338. installLink: (
  339. <ExternalLink href="https://docs.sentry.io/platforms/java/guides/spring-boot/" />
  340. ),
  341. }
  342. )}
  343. </div>
  344. <CodeSnippet language="java">{code}</CodeSnippet>
  345. </Fragment>
  346. );
  347. }
  348. export function JavaQuartzCronQuickStart(props: QuickStartProps) {
  349. const {slug} = withDefaultProps(props);
  350. const code = `import io.sentry.quartz.SentryJobListener;
  351. // you can set the monitor slug on the job detail
  352. JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
  353. jobDetailFactory.setJobDataAsMap(Collections.singletonMap(SentryJobListener.SENTRY_SLUG_KEY, "${slug}"));
  354. // you can also set the monitor slug on the trigger
  355. SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
  356. trigger.setJobDataAsMap(Collections.singletonMap(SENTRY_SLUG_KEY, "${slug}"));`;
  357. return (
  358. <Fragment>
  359. <div>
  360. {tct(
  361. '[installLink:Install and configure] the Sentry Java SDK (min v6.30.0), make sure `SentryJobListener` is [configureLink:configured], then instrument your monitor:',
  362. {
  363. installLink: <ExternalLink href="https://docs.sentry.io/platforms/java/" />,
  364. configureLink: (
  365. <ExternalLink href="https://docs.sentry.io/platforms/java/configuration/integrations/quartz/" />
  366. ),
  367. }
  368. )}
  369. </div>
  370. <CodeSnippet language="java">{code}</CodeSnippet>
  371. </Fragment>
  372. );
  373. }
  374. export function CeleryBeatAutoDiscovery(props: QuickStartProps) {
  375. const {dsnKey} = props;
  376. const code = `# tasks.py
  377. from celery import signals
  378. import sentry_sdk
  379. from sentry_sdk.integrations.celery import CeleryIntegration
  380. @signals.celeryd_init.connect
  381. def init_sentry(**kwargs):
  382. sentry_sdk.init(
  383. dsn='${dsnKey ?? '<PROJECT DSN>'}',
  384. integrations=[CeleryIntegration(monitor_beat_tasks=True)], # πŸ‘ˆ
  385. environment="local.dev.grace",
  386. release="v1.0",
  387. )
  388. `;
  389. return (
  390. <Fragment>
  391. <div>
  392. {tct(
  393. 'Use the [additionalDocs: Celery integration] to monitor your Celery periodic tasks. Initialize Sentry in the celeryd_init or beat_init signal.',
  394. {
  395. additionalDocs: (
  396. <ExternalLink href="https://docs.sentry.io/platforms/python/guides/celery/crons/#celery-beat-auto-discovery" />
  397. ),
  398. }
  399. )}
  400. </div>
  401. <div>{t('Make sure to set monitor_beat_tasks=True in CeleryIntegration:')}</div>
  402. <CodeSnippet language="python">{code}</CodeSnippet>
  403. </Fragment>
  404. );
  405. }
  406. export function PHPUpsertPlatformGuide() {
  407. const scheduleCode = `// Create a crontab schedule object (every 10 minutes)
  408. $monitorSchedule = \Sentry\MonitorSchedule::crontab('*/10 * * * *');
  409. // Or create an interval schedule object (every 10 minutes)
  410. $monitorSchedule = \Sentry\MonitorSchedule::interval(10, MonitorScheduleUnit::minute());`;
  411. const upsertCode = `// Create a config object
  412. $monitorConfig = new \Sentry\MonitorConfig(
  413. $monitorSchedule,
  414. checkinMargin: 5, // Optional check-in margin in minutes
  415. maxRuntime: 15, // Optional max runtime in minutes
  416. timezone: 'Europe/Vienna', // Optional timezone
  417. );
  418. // 🟑 Notify Sentry your job is running:
  419. $checkInId = \Sentry\captureCheckIn(
  420. slug: '<monitor-slug>',
  421. status: CheckInStatus::inProgress(),
  422. monitorConfig: $monitorConfig,
  423. );
  424. // Execute your scheduled task here...
  425. // 🟒 Notify Sentry your job has completed successfully:
  426. \Sentry\captureCheckIn(
  427. slug: '<monitor-slug>',
  428. status: CheckInStatus::inProgress(),
  429. checkInId: $checkInId,
  430. );`;
  431. return (
  432. <Fragment>
  433. <div>
  434. {tct(
  435. 'You can use the [additionalDocs: PHP SDK] to create and update your Monitors programmatically with code rather than creating them manually.',
  436. {
  437. additionalDocs: (
  438. <ExternalLink href="https://docs.sentry.io/platforms/php/crons/#upserting-cron-monitors" />
  439. ),
  440. }
  441. )}
  442. </div>
  443. <CodeSnippet language="php">{scheduleCode}</CodeSnippet>
  444. <CodeSnippet language="php">{upsertCode}</CodeSnippet>
  445. </Fragment>
  446. );
  447. }
  448. export function LaravelUpsertPlatformGuide() {
  449. const basicConfigCode = `protected function schedule(Schedule $schedule)
  450. {
  451. $schedule->command('emails:send')
  452. ->everyHour()
  453. ->sentryMonitor(); // add this line
  454. }`;
  455. const advancedConfigCode = `protected function schedule(Schedule $schedule)
  456. {
  457. $schedule->command('emails:send')
  458. ->everyHour()
  459. ->sentryMonitor(
  460. // Specify the slug of the job monitor in case of duplicate commands or if the monitor was created in the UI
  461. monitorSlug: null,
  462. // Check-in margin in minutes
  463. checkInMargin: 5,
  464. // Max runtime in minutes
  465. maxRuntime: 15,
  466. // In case you want to configure the job monitor exclusively in the UI, you can turn off sending the monitor config with the check-in.
  467. // Passing a monitor-slug is required in this case.
  468. updateMonitorConfig: false,
  469. )
  470. }`;
  471. return (
  472. <Fragment>
  473. <div>
  474. {tct('Use the [additionalDocs: Laravel SDK] to monitor your scheduled task.', {
  475. additionalDocs: (
  476. <ExternalLink href="https://docs.sentry.io/platforms/php/guides/laravel/crons/#job-monitoring" />
  477. ),
  478. })}
  479. </div>
  480. <div>
  481. {t(
  482. 'To set up, add the "sentryMonitor()" macro to your scheduled tasks defined in your "app/Console/Kernel.php" file:'
  483. )}
  484. </div>
  485. <CodeSnippet language="php">{basicConfigCode}</CodeSnippet>
  486. <div>
  487. {t(
  488. 'By default, the Laravel SDK will infer various parameters of your scheduled task. For greater control, we expose some optional parameters on the sentryMonitor() macro.'
  489. )}
  490. </div>
  491. <CodeSnippet language="php">{advancedConfigCode}</CodeSnippet>
  492. </Fragment>
  493. );
  494. }
  495. export function NodeJsUpsertPlatformGuide() {
  496. const upsertCode = `const checkInId = Sentry.captureCheckIn(
  497. {
  498. monitorSlug: '<monitor-slug>',
  499. status: 'in_progress',
  500. },
  501. {
  502. schedule: { // Specify your schedule options here
  503. type: 'crontab',
  504. value: '* * * * *',
  505. },
  506. checkinMargin: 1,
  507. maxRuntime: 1,
  508. timezone: 'America/Los_Angeles',
  509. });
  510. Sentry.captureCheckIn({
  511. checkInId,
  512. monitorSlug: '<monitor-slug>',
  513. status: 'ok',
  514. });
  515. `;
  516. return (
  517. <Fragment>
  518. <div>
  519. {tct(
  520. 'Use the [additionalDocs:Node SDK] to create and update your Monitors programmatically with code rather than creating them manually.',
  521. {
  522. additionalDocs: (
  523. <ExternalLink href="https://docs.sentry.io/platforms/node/crons/" />
  524. ),
  525. }
  526. )}
  527. </div>
  528. <CodeSnippet language="javascript">{upsertCode}</CodeSnippet>
  529. </Fragment>
  530. );
  531. }
  532. export function GoUpsertPlatformGuide() {
  533. const scheduleCode = `// Create a crontab schedule object (every 10 minutes)
  534. monitorSchedule := sentry.CrontabSchedule("*/10 * * * *")
  535. // Or create an interval schedule object (every 10 minutes)
  536. monitorSchedule := sentry.IntervalSchedule(10, sentry.MonitorScheduleUnitMinute)
  537. `;
  538. const upsertCode = `// Create a monitor config object
  539. monitorConfig := &sentry.MonitorConfig{
  540. Schedule: monitorSchedule,
  541. MaxRuntime: 2,
  542. CheckInMargin: 1,
  543. }
  544. // 🟑 Notify Sentry your job is running:
  545. checkinId := sentry.CaptureCheckIn(
  546. &sentry.CheckIn{
  547. MonitorSlug: "<monitor-slug>",
  548. Status: sentry.CheckInStatusInProgress,
  549. },
  550. monitorConfig,
  551. )
  552. // Execute your scheduled task here...
  553. // 🟒 Notify Sentry your job has completed successfully:
  554. sentry.CaptureCheckIn(
  555. &sentry.CheckIn{
  556. MonitorSlug: "<monitor-slug>",
  557. Status: sentry.CheckInStatusOK,
  558. },
  559. monitorConfig,
  560. )`;
  561. return (
  562. <Fragment>
  563. <div>
  564. {tct(
  565. 'You can use the [additionalDocs: Go SDK] to create and update your Monitors programmatically with code rather than creating them manually.',
  566. {
  567. additionalDocs: (
  568. <ExternalLink href="https://docs.sentry.io/platforms/go/crons/#upserting-cron-monitors" />
  569. ),
  570. }
  571. )}
  572. </div>
  573. <CodeSnippet language="go">{scheduleCode}</CodeSnippet>
  574. <CodeSnippet language="go">{upsertCode}</CodeSnippet>
  575. </Fragment>
  576. );
  577. }
  578. export function JavaUpsertPlatformGuide() {
  579. const scheduleCode = `import io.sentry.MonitorSchedule;
  580. import io.sentry.MonitorScheduleUnit;
  581. // Create a crontab schedule object (every 10 minutes)
  582. MonitorSchedule monitorSchedule = MonitorSchedule.crontab("*/10 * * * *");
  583. // Or create an interval schedule object (every 10 minutes)
  584. MonitorSchedule monitorSchedule = MonitorSchedule.interval(10, MonitorScheduleUnit.MINUTE);`;
  585. const upsertCode = `import io.sentry.MonitorConfig;
  586. // Create a config object
  587. MonitorConfig monitorConfig = new MonitorConfig(monitorSchedule);
  588. monitorConfig.setTimezone("Europe/Vienna"); // Optional timezone
  589. monitorConfig.setCheckinMargin(5L); // Optional check-in margin in minutes
  590. monitorConfig.setMaxRuntime(15L); // Optional max runtime in minutes
  591. // 🟑 Notify Sentry your job is running:
  592. CheckIn checkIn = new CheckIn(
  593. "<monitor-slug>",
  594. CheckInStatus.IN_PROGRESS
  595. );
  596. checkIn.setMonitorConfig(monitorConfig);
  597. SentryId checkInId = Sentry.captureCheckIn(checkIn);
  598. // Execute your scheduled task here...
  599. // 🟒 Notify Sentry your job has completed successfully:
  600. Sentry.captureCheckIn(
  601. new CheckIn(
  602. checkInId,
  603. "<monitor-slug>",
  604. CheckInStatus.OK
  605. )
  606. );`;
  607. return (
  608. <Fragment>
  609. <div>
  610. {tct(
  611. 'You can use the [additionalDocs: Java SDK] to create and update your Monitors programmatically with code rather than creating them manually.',
  612. {
  613. additionalDocs: (
  614. <ExternalLink href="https://docs.sentry.io/platforms/java/crons/#upserting-cron-monitors" />
  615. ),
  616. }
  617. )}
  618. </div>
  619. <CodeSnippet language="java">{scheduleCode}</CodeSnippet>
  620. <CodeSnippet language="java">{upsertCode}</CodeSnippet>
  621. </Fragment>
  622. );
  623. }