solid.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 * as Sentry from "@sentry/solid";
  33. import { render } from "solid-js/web";
  34. import App from "./app";
  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 root = document.getElementById("root");
  89. if (import.meta.env.DEV && !(root instanceof HTMLElement)) {
  90. throw new Error(
  91. "Root element not found. Did you forget to add it to your index.html? Or maybe the id attribute got misspelled?"
  92. );
  93. }
  94. render(() => <App />, root);
  95. `;
  96. const getVerifySnippet = () => `
  97. <button
  98. type="button"
  99. onClick={() => {
  100. throw new Error("Sentry Frontend Error");
  101. }}
  102. >
  103. Throw error
  104. </button>`;
  105. const getInstallConfig = () => [
  106. {
  107. language: 'bash',
  108. code: [
  109. {
  110. label: 'npm',
  111. value: 'npm',
  112. language: 'bash',
  113. code: 'npm install --save @sentry/solid',
  114. },
  115. {
  116. label: 'yarn',
  117. value: 'yarn',
  118. language: 'bash',
  119. code: 'yarn add @sentry/solid',
  120. },
  121. ],
  122. },
  123. ];
  124. const onboarding: OnboardingConfig = {
  125. introduction: params => (
  126. <Fragment>
  127. <MaybeBrowserProfilingBetaWarning {...params} />
  128. <p>
  129. {tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  130. strong: <strong />,
  131. })}
  132. </p>
  133. </Fragment>
  134. ),
  135. install: () => [
  136. {
  137. type: StepType.INSTALL,
  138. description: tct(
  139. 'Add the Sentry SDK as a dependency using [code:npm] or [code:yarn]:',
  140. {
  141. code: <code />,
  142. }
  143. ),
  144. configurations: getInstallConfig(),
  145. },
  146. ],
  147. configure: (params: Params) => [
  148. {
  149. type: StepType.CONFIGURE,
  150. description: tct(
  151. "Initialize Sentry as early as possible in your application's lifecycle, usually your solid app's entry point ([code:main.ts/js]):",
  152. {code: <code />}
  153. ),
  154. configurations: [
  155. {
  156. code: [
  157. {
  158. label: 'JavaScript',
  159. value: 'javascript',
  160. language: 'javascript',
  161. code: getSdkSetupSnippet(params),
  162. },
  163. ],
  164. },
  165. ...(params.isProfilingSelected
  166. ? [getProfilingDocumentHeaderConfigurationStep()]
  167. : []),
  168. ],
  169. },
  170. getUploadSourceMapsStep({
  171. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/solid/sourcemaps/',
  172. ...params,
  173. }),
  174. ],
  175. verify: () => [
  176. {
  177. type: StepType.VERIFY,
  178. description: t(
  179. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  180. ),
  181. configurations: [
  182. {
  183. code: [
  184. {
  185. label: 'JavaScript',
  186. value: 'javascript',
  187. language: 'javascript',
  188. code: getVerifySnippet(),
  189. },
  190. ],
  191. },
  192. ],
  193. },
  194. ],
  195. nextSteps: () => [
  196. {
  197. id: 'solid-features',
  198. name: t('Solid Features'),
  199. description: t('Learn about our first class integration with the Solid framework.'),
  200. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/features/',
  201. },
  202. ],
  203. };
  204. const replayOnboarding: OnboardingConfig = {
  205. install: () => [
  206. {
  207. type: StepType.INSTALL,
  208. description: tct(
  209. 'You need a minimum version 8.9.1 of [code:@sentry/solid] in order to use Session Replay. You do not need to install any additional packages.',
  210. {
  211. code: <code />,
  212. }
  213. ),
  214. configurations: getInstallConfig(),
  215. },
  216. ],
  217. configure: (params: Params) => [
  218. {
  219. type: StepType.CONFIGURE,
  220. description: getReplayConfigureDescription({
  221. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/session-replay/',
  222. }),
  223. configurations: [
  224. {
  225. code: [
  226. {
  227. label: 'JavaScript',
  228. value: 'javascript',
  229. language: 'javascript',
  230. code: getSdkSetupSnippet(params),
  231. },
  232. ],
  233. additionalInfo: <TracePropagationMessage />,
  234. },
  235. ],
  236. },
  237. ],
  238. verify: getReplayVerifyStep(),
  239. nextSteps: () => [],
  240. };
  241. const feedbackOnboarding: OnboardingConfig = {
  242. install: () => [
  243. {
  244. type: StepType.INSTALL,
  245. description: tct(
  246. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/solid]) installed, minimum version 7.85.0.',
  247. {
  248. code: <code />,
  249. }
  250. ),
  251. configurations: getInstallConfig(),
  252. },
  253. ],
  254. configure: (params: Params) => [
  255. {
  256. type: StepType.CONFIGURE,
  257. description: getFeedbackConfigureDescription({
  258. linkConfig:
  259. 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/configuration/',
  260. linkButton:
  261. 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/configuration/#bring-your-own-button',
  262. }),
  263. configurations: [
  264. {
  265. code: [
  266. {
  267. label: 'JavaScript',
  268. value: 'javascript',
  269. language: 'javascript',
  270. code: getSdkSetupSnippet(params),
  271. },
  272. ],
  273. },
  274. ],
  275. additionalInfo: crashReportCallout({
  276. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/#crash-report-modal',
  277. }),
  278. },
  279. ],
  280. verify: () => [],
  281. nextSteps: () => [],
  282. };
  283. const crashReportOnboarding: OnboardingConfig = {
  284. introduction: () => getCrashReportModalIntroduction(),
  285. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  286. configure: () => [
  287. {
  288. type: StepType.CONFIGURE,
  289. description: getCrashReportModalConfigDescription({
  290. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/configuration/#crash-report-modal',
  291. }),
  292. additionalInfo: widgetCallout({
  293. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/#user-feedback-widget',
  294. }),
  295. },
  296. ],
  297. verify: () => [],
  298. nextSteps: () => [],
  299. };
  300. const profilingOnboarding: OnboardingConfig = {
  301. ...onboarding,
  302. introduction: params => <MaybeBrowserProfilingBetaWarning {...params} />,
  303. };
  304. const docs: Docs = {
  305. onboarding,
  306. feedbackOnboardingNpm: feedbackOnboarding,
  307. replayOnboarding,
  308. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  309. crashReportOnboarding,
  310. profilingOnboarding,
  311. };
  312. export default docs;