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