gatsby.tsx 9.8 KB

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