astro.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  4. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {t, tct} from 'sentry/locale';
  7. import type {Organization, PlatformKey} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. // Configuration Start
  16. const replayIntegration = `
  17. new Sentry.Replay(),
  18. `;
  19. const replayOtherConfig = `
  20. // This sets the sample rate to be 10%. You may want this to be 100% while
  21. // in development and sample at a lower rate in production.
  22. replaysSessionSampleRate: 0.1,
  23. // If the entire session is not sampled, use the below sample rate to sample
  24. // sessions when an error occurs.
  25. replaysOnErrorSampleRate: 1.0,
  26. `;
  27. export const steps = ({
  28. sentryInitContent,
  29. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  30. {
  31. type: StepType.INSTALL,
  32. description: t(
  33. 'The Replay integration is already included with the Sentry Astro SDK.'
  34. ),
  35. configurations: [
  36. {
  37. language: 'bash',
  38. code: [
  39. {
  40. label: 'Bash',
  41. value: 'bash',
  42. language: 'bash',
  43. code: 'npx astro add @sentry/astro',
  44. },
  45. ],
  46. },
  47. ],
  48. },
  49. {
  50. type: StepType.CONFIGURE,
  51. description: tct(
  52. '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].',
  53. {
  54. code: <code />,
  55. link: (
  56. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/" />
  57. ),
  58. }
  59. ),
  60. configurations: [
  61. {
  62. language: 'javascript',
  63. code: `
  64. import * as Sentry from "@sentry/astro";
  65. Sentry.init({
  66. ${sentryInitContent}
  67. });
  68. `,
  69. },
  70. ],
  71. },
  72. ];
  73. // Configuration End
  74. export function GettingStartedWithAstroReplay({
  75. dsn,
  76. organization,
  77. newOrg,
  78. platformKey,
  79. projectId,
  80. ...props
  81. }: ModuleProps) {
  82. const integrations = replayIntegration.trim();
  83. const otherConfigs = replayOtherConfig.trim();
  84. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  85. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  86. sentryInitContent = sentryInitContent.concat(otherConfigs);
  87. return (
  88. <Fragment>
  89. <Layout
  90. steps={steps({
  91. sentryInitContent: sentryInitContent.join('\n'),
  92. organization,
  93. newOrg,
  94. platformKey,
  95. projectId,
  96. })}
  97. platformKey={platformKey}
  98. newOrg={newOrg}
  99. hideHeader
  100. {...props}
  101. />
  102. </Fragment>
  103. );
  104. }
  105. export default GettingStartedWithAstroReplay;