svelte.tsx 5.6 KB

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