gatsby.tsx 5.6 KB

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