svelte.tsx 8.8 KB

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