svelte.tsx 5.8 KB

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