astro.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getReplayConfigureDescription,
  11. getReplaySDKSetupSnippet,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/utils';
  13. import {t, tct} from 'sentry/locale';
  14. type Params = DocsParams;
  15. const getSdkSetupSnippet = (params: Params) => `
  16. import { defineConfig } from "astro/config";
  17. import sentry from "@sentry/astro";
  18. export default defineConfig({
  19. integrations: [
  20. sentry({
  21. dsn: "${params.dsn}",${
  22. params.isPerformanceSelected
  23. ? ''
  24. : `
  25. tracesSampleRate: 0,`
  26. }${
  27. params.isReplaySelected
  28. ? ''
  29. : `
  30. replaysSessionSampleRate: 0,
  31. replaysOnErrorSampleRate: 0,`
  32. }
  33. sourceMapsUploadOptions: {
  34. project: "${params.projectSlug}",
  35. authToken: process.env.SENTRY_AUTH_TOKEN,
  36. },
  37. }),
  38. ],
  39. });
  40. `;
  41. const getVerifyAstroSnippet = () => `
  42. <!-- your-page.astro -->
  43. <button onclick="throw new Error('This is a test error')">
  44. Throw test error
  45. </button>
  46. `;
  47. const getInstallConfig = () => [
  48. {
  49. type: StepType.INSTALL,
  50. description: tct(
  51. 'Install the [sentryAstroPkg:@sentry/astro] package with the [astroCli:astro] CLI:',
  52. {
  53. sentryAstroPkg: <code />,
  54. astroCli: <code />,
  55. }
  56. ),
  57. configurations: [
  58. {
  59. language: 'bash',
  60. code: [
  61. {
  62. label: 'bash',
  63. value: 'bash',
  64. language: 'bash',
  65. code: `npx astro add @sentry/astro`,
  66. },
  67. ],
  68. },
  69. ],
  70. },
  71. ];
  72. const onboarding: OnboardingConfig = {
  73. introduction: () =>
  74. tct("Sentry's integration with [astroLink:Astro] supports Astro 3.0.0 and above.", {
  75. astroLink: <ExternalLink href="https://astro.build/" />,
  76. }),
  77. install: () => getInstallConfig(),
  78. configure: (params: Params) => [
  79. {
  80. type: StepType.CONFIGURE,
  81. description: tct(
  82. 'Open up your [astroConfig:astro.config.mjs] file and configure the DSN, and any other settings you need:',
  83. {
  84. astroConfig: <code />,
  85. }
  86. ),
  87. configurations: [
  88. {
  89. code: [
  90. {
  91. label: 'JavaScript',
  92. value: 'javascript',
  93. language: 'javascript',
  94. code: getSdkSetupSnippet(params),
  95. },
  96. ],
  97. },
  98. {
  99. description: tct(
  100. 'Add your Sentry auth token to the [authTokenEnvVar:SENTRY_AUTH_TOKEN] environment variable:',
  101. {
  102. authTokenEnvVar: <code />,
  103. }
  104. ),
  105. language: 'bash',
  106. code: [
  107. {
  108. value: 'bash',
  109. language: 'bash',
  110. label: 'bash',
  111. code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
  112. },
  113. ],
  114. },
  115. {
  116. description: tct(
  117. 'You can further customize your SDK by [manualSetupLink:manually inializing the SDK].',
  118. {
  119. manualSetupLink: (
  120. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/" />
  121. ),
  122. }
  123. ),
  124. },
  125. ],
  126. },
  127. ],
  128. verify: () => [
  129. {
  130. type: StepType.VERIFY,
  131. description: t(
  132. 'Then throw a test error anywhere in your app, so you can test that everything is working:'
  133. ),
  134. configurations: [
  135. {
  136. code: [
  137. {
  138. label: 'Astro',
  139. value: 'html',
  140. language: 'html',
  141. code: getVerifyAstroSnippet(),
  142. },
  143. ],
  144. },
  145. ],
  146. additionalInfo: (
  147. <Fragment>
  148. <p>
  149. {t(
  150. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  151. )}
  152. </p>
  153. <p>
  154. {t(
  155. "If you're an existing user and have disabled alerts, you won't receive this email."
  156. )}
  157. </p>
  158. </Fragment>
  159. ),
  160. },
  161. ],
  162. nextSteps: () => [
  163. {
  164. id: 'astro-manual-setup',
  165. name: t('Customize your SDK Setup'),
  166. description: t(
  167. 'Learn how to further configure and customize your Sentry Astro SDK setup.'
  168. ),
  169. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/',
  170. },
  171. {
  172. id: 'performance-monitoring',
  173. name: t('Performance Monitoring'),
  174. description: t(
  175. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  176. ),
  177. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/performance/',
  178. },
  179. {
  180. id: 'session-replay',
  181. name: t('Session Replay'),
  182. description: t(
  183. 'Get to the root cause of an error or latency issue faster by seeing all the technical details related to that issue in one visual replay on your web application.'
  184. ),
  185. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/session-replay/',
  186. },
  187. ],
  188. };
  189. const replayOnboarding: OnboardingConfig = {
  190. install: () => getInstallConfig(),
  191. configure: (params: Params) => [
  192. {
  193. type: StepType.CONFIGURE,
  194. description: getReplayConfigureDescription({
  195. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/session-replay/',
  196. }),
  197. configurations: [
  198. {
  199. code: [
  200. {
  201. label: 'JavaScript',
  202. value: 'javascript',
  203. language: 'javascript',
  204. code: getReplaySDKSetupSnippet({
  205. importStatement: `import * as Sentry from "@sentry/astro";`,
  206. dsn: params.dsn,
  207. }),
  208. },
  209. ],
  210. },
  211. ],
  212. },
  213. ],
  214. verify: () => [],
  215. nextSteps: () => [],
  216. };
  217. const docs: Docs = {
  218. onboarding,
  219. replayOnboardingNpm: replayOnboarding,
  220. };
  221. export default docs;