gatsby.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. getProfilingDocumentHeaderConfigurationStep,
  22. MaybeBrowserProfilingBetaWarning,
  23. } from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  24. import {
  25. getReplayConfigOptions,
  26. getReplayConfigureDescription,
  27. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  28. import {t, tct} from 'sentry/locale';
  29. type Params = DocsParams;
  30. const getSdkSetupSnippet = (params: Params) => `
  31. import * as Sentry from "@sentry/gatsby";
  32. Sentry.init({
  33. dsn: "${params.dsn.public}",
  34. integrations: [${
  35. params.isPerformanceSelected
  36. ? `
  37. Sentry.browserTracingIntegration(),`
  38. : ''
  39. }${
  40. params.isProfilingSelected
  41. ? `
  42. Sentry.browserProfilingIntegration(),`
  43. : ''
  44. }${
  45. params.isFeedbackSelected
  46. ? `
  47. Sentry.feedbackIntegration({
  48. // Additional SDK configuration goes in here, for example:
  49. colorScheme: "system",
  50. ${getFeedbackConfigOptions(params.feedbackOptions)}}),`
  51. : ''
  52. }${
  53. params.isReplaySelected
  54. ? `
  55. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  56. : ''
  57. }
  58. ],${
  59. params.isPerformanceSelected
  60. ? `
  61. // Tracing
  62. tracesSampleRate: 1.0, // Capture 100% of the transactions
  63. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  64. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  65. : ''
  66. }${
  67. params.isReplaySelected
  68. ? `
  69. // Session Replay
  70. 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.
  71. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  72. : ''
  73. }${
  74. params.isProfilingSelected
  75. ? `
  76. // Set profilesSampleRate to 1.0 to profile every transaction.
  77. // Since profilesSampleRate is relative to tracesSampleRate,
  78. // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  79. // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  80. // results in 25% of transactions being profiled (0.5*0.5=0.25)
  81. profilesSampleRate: 1.0,`
  82. : ''
  83. }
  84. });
  85. const container = document.getElementById(“app”);
  86. const root = createRoot(container);
  87. root.render(<App />);
  88. `;
  89. const getVerifyGatsbySnippet = () => `
  90. myUndefinedFunction();`;
  91. const getConfigureStep = (params: Params) => {
  92. return {
  93. type: StepType.CONFIGURE,
  94. configurations: [
  95. {
  96. description: tct(
  97. 'Register the [codeSentry@sentry/gatsby] plugin in your Gatsby configuration file (typically [codeGatsby:gatsby-config.js]).',
  98. {codeSentry: <code />, codeGatsby: <code />}
  99. ),
  100. code: [
  101. {
  102. label: 'JavaScript',
  103. value: 'javascript',
  104. language: 'javascript',
  105. code: `module.exports = {
  106. plugins: [{
  107. resolve: "@sentry/gatsby",
  108. }],
  109. };`,
  110. },
  111. ],
  112. },
  113. {
  114. description: tct('Then, configure your [codeSentry:Sentry.init:]', {
  115. codeSentry: <code />,
  116. }),
  117. code: [
  118. {
  119. label: 'JavaScript',
  120. value: 'javascript',
  121. language: 'javascript',
  122. code: getSdkSetupSnippet(params),
  123. },
  124. ],
  125. },
  126. ...(params.isProfilingSelected
  127. ? [getProfilingDocumentHeaderConfigurationStep()]
  128. : []),
  129. ],
  130. };
  131. };
  132. const getInstallConfig = () => [
  133. {
  134. language: 'bash',
  135. code: [
  136. {
  137. label: 'npm',
  138. value: 'npm',
  139. language: 'bash',
  140. code: 'npm install --save @sentry/gatsby',
  141. },
  142. {
  143. label: 'yarn',
  144. value: 'yarn',
  145. language: 'bash',
  146. code: 'yarn add @sentry/gatsby',
  147. },
  148. ],
  149. },
  150. ];
  151. const onboarding: OnboardingConfig = {
  152. introduction: MaybeBrowserProfilingBetaWarning,
  153. install: () => [
  154. {
  155. type: StepType.INSTALL,
  156. description: tct(
  157. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  158. {
  159. codeYarn: <code />,
  160. codeNpm: <code />,
  161. }
  162. ),
  163. configurations: getInstallConfig(),
  164. },
  165. ],
  166. configure: (params: Params) => [
  167. getConfigureStep(params),
  168. getUploadSourceMapsStep({
  169. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/sourcemaps//',
  170. }),
  171. ],
  172. verify: () => [
  173. {
  174. type: StepType.VERIFY,
  175. description: t(
  176. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  177. ),
  178. configurations: [
  179. {
  180. code: [
  181. {
  182. label: 'JavaScript',
  183. value: 'javascript',
  184. language: 'javascript',
  185. code: getVerifyGatsbySnippet(),
  186. },
  187. ],
  188. },
  189. ],
  190. },
  191. ],
  192. nextSteps: () => [
  193. {
  194. id: 'performance-monitoring',
  195. name: t('Tracing'),
  196. description: t(
  197. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  198. ),
  199. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/tracing/',
  200. },
  201. {
  202. id: 'session-replay',
  203. name: t('Session Replay'),
  204. description: t(
  205. '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.'
  206. ),
  207. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay/',
  208. },
  209. ],
  210. };
  211. const replayOnboarding: OnboardingConfig = {
  212. install: () => [
  213. {
  214. type: StepType.INSTALL,
  215. description: tct(
  216. '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.',
  217. {
  218. code: <code />,
  219. }
  220. ),
  221. configurations: getInstallConfig(),
  222. },
  223. ],
  224. configure: (params: Params) => [
  225. {
  226. type: StepType.CONFIGURE,
  227. description: getReplayConfigureDescription({
  228. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay/',
  229. }),
  230. configurations: [getConfigureStep(params)],
  231. additionalInfo: (
  232. <Fragment>
  233. <TracePropagationMessage />
  234. {tct(
  235. '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()].',
  236. {
  237. codeGatsby: <code />,
  238. codeSentry: <code />,
  239. codeConfig: <code />,
  240. codeNew: <code />,
  241. }
  242. )}
  243. </Fragment>
  244. ),
  245. },
  246. ],
  247. verify: () => [],
  248. nextSteps: () => [],
  249. };
  250. const feedbackOnboarding: OnboardingConfig = {
  251. install: () => [
  252. {
  253. type: StepType.INSTALL,
  254. description: tct(
  255. '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.',
  256. {
  257. code: <code />,
  258. }
  259. ),
  260. configurations: getInstallConfig(),
  261. },
  262. ],
  263. configure: (params: Params) => [
  264. {
  265. type: StepType.CONFIGURE,
  266. description: getFeedbackConfigureDescription({
  267. linkConfig:
  268. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/',
  269. linkButton:
  270. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/#bring-your-own-button',
  271. }),
  272. configurations: [
  273. {
  274. code: [
  275. {
  276. label: 'JavaScript',
  277. value: 'javascript',
  278. language: 'javascript',
  279. code: getSdkSetupSnippet(params),
  280. },
  281. ],
  282. },
  283. ],
  284. additionalInfo: crashReportCallout({
  285. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/#crash-report-modal',
  286. }),
  287. },
  288. ],
  289. verify: () => [],
  290. nextSteps: () => [],
  291. };
  292. const crashReportOnboarding: OnboardingConfig = {
  293. introduction: () => getCrashReportModalIntroduction(),
  294. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  295. configure: () => [
  296. {
  297. type: StepType.CONFIGURE,
  298. description: getCrashReportModalConfigDescription({
  299. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/#crash-report-modal',
  300. }),
  301. additionalInfo: widgetCallout({
  302. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/#user-feedback-widget',
  303. }),
  304. },
  305. ],
  306. verify: () => [],
  307. nextSteps: () => [],
  308. };
  309. const docs: Docs = {
  310. onboarding,
  311. feedbackOnboardingNpm: feedbackOnboarding,
  312. replayOnboardingNpm: replayOnboarding,
  313. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  314. crashReportOnboarding,
  315. };
  316. export default docs;