svelte.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {t, tct} from 'sentry/locale';
  9. type Params = DocsParams;
  10. const getSdkSetupSnippet = (params: Params) => `
  11. import "./app.css";
  12. import App from "./App.svelte";
  13. import * as Sentry from "@sentry/svelte";
  14. Sentry.init({
  15. dsn: "${params.dsn}",
  16. integrations: [${
  17. params.isPerformanceSelected
  18. ? `
  19. new Sentry.BrowserTracing({
  20. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  21. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],
  22. }),`
  23. : ''
  24. }${
  25. params.isReplaySelected
  26. ? `
  27. new Sentry.Replay(),`
  28. : ''
  29. }
  30. ],${
  31. params.isPerformanceSelected
  32. ? `
  33. // Performance Monitoring
  34. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  35. : ''
  36. }${
  37. params.isReplaySelected
  38. ? `
  39. // Session Replay
  40. 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.
  41. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  42. : ''
  43. }
  44. });
  45. const app = new App({
  46. target: document.getElementById("app"),
  47. });
  48. export default app;
  49. `;
  50. const getVerifySvelteSnippet = () => `
  51. // SomeComponent.svelte
  52. <button type="button" on:click="{unknownFunction}">Break the world</button>`;
  53. const onboarding: OnboardingConfig = {
  54. install: () => [
  55. {
  56. type: StepType.INSTALL,
  57. configurations: [
  58. {
  59. description: tct(
  60. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  61. {
  62. codeYarn: <code />,
  63. codeNpm: <code />,
  64. }
  65. ),
  66. language: 'bash',
  67. code: [
  68. {
  69. label: 'npm',
  70. value: 'npm',
  71. language: 'bash',
  72. code: 'npm install --save @sentry/svelte',
  73. },
  74. {
  75. label: 'yarn',
  76. value: 'yarn',
  77. language: 'bash',
  78. code: 'yarn add @sentry/svelte',
  79. },
  80. ],
  81. },
  82. ],
  83. },
  84. ],
  85. configure: (params: Params) => [
  86. {
  87. type: StepType.CONFIGURE,
  88. description: tct(
  89. "Initialize Sentry as early as possible in your application's lifecycle, usually your Svelte app's entry point ([code:main.ts/js]):",
  90. {code: <code />}
  91. ),
  92. configurations: [
  93. {
  94. code: [
  95. {
  96. label: 'JavaScript',
  97. value: 'javascript',
  98. language: 'javascript',
  99. code: getSdkSetupSnippet(params),
  100. },
  101. ],
  102. },
  103. ],
  104. },
  105. getUploadSourceMapsStep({
  106. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/svelte/sourcemaps/',
  107. }),
  108. ],
  109. verify: () => [
  110. {
  111. type: StepType.VERIFY,
  112. description: t(
  113. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  114. ),
  115. configurations: [
  116. {
  117. code: [
  118. {
  119. label: 'JavaScript',
  120. value: 'javascript',
  121. language: 'javascript',
  122. code: getVerifySvelteSnippet(),
  123. },
  124. ],
  125. },
  126. ],
  127. },
  128. ],
  129. nextSteps: () => [
  130. {
  131. id: 'svelte-features',
  132. name: t('Svelte Features'),
  133. description: t(
  134. 'Learn about our first class integration with the Svelte framework.'
  135. ),
  136. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/features/',
  137. },
  138. {
  139. id: 'performance-monitoring',
  140. name: t('Performance Monitoring'),
  141. description: t(
  142. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  143. ),
  144. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/performance/',
  145. },
  146. {
  147. id: 'session-replay',
  148. name: t('Session Replay'),
  149. description: t(
  150. '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.'
  151. ),
  152. link: 'https://docs.sentry.io/platforms/javascript/guides/svelte/session-replay/',
  153. },
  154. ],
  155. };
  156. const docs: Docs = {
  157. onboarding,
  158. };
  159. export default docs;