gatsby.tsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. import {Fragment} from 'react';
  2. import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  3. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  4. import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  12. import {
  13. getCrashReportJavaScriptInstallStep,
  14. getCrashReportModalConfigDescription,
  15. getCrashReportModalIntroduction,
  16. getFeedbackConfigOptions,
  17. getFeedbackConfigureDescription,
  18. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  19. import {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  20. import {
  21. getReplayConfigOptions,
  22. getReplayConfigureDescription,
  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 * as Sentry from "@sentry/gatsby";
  28. Sentry.init({
  29. dsn: "${params.dsn}",
  30. integrations: [${
  31. params.isPerformanceSelected
  32. ? `
  33. Sentry.browserTracingIntegration(),`
  34. : ''
  35. }${
  36. params.isFeedbackSelected
  37. ? `
  38. Sentry.feedbackIntegration({
  39. // Additional SDK configuration goes in here, for example:
  40. colorScheme: "system",
  41. ${getFeedbackConfigOptions(params.feedbackOptions)}}),`
  42. : ''
  43. }${
  44. params.isReplaySelected
  45. ? `
  46. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  47. : ''
  48. }
  49. ],${
  50. params.isPerformanceSelected
  51. ? `
  52. // Performance Monitoring
  53. tracesSampleRate: 1.0, // Capture 100% of the transactions
  54. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  55. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  56. : ''
  57. }${
  58. params.isReplaySelected
  59. ? `
  60. // Session Replay
  61. replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
  62. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  63. : ''
  64. }
  65. });
  66. const container = document.getElementById(“app”);
  67. const root = createRoot(container);
  68. root.render(<App />);
  69. `;
  70. const getVerifyGatsbySnippet = () => `
  71. myUndefinedFunction();`;
  72. const getConfigureStep = (params: Params) => {
  73. return {
  74. type: StepType.CONFIGURE,
  75. configurations: [
  76. {
  77. description: tct(
  78. 'Register the [codeSentry@sentry/gatsby] plugin in your Gatsby configuration file (typically [codeGatsby:gatsby-config.js]).',
  79. {codeSentry: <code />, codeGatsby: <code />}
  80. ),
  81. code: [
  82. {
  83. label: 'JavaScript',
  84. value: 'javascript',
  85. language: 'javascript',
  86. code: `module.exports = {
  87. plugins: [{
  88. resolve: "@sentry/gatsby",
  89. }],
  90. };`,
  91. },
  92. ],
  93. },
  94. {
  95. description: tct('Then, configure your [codeSentry:Sentry.init:]', {
  96. codeSentry: <code />,
  97. }),
  98. code: [
  99. {
  100. label: 'JavaScript',
  101. value: 'javascript',
  102. language: 'javascript',
  103. code: getSdkSetupSnippet(params),
  104. },
  105. ],
  106. },
  107. ],
  108. };
  109. };
  110. const getInstallConfig = () => [
  111. {
  112. language: 'bash',
  113. code: [
  114. {
  115. label: 'npm',
  116. value: 'npm',
  117. language: 'bash',
  118. code: 'npm install --save @sentry/gatsby',
  119. },
  120. {
  121. label: 'yarn',
  122. value: 'yarn',
  123. language: 'bash',
  124. code: 'yarn add @sentry/gatsby',
  125. },
  126. ],
  127. },
  128. ];
  129. const onboarding: OnboardingConfig = {
  130. install: () => [
  131. {
  132. type: StepType.INSTALL,
  133. description: tct(
  134. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  135. {
  136. codeYarn: <code />,
  137. codeNpm: <code />,
  138. }
  139. ),
  140. configurations: getInstallConfig(),
  141. },
  142. ],
  143. configure: (params: Params) => [
  144. getConfigureStep(params),
  145. getUploadSourceMapsStep({
  146. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/sourcemaps//',
  147. }),
  148. ],
  149. verify: () => [
  150. {
  151. type: StepType.VERIFY,
  152. description: t(
  153. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  154. ),
  155. configurations: [
  156. {
  157. code: [
  158. {
  159. label: 'JavaScript',
  160. value: 'javascript',
  161. language: 'javascript',
  162. code: getVerifyGatsbySnippet(),
  163. },
  164. ],
  165. },
  166. ],
  167. },
  168. ],
  169. nextSteps: () => [
  170. {
  171. id: 'performance-monitoring',
  172. name: t('Performance Monitoring'),
  173. description: t(
  174. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  175. ),
  176. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/performance/',
  177. },
  178. {
  179. id: 'session-replay',
  180. name: t('Session Replay'),
  181. description: t(
  182. '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.'
  183. ),
  184. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay/',
  185. },
  186. ],
  187. };
  188. const replayOnboarding: OnboardingConfig = {
  189. install: () => [
  190. {
  191. type: StepType.INSTALL,
  192. description: tct(
  193. 'You need a minimum version 7.27.0 of [code:@sentry/gatsby] in order to use Session Replay. You do not need to install any additional packages.',
  194. {
  195. code: <code />,
  196. }
  197. ),
  198. configurations: getInstallConfig(),
  199. },
  200. ],
  201. configure: (params: Params) => [
  202. {
  203. type: StepType.CONFIGURE,
  204. description: getReplayConfigureDescription({
  205. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay/',
  206. }),
  207. configurations: [getConfigureStep(params)],
  208. additionalInfo: (
  209. <Fragment>
  210. <TracePropagationMessage />
  211. {tct(
  212. 'Note: If [codeGatsby:gatsby-config.js] has any settings for the [codeSentry:@sentry/gatsby] plugin, they need to be moved into [codeConfig:sentry.config.js]. The [codeGatsby:gatsby-config.js] file does not support non-serializable options, like [codeNew:new Replay()].',
  213. {
  214. codeGatsby: <code />,
  215. codeSentry: <code />,
  216. codeConfig: <code />,
  217. codeNew: <code />,
  218. }
  219. )}
  220. </Fragment>
  221. ),
  222. },
  223. ],
  224. verify: () => [],
  225. nextSteps: () => [],
  226. };
  227. const feedbackOnboarding: OnboardingConfig = {
  228. install: () => [
  229. {
  230. type: StepType.INSTALL,
  231. description: tct(
  232. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/gatsby]) installed, minimum version 7.85.0.',
  233. {
  234. code: <code />,
  235. }
  236. ),
  237. configurations: getInstallConfig(),
  238. },
  239. ],
  240. configure: (params: Params) => [
  241. {
  242. type: StepType.CONFIGURE,
  243. description: getFeedbackConfigureDescription({
  244. linkConfig:
  245. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/',
  246. linkButton:
  247. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/#bring-your-own-button',
  248. }),
  249. configurations: [
  250. {
  251. code: [
  252. {
  253. label: 'JavaScript',
  254. value: 'javascript',
  255. language: 'javascript',
  256. code: getSdkSetupSnippet(params),
  257. },
  258. ],
  259. },
  260. ],
  261. additionalInfo: crashReportCallout({
  262. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/#crash-report-modal',
  263. }),
  264. },
  265. ],
  266. verify: () => [],
  267. nextSteps: () => [],
  268. };
  269. const crashReportOnboarding: OnboardingConfig = {
  270. introduction: () => getCrashReportModalIntroduction(),
  271. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  272. configure: () => [
  273. {
  274. type: StepType.CONFIGURE,
  275. description: getCrashReportModalConfigDescription({
  276. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/#crash-report-modal',
  277. }),
  278. additionalInfo: widgetCallout({
  279. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/#user-feedback-widget',
  280. }),
  281. },
  282. ],
  283. verify: () => [],
  284. nextSteps: () => [],
  285. };
  286. const docs: Docs = {
  287. onboarding,
  288. feedbackOnboardingNpm: feedbackOnboarding,
  289. replayOnboardingNpm: replayOnboarding,
  290. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  291. crashReportOnboarding,
  292. };
  293. export default docs;