astro.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 {getReplaySDKSetupSnippet} from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  21. import {t, tct} from 'sentry/locale';
  22. type Params = DocsParams;
  23. const getSdkSetupSnippet = (params: Params) => `
  24. import { defineConfig } from "astro/config";
  25. import sentry from "@sentry/astro";
  26. export default defineConfig({
  27. integrations: [
  28. sentry({
  29. dsn: "${params.dsn}",${
  30. params.isPerformanceSelected
  31. ? ''
  32. : `
  33. tracesSampleRate: 0,`
  34. }${
  35. params.isReplaySelected
  36. ? ''
  37. : `
  38. replaysSessionSampleRate: 0,
  39. replaysOnErrorSampleRate: 0,`
  40. }
  41. sourceMapsUploadOptions: {
  42. project: "${params.projectSlug}",
  43. authToken: process.env.SENTRY_AUTH_TOKEN,
  44. },
  45. }),
  46. ],
  47. });
  48. `;
  49. const getVerifyAstroSnippet = () => `
  50. <!-- your-page.astro -->
  51. ---
  52. ---
  53. <button id="error-button">Throw test error</button>
  54. <script>
  55. function handleClick () {
  56. throw new Error('This is a test error');
  57. }
  58. document.querySelector("#error-button").addEventListener("click", handleClick);
  59. </script>
  60. `;
  61. const getInstallConfig = () => [
  62. {
  63. type: StepType.INSTALL,
  64. description: tct(
  65. 'Install the [sentryAstroPkg:@sentry/astro] package with the [astroCli:astro] CLI:',
  66. {
  67. sentryAstroPkg: <code />,
  68. astroCli: <code />,
  69. }
  70. ),
  71. configurations: [
  72. {
  73. language: 'bash',
  74. code: [
  75. {
  76. label: 'bash',
  77. value: 'bash',
  78. language: 'bash',
  79. code: `npx astro add @sentry/astro`,
  80. },
  81. ],
  82. },
  83. ],
  84. },
  85. ];
  86. const onboarding: OnboardingConfig = {
  87. introduction: () =>
  88. tct("Sentry's integration with [astroLink:Astro] supports Astro 3.0.0 and above.", {
  89. astroLink: <ExternalLink href="https://astro.build/" />,
  90. }),
  91. install: () => getInstallConfig(),
  92. configure: (params: Params) => [
  93. {
  94. type: StepType.CONFIGURE,
  95. description: tct(
  96. 'Open up your [astroConfig:astro.config.mjs] file and configure the DSN, and any other settings you need:',
  97. {
  98. astroConfig: <code />,
  99. }
  100. ),
  101. configurations: [
  102. {
  103. code: [
  104. {
  105. label: 'JavaScript',
  106. value: 'javascript',
  107. language: 'javascript',
  108. code: getSdkSetupSnippet(params),
  109. },
  110. ],
  111. },
  112. {
  113. description: tct(
  114. 'Add your Sentry auth token to the [authTokenEnvVar:SENTRY_AUTH_TOKEN] environment variable:',
  115. {
  116. authTokenEnvVar: <code />,
  117. }
  118. ),
  119. language: 'bash',
  120. code: [
  121. {
  122. value: 'bash',
  123. language: 'bash',
  124. label: 'bash',
  125. code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
  126. },
  127. ],
  128. },
  129. {
  130. description: tct(
  131. 'You can further customize your SDK by [manualSetupLink:manually inializing the SDK].',
  132. {
  133. manualSetupLink: (
  134. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/" />
  135. ),
  136. }
  137. ),
  138. },
  139. ],
  140. },
  141. ],
  142. verify: () => [
  143. {
  144. type: StepType.VERIFY,
  145. description: t(
  146. 'Then throw a test error anywhere in your app, so you can test that everything is working:'
  147. ),
  148. configurations: [
  149. {
  150. code: [
  151. {
  152. label: 'Astro',
  153. value: 'html',
  154. language: 'html',
  155. code: getVerifyAstroSnippet(),
  156. },
  157. ],
  158. },
  159. ],
  160. additionalInfo: (
  161. <Fragment>
  162. <p>
  163. {t(
  164. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  165. )}
  166. </p>
  167. <p>
  168. {t(
  169. "If you're an existing user and have disabled alerts, you won't receive this email."
  170. )}
  171. </p>
  172. </Fragment>
  173. ),
  174. },
  175. ],
  176. nextSteps: () => [
  177. {
  178. id: 'astro-manual-setup',
  179. name: t('Customize your SDK Setup'),
  180. description: t(
  181. 'Learn how to further configure and customize your Sentry Astro SDK setup.'
  182. ),
  183. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/',
  184. },
  185. {
  186. id: 'performance-monitoring',
  187. name: t('Performance Monitoring'),
  188. description: t(
  189. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  190. ),
  191. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/performance/',
  192. },
  193. {
  194. id: 'session-replay',
  195. name: t('Session Replay'),
  196. description: t(
  197. '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.'
  198. ),
  199. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/session-replay/',
  200. },
  201. ],
  202. };
  203. const replayOnboarding: OnboardingConfig = {
  204. install: () => [
  205. {
  206. ...getInstallConfig()[0],
  207. additionalInfo:
  208. 'Session Replay is enabled by default when you install the Astro SDK!',
  209. },
  210. ],
  211. configure: (params: Params) => [
  212. {
  213. type: StepType.CONFIGURE,
  214. description: tct(
  215. 'There are several privacy and sampling options available. Learn more about configuring Session Replay by reading the [link:configuration docs].',
  216. {
  217. link: (
  218. <ExternalLink
  219. href={
  220. 'https://docs.sentry.io/platforms/javascript/guides/astro/session-replay/'
  221. }
  222. />
  223. ),
  224. }
  225. ),
  226. configurations: [
  227. {
  228. description: tct(
  229. 'You can set sample rates directly in your [code:astro.config.js] file:',
  230. {
  231. code: <code />,
  232. }
  233. ),
  234. code: [
  235. {
  236. label: 'JavaScript',
  237. value: 'javascript',
  238. language: 'javascript',
  239. filename: 'astro.config.js',
  240. code: `
  241. import { defineConfig } from "astro/config";
  242. import sentry from "@sentry/astro";
  243. export default defineConfig({
  244. integrations: [
  245. sentry({
  246. dsn: "${params.dsn}",
  247. replaysSessionSampleRate: 0.2, // defaults to 0.1
  248. replaysOnErrorSampleRate: 1.0, // defaults to 1.0
  249. }),
  250. ],
  251. });
  252. `,
  253. },
  254. ],
  255. additionalInfo: tct(
  256. 'Further Replay options, like privacy settings, can be set in a [code:sentry.client.config.js] file:',
  257. {
  258. code: <code />,
  259. }
  260. ),
  261. },
  262. {
  263. code: [
  264. {
  265. label: 'JavaScript',
  266. value: 'javascript',
  267. language: 'javascript',
  268. filename: 'sentry.client.config.js',
  269. code: getReplaySDKSetupSnippet({
  270. importStatement: `// This file overrides \`astro.config.mjs\` for the browser-side.
  271. // SDK options from \`astro.config.mjs\` will not apply.
  272. import * as Sentry from "@sentry/astro";`,
  273. dsn: params.dsn,
  274. mask: params.replayOptions?.mask,
  275. block: params.replayOptions?.block,
  276. }),
  277. },
  278. ],
  279. additionalInfo: tct(
  280. `Note that creating your own [code:sentry.client.config.js] file will override the default settings in your [code2:astro.config.js] file. Learn more about this [link:here].`,
  281. {
  282. code: <code />,
  283. code2: <code />,
  284. link: (
  285. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/#manual-sdk-initialization" />
  286. ),
  287. }
  288. ),
  289. },
  290. ],
  291. additionalInfo: <TracePropagationMessage />,
  292. isOptional: true,
  293. },
  294. ],
  295. verify: () => [],
  296. nextSteps: () => [],
  297. };
  298. const feedbackOnboarding: OnboardingConfig = {
  299. install: () => [
  300. {
  301. type: StepType.INSTALL,
  302. description: tct(
  303. '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.',
  304. {
  305. code: <code />,
  306. }
  307. ),
  308. configurations: getInstallConfig(),
  309. },
  310. ],
  311. configure: (params: Params) => [
  312. {
  313. type: StepType.CONFIGURE,
  314. description: getFeedbackConfigureDescription({
  315. linkConfig:
  316. 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/configuration/',
  317. linkButton:
  318. 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/configuration/#bring-your-own-button',
  319. }),
  320. configurations: [
  321. {
  322. code: [
  323. {
  324. label: 'JavaScript',
  325. value: 'javascript',
  326. language: 'javascript',
  327. code: getFeedbackSDKSetupSnippet({
  328. importStatement: `import * as Sentry from "@sentry/astro";`,
  329. dsn: params.dsn,
  330. feedbackOptions: params.feedbackOptions,
  331. }),
  332. },
  333. ],
  334. },
  335. ],
  336. additionalInfo: crashReportCallout({
  337. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/#crash-report-modal',
  338. }),
  339. },
  340. ],
  341. verify: () => [],
  342. nextSteps: () => [],
  343. };
  344. const crashReportOnboarding: OnboardingConfig = {
  345. introduction: () => getCrashReportModalIntroduction(),
  346. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  347. configure: () => [
  348. {
  349. type: StepType.CONFIGURE,
  350. description: getCrashReportModalConfigDescription({
  351. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/configuration/#crash-report-modal',
  352. }),
  353. additionalInfo: widgetCallout({
  354. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/#user-feedback-widget',
  355. }),
  356. },
  357. ],
  358. verify: () => [],
  359. nextSteps: () => [],
  360. };
  361. const docs: Docs = {
  362. onboarding,
  363. feedbackOnboardingNpm: feedbackOnboarding,
  364. replayOnboardingNpm: replayOnboarding,
  365. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  366. crashReportOnboarding,
  367. };
  368. export default docs;