svelte.tsx 5.6 KB

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