gatsby.tsx 6.4 KB

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