javascript.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. 'For the Session Replay to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/react]) installed, minimum version 7.27.0.',
  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/browser',
  44. },
  45. {
  46. label: 'yarn',
  47. value: 'yarn',
  48. language: 'bash',
  49. code: 'yarn add @sentry/browser',
  50. },
  51. ],
  52. },
  53. ],
  54. },
  55. {
  56. type: StepType.CONFIGURE,
  57. description: tct(
  58. '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].',
  59. {
  60. code: <code />,
  61. link: (
  62. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/" />
  63. ),
  64. }
  65. ),
  66. configurations: [
  67. {
  68. language: 'javascript',
  69. code: `
  70. import * as Sentry from "@sentry/browser";
  71. Sentry.init({
  72. ${sentryInitContent}
  73. });
  74. `,
  75. },
  76. ],
  77. },
  78. ];
  79. // Configuration End
  80. export function GettingStartedWithJavaScriptReplay({
  81. dsn,
  82. organization,
  83. newOrg,
  84. platformKey,
  85. projectId,
  86. ...props
  87. }: ModuleProps) {
  88. const integrations = replayIntegration.trim();
  89. const otherConfigs = replayOtherConfig.trim();
  90. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  91. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  92. sentryInitContent = sentryInitContent.concat(otherConfigs);
  93. return (
  94. <Layout
  95. steps={steps({
  96. sentryInitContent: sentryInitContent.join('\n'),
  97. organization,
  98. newOrg,
  99. platformKey,
  100. projectId,
  101. })}
  102. platformKey={platformKey}
  103. newOrg={newOrg}
  104. hideHeader
  105. {...props}
  106. />
  107. );
  108. }
  109. export default GettingStartedWithJavaScriptReplay;