sentryReplayInit.tsx 901 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {useEffect} from 'react';
  2. import {Organization} from 'sentry/types';
  3. async function initSentryReplays() {
  4. const {SentryReplay} = await import('@sentry/replay');
  5. const replays = new SentryReplay({
  6. stickySession: true,
  7. });
  8. replays.setup();
  9. }
  10. /**
  11. * Load the Sentry Replay integration based on the feature flag.
  12. *
  13. * Can't use `useOrganization` because it throws on
  14. * `/settings/account/api/auth-token/` because organization is not *immediately*
  15. * set in context
  16. */
  17. export function SentryReplayInit({organization}: {organization: Organization | null}) {
  18. useEffect(() => {
  19. if (process.env.NODE_ENV !== 'production' || process.env.IS_ACCEPTANCE_TEST) {
  20. return;
  21. }
  22. if (!organization) {
  23. return;
  24. }
  25. if (!organization.features.includes('session-replay-sdk')) {
  26. return;
  27. }
  28. initSentryReplays();
  29. }, [organization]);
  30. return null;
  31. }