gatsby.tsx 4.8 KB

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