svelte.tsx 5.6 KB

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