gatsby.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {tct} from 'sentry/locale';
  6. import type {Organization, PlatformKey} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. // Configuration Start
  15. const replayIntegration = `
  16. new Sentry.Replay(),
  17. `;
  18. const replayOtherConfig = `
  19. // This sets the sample rate to be 10%. You may want this to be 100% while
  20. // in development and sample at a lower rate in production.
  21. replaysSessionSampleRate: 0.1,
  22. // If the entire session is not sampled, use the below sample rate to sample
  23. // sessions when an error occurs.
  24. replaysOnErrorSampleRate: 1.0,
  25. `;
  26. export const steps = ({
  27. sentryInitContent,
  28. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  29. {
  30. type: StepType.INSTALL,
  31. description: tct(
  32. 'To use Sentry with your Gatsby application, you will need to use [code:@sentry/gatsby] (Sentry’s Gatsby SDK):',
  33. {code: <code />}
  34. ),
  35. configurations: [
  36. {
  37. language: 'bash',
  38. code: [
  39. {
  40. label: 'npm',
  41. value: 'npm',
  42. language: 'bash',
  43. code: 'npm install --save @sentry/gatsby',
  44. },
  45. {
  46. label: 'yarn',
  47. value: 'yarn',
  48. language: 'bash',
  49. code: 'yarn add @sentry/gatsby',
  50. },
  51. ],
  52. },
  53. ],
  54. },
  55. {
  56. type: StepType.REGISTER,
  57. description: tct(
  58. 'Register the [codeSentry:@sentry/gatsby] plugin in your Gatsby configuration file (typically [codeGatsby:gatsby-config.js]).',
  59. {
  60. codeSentry: <code />,
  61. codeGatsby: <code />,
  62. link: (
  63. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/" />
  64. ),
  65. }
  66. ),
  67. configurations: [
  68. {
  69. language: 'javascript',
  70. code: `
  71. module.exports = {
  72. plugins: [
  73. {
  74. resolve: "@sentry/gatsby",
  75. },
  76. ],
  77. };
  78. `,
  79. },
  80. ],
  81. },
  82. {
  83. type: StepType.CONFIGURE,
  84. description: tct(
  85. 'Add the following to your SDK config. There are several privacy and sampling options available, all of which can be set using the [code:integrations] constructor. Learn more about configuring Session Replay by reading the [link:configuration docs].',
  86. {
  87. code: <code />,
  88. link: (
  89. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/" />
  90. ),
  91. }
  92. ),
  93. configurations: [
  94. {
  95. language: 'javascript',
  96. code: `
  97. import * as Sentry from "@sentry/gatsby";
  98. Sentry.init({
  99. ${sentryInitContent}
  100. });
  101. `,
  102. },
  103. ],
  104. additionalInfo: tct(
  105. '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()].',
  106. {
  107. codeGatsby: <code />,
  108. codeSentry: <code />,
  109. codeConfig: <code />,
  110. codeNew: <code />,
  111. }
  112. ),
  113. },
  114. ];
  115. // Configuration End
  116. export function GettingStartedWithGatsbyReplay({
  117. dsn,
  118. organization,
  119. newOrg,
  120. platformKey,
  121. projectId,
  122. ...props
  123. }: ModuleProps) {
  124. const integrations = replayIntegration.trim();
  125. const otherConfigs = replayOtherConfig.trim();
  126. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  127. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  128. sentryInitContent = sentryInitContent.concat(otherConfigs);
  129. return (
  130. <Layout
  131. steps={steps({
  132. sentryInitContent: sentryInitContent.join('\n'),
  133. organization,
  134. newOrg,
  135. platformKey,
  136. projectId,
  137. })}
  138. platformKey={platformKey}
  139. newOrg={newOrg}
  140. hideHeader
  141. {...props}
  142. />
  143. );
  144. }
  145. export default GettingStartedWithGatsbyReplay;