react.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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: (
  32. <p>
  33. {tct(
  34. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]. You need a minimum version 7.27.0 of [code:@sentry/react] in order to use Session Replay. You do not need to install any additional packages.',
  35. {
  36. code: <code />,
  37. codeYarn: <code />,
  38. codeNpm: <code />,
  39. }
  40. )}
  41. </p>
  42. ),
  43. configurations: [
  44. {
  45. language: 'bash',
  46. code: [
  47. {
  48. label: 'npm',
  49. value: 'npm',
  50. language: 'bash',
  51. code: 'npm install --save @sentry/react',
  52. },
  53. {
  54. label: 'yarn',
  55. value: 'yarn',
  56. language: 'bash',
  57. code: 'yarn add @sentry/react',
  58. },
  59. ],
  60. },
  61. ],
  62. },
  63. {
  64. type: StepType.CONFIGURE,
  65. description: tct(
  66. '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].',
  67. {
  68. code: <code />,
  69. link: (
  70. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/" />
  71. ),
  72. }
  73. ),
  74. configurations: [
  75. {
  76. language: 'javascript',
  77. code: `
  78. import * as Sentry from "@sentry/react";
  79. Sentry.init({
  80. ${sentryInitContent}
  81. });
  82. const container = document.getElementById(“app”);
  83. const root = createRoot(container);
  84. root.render(<App />);
  85. `,
  86. },
  87. ],
  88. },
  89. ];
  90. // Configuration End
  91. export function GettingStartedWithReactReplay({
  92. dsn,
  93. organization,
  94. newOrg,
  95. platformKey,
  96. projectId,
  97. ...props
  98. }: ModuleProps) {
  99. const integrations = replayIntegration.trim();
  100. const otherConfigs = replayOtherConfig.trim();
  101. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  102. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  103. sentryInitContent = sentryInitContent.concat(otherConfigs);
  104. return (
  105. <Layout
  106. steps={steps({
  107. sentryInitContent: sentryInitContent.join('\n'),
  108. organization,
  109. newOrg,
  110. platformKey,
  111. projectId,
  112. })}
  113. newOrg={newOrg}
  114. platformKey={platformKey}
  115. hideHeader
  116. {...props}
  117. />
  118. );
  119. }
  120. export default GettingStartedWithReactReplay;