svelte.tsx 9.4 KB

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