cloudflare-pages.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  9. import {
  10. getCrashReportJavaScriptInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import {t, tct} from 'sentry/locale';
  15. import {getInstallConfig} from 'sentry/utils/gettingStartedDocs/node';
  16. type Params = DocsParams;
  17. const getSdkConfigureSnippetToml = () => `
  18. compatibility_flags = ["nodejs_compat"]
  19. # compatibility_flags = ["nodejs_als"]
  20. `;
  21. const getSdkConfigureSnippetJson = () => `
  22. {
  23. "compatibility_flags": [
  24. "nodejs_compat"
  25. ],
  26. "compatibility_date": "2024-09-23"
  27. }`;
  28. const getSdkSetupSnippet = (params: Params) => `
  29. import * as Sentry from "@sentry/cloudflare";
  30. export const onRequest = [
  31. // Make sure Sentry is the first middleware
  32. Sentry.sentryPagesPlugin((context) => ({
  33. dsn: "${params.dsn.public}",
  34. // Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
  35. // Learn more at
  36. // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
  37. tracesSampleRate: 1.0,
  38. })),
  39. // Add more middlewares here
  40. ];`;
  41. const getVerifySnippet = () => `
  42. setTimeout(() => {
  43. throw new Error();
  44. });`;
  45. const onboarding: OnboardingConfig = {
  46. introduction: () =>
  47. t(
  48. 'In this quick guide you’ll set up and configure the Sentry Cloudflare SDK for the use in your Cloudflare Pages application.'
  49. ),
  50. install: params => [
  51. {
  52. type: StepType.INSTALL,
  53. description: t('Add the Sentry Cloudflare SDK as a dependency:'),
  54. configurations: getInstallConfig(params, {
  55. basePackage: '@sentry/cloudflare',
  56. }),
  57. },
  58. ],
  59. configure: params => [
  60. {
  61. type: StepType.CONFIGURE,
  62. description: t(
  63. "Configuration should happen as early as possible in your application's lifecycle."
  64. ),
  65. configurations: [
  66. {
  67. description: tct(
  68. "To use the SDK, you'll need to set either the [code:nodejs_compat] or [code:nodejs_als] compatibility flags in your [code:wrangler.toml]. This is because the SDK needs access to the [code:AsyncLocalStorage] API to work correctly.",
  69. {
  70. code: <code />,
  71. }
  72. ),
  73. code: [
  74. {
  75. label: 'JSON',
  76. value: 'json',
  77. language: 'json',
  78. filename: 'wrangler.json',
  79. code: getSdkConfigureSnippetJson(),
  80. },
  81. {
  82. label: 'Toml',
  83. value: 'toml',
  84. language: 'toml',
  85. filename: 'wrangler.toml',
  86. code: getSdkConfigureSnippetToml(),
  87. },
  88. ],
  89. },
  90. {
  91. description: tct(
  92. 'Add the [code:sentryPagesPlugin] as [guideLink:middleware to your Cloudflare Pages application]. We recommend adding a [code:functions/_middleware.js] for the middleware setup so that Sentry is initialized for your entire app.',
  93. {
  94. code: <code />,
  95. guideLink: (
  96. <ExternalLink href="https://developers.cloudflare.com/pages/functions/middleware/" />
  97. ),
  98. }
  99. ),
  100. code: [
  101. {
  102. label: 'JavaScript',
  103. value: 'javascript',
  104. language: 'javascript',
  105. filename: 'functions/_middleware.js',
  106. code: getSdkSetupSnippet(params),
  107. },
  108. ],
  109. },
  110. ],
  111. },
  112. getUploadSourceMapsStep({
  113. guideLink:
  114. 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/sourcemaps/',
  115. ...params,
  116. }),
  117. ],
  118. verify: () => [
  119. {
  120. type: StepType.VERIFY,
  121. description: t(
  122. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  123. ),
  124. configurations: [
  125. {
  126. language: 'javascript',
  127. code: getVerifySnippet(),
  128. },
  129. ],
  130. },
  131. ],
  132. };
  133. const crashReportOnboarding: OnboardingConfig = {
  134. introduction: () => getCrashReportModalIntroduction(),
  135. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  136. configure: () => [
  137. {
  138. type: StepType.CONFIGURE,
  139. description: getCrashReportModalConfigDescription({
  140. link: 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/user-feedback/configuration/#crash-report-modal',
  141. }),
  142. },
  143. ],
  144. verify: () => [],
  145. nextSteps: () => [],
  146. };
  147. const docs: Docs = {
  148. onboarding,
  149. crashReportOnboarding,
  150. };
  151. export default docs;