gatsby.tsx 10 KB

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