gatsby.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 [code:Sentry@sentry/gatsby] plugin in your Gatsby configuration file (typically [code:gatsby-config.js]).',
  99. {code: <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: params => (
  154. <Fragment>
  155. <MaybeBrowserProfilingBetaWarning {...params} />
  156. <p>
  157. {tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  158. strong: <strong />,
  159. })}
  160. </p>
  161. </Fragment>
  162. ),
  163. install: () => [
  164. {
  165. type: StepType.INSTALL,
  166. description: tct(
  167. 'Add the Sentry SDK as a dependency using [code:npm] or [code:yarn]:',
  168. {
  169. code: <code />,
  170. }
  171. ),
  172. configurations: getInstallConfig(),
  173. },
  174. ],
  175. configure: (params: Params) => [
  176. getConfigureStep(params),
  177. getUploadSourceMapsStep({
  178. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/sourcemaps/',
  179. ...params,
  180. }),
  181. ],
  182. verify: () => [
  183. {
  184. type: StepType.VERIFY,
  185. description: t(
  186. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  187. ),
  188. configurations: [
  189. {
  190. code: [
  191. {
  192. label: 'JavaScript',
  193. value: 'javascript',
  194. language: 'javascript',
  195. code: getVerifySnippet(),
  196. },
  197. ],
  198. },
  199. ],
  200. },
  201. ],
  202. nextSteps: () => [],
  203. };
  204. const replayOnboarding: OnboardingConfig = {
  205. install: () => [
  206. {
  207. type: StepType.INSTALL,
  208. description: tct(
  209. '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.',
  210. {
  211. code: <code />,
  212. }
  213. ),
  214. configurations: getInstallConfig(),
  215. },
  216. ],
  217. configure: (params: Params) => [
  218. {
  219. type: StepType.CONFIGURE,
  220. description: getReplayConfigureDescription({
  221. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay/',
  222. }),
  223. configurations: [getConfigureStep(params)],
  224. additionalInfo: (
  225. <Fragment>
  226. <TracePropagationMessage />
  227. {tct(
  228. 'Note: If [code:gatsby-config.js] has any settings for the [code:@sentry/gatsby] plugin, they need to be moved into [code:sentry.config.js]. The [code:gatsby-config.js] file does not support non-serializable options, like [code:new Replay()].',
  229. {
  230. code: <code />,
  231. }
  232. )}
  233. </Fragment>
  234. ),
  235. },
  236. ],
  237. verify: getReplayVerifyStep(),
  238. nextSteps: () => [],
  239. };
  240. const feedbackOnboarding: OnboardingConfig = {
  241. install: () => [
  242. {
  243. type: StepType.INSTALL,
  244. description: tct(
  245. '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.',
  246. {
  247. code: <code />,
  248. }
  249. ),
  250. configurations: getInstallConfig(),
  251. },
  252. ],
  253. configure: (params: Params) => [
  254. {
  255. type: StepType.CONFIGURE,
  256. description: getFeedbackConfigureDescription({
  257. linkConfig:
  258. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/',
  259. linkButton:
  260. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/#bring-your-own-button',
  261. }),
  262. configurations: [
  263. {
  264. code: [
  265. {
  266. label: 'JavaScript',
  267. value: 'javascript',
  268. language: 'javascript',
  269. code: getSdkSetupSnippet(params),
  270. },
  271. ],
  272. },
  273. ],
  274. additionalInfo: crashReportCallout({
  275. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/#crash-report-modal',
  276. }),
  277. },
  278. ],
  279. verify: () => [],
  280. nextSteps: () => [],
  281. };
  282. const crashReportOnboarding: OnboardingConfig = {
  283. introduction: () => getCrashReportModalIntroduction(),
  284. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  285. configure: () => [
  286. {
  287. type: StepType.CONFIGURE,
  288. description: getCrashReportModalConfigDescription({
  289. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/configuration/#crash-report-modal',
  290. }),
  291. additionalInfo: widgetCallout({
  292. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback/#user-feedback-widget',
  293. }),
  294. },
  295. ],
  296. verify: () => [],
  297. nextSteps: () => [],
  298. };
  299. const profilingOnboarding: OnboardingConfig = {
  300. ...onboarding,
  301. introduction: params => <MaybeBrowserProfilingBetaWarning {...params} />,
  302. };
  303. const docs: Docs = {
  304. onboarding,
  305. feedbackOnboardingNpm: feedbackOnboarding,
  306. replayOnboarding,
  307. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  308. crashReportOnboarding,
  309. profilingOnboarding,
  310. };
  311. export default docs;