svelte.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. // Configuration Start
  8. const replayIntegration = `
  9. new Sentry.Replay(),
  10. `;
  11. const replayOtherConfig = `
  12. // Session Replay
  13. replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
  14. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
  15. `;
  16. const performanceIntegration = `
  17. new Sentry.BrowserTracing({
  18. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  19. tracePropagationTargets: ["localhost", "https:yourserver.io/api/"],
  20. }),
  21. `;
  22. const performanceOtherConfig = `
  23. // Performance Monitoring
  24. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!
  25. `;
  26. export const steps = ({
  27. sentryInitContent,
  28. }: {
  29. sentryInitContent?: string;
  30. } = {}): LayoutProps['steps'] => [
  31. {
  32. type: StepType.INSTALL,
  33. description: t(
  34. 'Sentry captures data by using an SDK within your application’s runtime.'
  35. ),
  36. configurations: [
  37. {
  38. language: 'bash',
  39. code: `
  40. # Using yarn
  41. yarn add @sentry/svelte
  42. # Using npm
  43. npm install --save @sentry/svelte
  44. `,
  45. },
  46. ],
  47. },
  48. {
  49. type: StepType.CONFIGURE,
  50. description: (
  51. <p>
  52. {tct(
  53. "Initialize Sentry as early as possible in your application's lifecycle, usually your Svelte app's entry point ([code:main.ts/js]):",
  54. {code: <code />}
  55. )}
  56. </p>
  57. ),
  58. configurations: [
  59. {
  60. language: 'javascript',
  61. code: `
  62. import "./app.css";
  63. import App from "./App.svelte";
  64. import * as Sentry from "@sentry/svelte";
  65. Sentry.init({
  66. ${sentryInitContent}
  67. });
  68. const app = new App({
  69. target: document.getElementById("app"),
  70. });
  71. export default app;
  72. `,
  73. },
  74. ],
  75. },
  76. getUploadSourceMapsStep(
  77. 'https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/'
  78. ),
  79. {
  80. type: StepType.VERIFY,
  81. description: t(
  82. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  83. ),
  84. configurations: [
  85. {
  86. language: 'javascript',
  87. code: `
  88. // SomeComponent.svelte
  89. <button type="button" on:click="{unknownFunction}">Break the world</button>
  90. `,
  91. },
  92. ],
  93. },
  94. ];
  95. export const nextSteps = [
  96. {
  97. id: 'svelte-features',
  98. name: t('Svelte Features'),
  99. description: t('Learn about our first class integration with the Svelte framework.'),
  100. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/features/',
  101. },
  102. {
  103. id: 'performance-monitoring',
  104. name: t('Performance Monitoring'),
  105. description: t(
  106. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  107. ),
  108. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/performance/',
  109. },
  110. {
  111. id: 'session-replay',
  112. name: t('Session Replay'),
  113. description: t(
  114. 'Get to the root cause of an error or latency issue faster by seeing all the technical details related to that issue in one visual replay on your web application.'
  115. ),
  116. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/session-replay/',
  117. },
  118. ];
  119. // Configuration End
  120. export function GettingStartedWithSvelte({
  121. dsn,
  122. activeProductSelection = [],
  123. ...props
  124. }: ModuleProps) {
  125. const integrations: string[] = [];
  126. const otherConfigs: string[] = [];
  127. let nextStepDocs = [...nextSteps];
  128. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  129. integrations.push(performanceIntegration.trim());
  130. otherConfigs.push(performanceOtherConfig.trim());
  131. nextStepDocs = nextStepDocs.filter(
  132. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  133. );
  134. }
  135. if (activeProductSelection.includes(ProductSolution.SESSION_REPLAY)) {
  136. integrations.push(replayIntegration.trim());
  137. otherConfigs.push(replayOtherConfig.trim());
  138. nextStepDocs = nextStepDocs.filter(
  139. step => step.id !== ProductSolution.SESSION_REPLAY
  140. );
  141. }
  142. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  143. if (integrations.length > 0) {
  144. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  145. }
  146. if (otherConfigs.length > 0) {
  147. sentryInitContent = sentryInitContent.concat(otherConfigs);
  148. }
  149. return (
  150. <Layout
  151. steps={steps({sentryInitContent: sentryInitContent.join('\n')})}
  152. nextSteps={nextStepDocs}
  153. {...props}
  154. />
  155. );
  156. }
  157. export default GettingStartedWithSvelte;