jsLoader.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import styled from '@emotion/styled';
  2. import beautify from 'js-beautify';
  3. import Alert from 'sentry/components/alert';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  6. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  7. import type {
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {
  12. getReplayConfigureDescription,
  13. getReplayJsLoaderSdkSetupSnippet,
  14. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  15. import {t, tct} from 'sentry/locale';
  16. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  17. type Params = DocsParams;
  18. const getInstallConfig = (params: Params) => [
  19. {
  20. type: StepType.INSTALL,
  21. configurations: [
  22. {
  23. description: t('Add this script tag to the top of the page:'),
  24. language: 'html',
  25. code: beautify.html(
  26. `<script src="${params.dsn.cdn}" crossorigin="anonymous"></script>`,
  27. {indent_size: 2, wrap_attributes: 'force-expand-multiline'}
  28. ),
  29. additionalInfo: (
  30. <StyledAlert type="info" showIcon>
  31. {tct(
  32. 'Make sure that Session Replay is enabled in your [link:project settings].',
  33. {
  34. link: (
  35. <ExternalLink
  36. href={normalizeUrl(
  37. `/settings/${params.organization.slug}/projects/${params.projectSlug}/loader-script/`
  38. )}
  39. />
  40. ),
  41. }
  42. )}
  43. </StyledAlert>
  44. ),
  45. },
  46. ],
  47. },
  48. ];
  49. const getVerifySnippet = () => `
  50. <!-- A button to trigger a test error -->
  51. <button id="test-error">Trigger Test Error</button>
  52. <script>
  53. const button = document.getElementById('test-error');
  54. button.addEventListener('click', () => {
  55. throw new Error('This is a test error');
  56. });
  57. </script>`;
  58. const replayOnboardingJsLoader: OnboardingConfig = {
  59. install: (params: Params) => getInstallConfig(params),
  60. configure: (params: Params) => [
  61. {
  62. title: t('Configure Session Replay (Optional)'),
  63. description: getReplayConfigureDescription({
  64. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  65. }),
  66. configurations: [
  67. {
  68. language: 'html',
  69. code: getReplayJsLoaderSdkSetupSnippet(params),
  70. },
  71. ],
  72. collapsible: true,
  73. additionalInfo: <TracePropagationMessage />,
  74. },
  75. ],
  76. verify: () => [
  77. {
  78. type: StepType.VERIFY,
  79. description: t(
  80. 'To verify your Replay setup, trigger an error on your page and watch Sentry capture the event along with a recording of the user interaction.'
  81. ),
  82. configurations: [
  83. {
  84. description: t('You can simulate an error by adding the following code:'),
  85. language: 'html',
  86. code: getVerifySnippet(),
  87. additionalInfo: t(
  88. 'After clicking the button, wait a few moments, and you\'ll see a new session appear on the "Replays" page.'
  89. ),
  90. },
  91. ],
  92. },
  93. ],
  94. nextSteps: () => [],
  95. };
  96. const StyledAlert = styled(Alert)`
  97. margin: 0;
  98. `;
  99. export default replayOnboardingJsLoader;