gatsby.tsx 8.1 KB

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