gatsby.tsx 9.8 KB

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