quickStartEntries.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. }