svelte.tsx 9.3 KB

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