astro.tsx 6.4 KB

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