svelte.tsx 7.6 KB

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