astro.tsx 8.0 KB

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