jsLoader.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/withDomainRequired';
  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.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/projects/${params.projectSlug}/loader-script/`
  38. )}
  39. />
  40. ),
  41. }
  42. )}
  43. </StyledAlert>
  44. ),
  45. },
  46. ],
  47. },
  48. ];
  49. const replayOnboardingJsLoader: OnboardingConfig = {
  50. install: (params: Params) => getInstallConfig(params),
  51. configure: (params: Params) => [
  52. {
  53. type: StepType.CONFIGURE,
  54. description: getReplayConfigureDescription({
  55. link: 'https://docs.sentry.io/platforms/javascript/session-replay/',
  56. }),
  57. configurations: [
  58. {
  59. language: 'html',
  60. code: getReplayJsLoaderSdkSetupSnippet(params),
  61. },
  62. ],
  63. isOptional: true,
  64. additionalInfo: tracePropagationMessage,
  65. },
  66. ],
  67. verify: () => [],
  68. nextSteps: () => [],
  69. };
  70. const StyledAlert = styled(Alert)`
  71. margin: 0;
  72. `;
  73. export default replayOnboardingJsLoader;