astro.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 {
  22. getReplaySDKSetupSnippet,
  23. getReplayVerifyStep,
  24. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  25. import {t, tct} from 'sentry/locale';
  26. type Params = DocsParams;
  27. const getSdkSetupSnippet = (params: Params) => `
  28. import { defineConfig } from "astro/config";
  29. import sentry from "@sentry/astro";
  30. export default defineConfig({
  31. integrations: [
  32. sentry({
  33. dsn: "${params.dsn.public}",${
  34. params.isPerformanceSelected
  35. ? ''
  36. : `
  37. tracesSampleRate: 0,`
  38. }${
  39. params.isReplaySelected
  40. ? ''
  41. : `
  42. replaysSessionSampleRate: 0,
  43. replaysOnErrorSampleRate: 0,`
  44. }
  45. sourceMapsUploadOptions: {
  46. project: "${params.projectSlug}",
  47. authToken: process.env.SENTRY_AUTH_TOKEN,
  48. },
  49. }),
  50. ],
  51. });
  52. `;
  53. const getVerifySnippet = () => `
  54. <!-- your-page.astro -->
  55. ---
  56. ---
  57. <button id="error-button">Throw test error</button>
  58. <script>
  59. function handleClick () {
  60. throw new Error('This is a test error');
  61. }
  62. document.querySelector("#error-button").addEventListener("click", handleClick);
  63. </script>
  64. `;
  65. const getInstallConfig = () => [
  66. {
  67. type: StepType.INSTALL,
  68. description: tct(
  69. 'Install the [code:@sentry/astro] package with the [code:astro] CLI:',
  70. {
  71. code: <code />,
  72. }
  73. ),
  74. configurations: [
  75. {
  76. language: 'bash',
  77. code: [
  78. {
  79. label: 'bash',
  80. value: 'bash',
  81. language: 'bash',
  82. code: `npx astro add @sentry/astro`,
  83. },
  84. ],
  85. },
  86. ],
  87. },
  88. ];
  89. const onboarding: OnboardingConfig = {
  90. introduction: () => (
  91. <Fragment>
  92. <p>
  93. {tct(
  94. "Sentry's integration with [astroLink:Astro] supports Astro 3.0.0 and above.",
  95. {
  96. astroLink: <ExternalLink href="https://astro.build/" />,
  97. }
  98. )}
  99. </p>
  100. <p>
  101. {tct("In this quick guide you'll use the [astrocli:astro] CLI to set up:", {
  102. astrocli: <strong />,
  103. })}
  104. </p>
  105. </Fragment>
  106. ),
  107. install: () => getInstallConfig(),
  108. configure: (params: Params) => [
  109. {
  110. type: StepType.CONFIGURE,
  111. description: tct(
  112. 'Open up your [astroConfig:astro.config.mjs] file and configure the DSN, and any other settings you need:',
  113. {
  114. astroConfig: <code />,
  115. }
  116. ),
  117. configurations: [
  118. {
  119. code: [
  120. {
  121. label: 'JavaScript',
  122. value: 'javascript',
  123. language: 'javascript',
  124. code: getSdkSetupSnippet(params),
  125. },
  126. ],
  127. },
  128. {
  129. description: tct(
  130. 'Add your Sentry auth token to the [authTokenEnvVar:SENTRY_AUTH_TOKEN] environment variable:',
  131. {
  132. authTokenEnvVar: <code />,
  133. }
  134. ),
  135. language: 'bash',
  136. code: [
  137. {
  138. value: 'bash',
  139. language: 'bash',
  140. label: 'bash',
  141. code: `SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___`,
  142. },
  143. ],
  144. },
  145. {
  146. description: tct(
  147. 'You can further customize your SDK by [manualSetupLink:manually inializing the SDK].',
  148. {
  149. manualSetupLink: (
  150. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/" />
  151. ),
  152. }
  153. ),
  154. },
  155. ],
  156. },
  157. ],
  158. verify: () => [
  159. {
  160. type: StepType.VERIFY,
  161. description: t(
  162. 'Then throw a test error anywhere in your app, so you can test that everything is working:'
  163. ),
  164. configurations: [
  165. {
  166. code: [
  167. {
  168. label: 'Astro',
  169. value: 'html',
  170. language: 'html',
  171. code: getVerifySnippet(),
  172. },
  173. ],
  174. },
  175. ],
  176. additionalInfo: (
  177. <Fragment>
  178. <p>
  179. {t(
  180. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  181. )}
  182. </p>
  183. <p>
  184. {t(
  185. "If you're an existing user and have disabled alerts, you won't receive this email."
  186. )}
  187. </p>
  188. </Fragment>
  189. ),
  190. },
  191. ],
  192. nextSteps: () => [
  193. {
  194. id: 'astro-manual-setup',
  195. name: t('Customize your SDK Setup'),
  196. description: t(
  197. 'Learn how to further configure and customize your Sentry Astro SDK setup.'
  198. ),
  199. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/',
  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. title: 'Configure Session Replay (Optional)',
  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.public}",
  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.public,
  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 [code:astro.config.js] file. Learn more about this [link:here].`,
  281. {
  282. code: <code />,
  283. link: (
  284. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/astro/manual-setup/#manual-sdk-initialization" />
  285. ),
  286. }
  287. ),
  288. },
  289. ],
  290. additionalInfo: <TracePropagationMessage />,
  291. collapsible: true,
  292. },
  293. ],
  294. verify: getReplayVerifyStep(),
  295. nextSteps: () => [],
  296. };
  297. const feedbackOnboarding: OnboardingConfig = {
  298. install: () => [
  299. {
  300. type: StepType.INSTALL,
  301. description: tct(
  302. '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.',
  303. {
  304. code: <code />,
  305. }
  306. ),
  307. configurations: getInstallConfig(),
  308. },
  309. ],
  310. configure: (params: Params) => [
  311. {
  312. type: StepType.CONFIGURE,
  313. description: getFeedbackConfigureDescription({
  314. linkConfig:
  315. 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/configuration/',
  316. linkButton:
  317. 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/configuration/#bring-your-own-button',
  318. }),
  319. configurations: [
  320. {
  321. code: [
  322. {
  323. label: 'JavaScript',
  324. value: 'javascript',
  325. language: 'javascript',
  326. code: getFeedbackSDKSetupSnippet({
  327. importStatement: `import * as Sentry from "@sentry/astro";`,
  328. dsn: params.dsn.public,
  329. feedbackOptions: params.feedbackOptions,
  330. }),
  331. },
  332. ],
  333. },
  334. ],
  335. additionalInfo: crashReportCallout({
  336. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/#crash-report-modal',
  337. }),
  338. },
  339. ],
  340. verify: () => [],
  341. nextSteps: () => [],
  342. };
  343. const crashReportOnboarding: OnboardingConfig = {
  344. introduction: () => getCrashReportModalIntroduction(),
  345. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  346. configure: params => [
  347. {
  348. type: StepType.CONFIGURE,
  349. description: getCrashReportModalConfigDescription({
  350. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/configuration/#crash-report-modal',
  351. }),
  352. additionalInfo: widgetCallout({
  353. link: 'https://docs.sentry.io/platforms/javascript/guides/astro/user-feedback/#user-feedback-widget',
  354. }),
  355. ...(params.isProfilingSelected
  356. ? [getProfilingDocumentHeaderConfigurationStep()]
  357. : []),
  358. },
  359. ],
  360. verify: () => [],
  361. nextSteps: () => [],
  362. };
  363. const docs: Docs = {
  364. onboarding,
  365. feedbackOnboardingNpm: feedbackOnboarding,
  366. replayOnboarding,
  367. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  368. crashReportOnboarding,
  369. };
  370. export default docs;