astro.tsx 12 KB

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