svelte.tsx 9.5 KB

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