gatsby.tsx 6.0 KB

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