gatsby.tsx 6.2 KB

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