gatsby.tsx 6.0 KB

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