gatsby.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const replayIntegration = `
  9. new Sentry.Replay(),
  10. `;
  11. const replayOtherConfig = `
  12. // Session Replay
  13. 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.
  14. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  15. `;
  16. const performanceIntegration = `
  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. const performanceOtherConfig = `
  23. // Performance Monitoring
  24. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  25. `;
  26. export const steps = ({
  27. sentryInitContent,
  28. }: {
  29. sentryInitContent?: string;
  30. } = {}): LayoutProps['steps'] => [
  31. {
  32. type: StepType.INSTALL,
  33. description: t(
  34. 'Sentry captures data by using an SDK within your application’s runtime.'
  35. ),
  36. configurations: [
  37. {
  38. language: 'bash',
  39. code: `
  40. # Using yarn
  41. yarn add @sentry/gatsby
  42. # Using npm
  43. npm install --save @sentry/gatsby
  44. `,
  45. },
  46. ],
  47. },
  48. {
  49. type: StepType.CONFIGURE,
  50. configurations: [
  51. {
  52. description: (
  53. <p>
  54. {tct(
  55. 'Register the [code:@sentry/gatsby] plugin in your Gatsby configuration file (typically [code:gatsby-config.js]).',
  56. {
  57. code: <code />,
  58. }
  59. )}
  60. </p>
  61. ),
  62. language: 'javascript',
  63. code: `
  64. module.exports = {
  65. plugins: [
  66. {
  67. resolve: "@sentry/gatsby",
  68. },
  69. ],
  70. };
  71. `,
  72. },
  73. {
  74. description: (
  75. <p>{tct('Then, configure your [code:Sentry.init]:', {code: <code />})}</p>
  76. ),
  77. language: 'javascript',
  78. code: `
  79. import * as Sentry from "@sentry/gatsby";
  80. Sentry.init({
  81. ${sentryInitContent}
  82. });
  83. const container = document.getElementById(“app”);
  84. const root = createRoot(container);
  85. root.render(<App />)
  86. `,
  87. },
  88. ],
  89. },
  90. getUploadSourceMapsStep(
  91. 'https://docs.sentry.io/platforms/javascript/guides/gatsby/sourcemaps/'
  92. ),
  93. {
  94. type: StepType.VERIFY,
  95. description: t(
  96. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  97. ),
  98. configurations: [
  99. {
  100. language: 'javascript',
  101. code: 'myUndefinedFunction();',
  102. },
  103. ],
  104. },
  105. ];
  106. export const nextSteps = [
  107. {
  108. id: 'performance-monitoring',
  109. name: t('Performance Monitoring'),
  110. description: t(
  111. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  112. ),
  113. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/performance/',
  114. },
  115. {
  116. id: 'session-replay',
  117. name: t('Session Replay'),
  118. description: t(
  119. '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.'
  120. ),
  121. link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay/',
  122. },
  123. ];
  124. // Configuration End
  125. export function GettingStartedWithGatsby({
  126. dsn,
  127. activeProductSelection = [],
  128. ...props
  129. }: ModuleProps) {
  130. const integrations: string[] = [];
  131. const otherConfigs: string[] = [];
  132. let nextStepDocs = [...nextSteps];
  133. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  134. integrations.push(performanceIntegration.trim());
  135. otherConfigs.push(performanceOtherConfig.trim());
  136. nextStepDocs = nextStepDocs.filter(
  137. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  138. );
  139. }
  140. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  141. integrations.push(replayIntegration.trim());
  142. otherConfigs.push(replayOtherConfig.trim());
  143. nextStepDocs = nextStepDocs.filter(
  144. step => step.id !== ProductSolution.SESSION_REPLAY
  145. );
  146. }
  147. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  148. if (integrations.length > 0) {
  149. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  150. }
  151. if (otherConfigs.length > 0) {
  152. sentryInitContent = sentryInitContent.concat(otherConfigs);
  153. }
  154. return (
  155. <Layout
  156. steps={steps({sentryInitContent: sentryInitContent.join('\n')})}
  157. nextSteps={nextStepDocs}
  158. {...props}
  159. />
  160. );
  161. }
  162. export default GettingStartedWithGatsby;