solid.tsx 9.7 KB

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