svelte.tsx 6.0 KB

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