astro.tsx 9.1 KB

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