solidstart.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. import ExternalLink from 'sentry/components/links/externalLink';
  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 {
  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. getProfilingDocumentHeaderConfigurationStep,
  21. MaybeBrowserProfilingBetaWarning,
  22. } from 'sentry/components/onboarding/gettingStartedDoc/utils/profilingOnboarding';
  23. import {
  24. getReplayConfigOptions,
  25. getReplayConfigureDescription,
  26. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  27. import {t, tct} from 'sentry/locale';
  28. type Params = DocsParams;
  29. const getSdkClientSetupSnippet = (params: Params) => `
  30. import * as Sentry from "@sentry/solidstart";
  31. ${params.isPerformanceSelected ? 'import { solidRouterBrowserTracingIntegration } from "@sentry/solidstart/solidrouter";' : ''}
  32. import { mount, StartClient } from "@solidjs/start/client";
  33. Sentry.init({
  34. dsn: "${params.dsn.public}",
  35. integrations: [${
  36. params.isPerformanceSelected
  37. ? `
  38. solidRouterBrowserTracingIntegration(),`
  39. : ''
  40. }${
  41. params.isProfilingSelected
  42. ? `
  43. Sentry.browserProfilingIntegration(),`
  44. : ''
  45. }${
  46. params.isFeedbackSelected
  47. ? `
  48. Sentry.feedbackIntegration({
  49. // Additional SDK configuration goes in here, for example:
  50. colorScheme: "system",
  51. ${getFeedbackConfigOptions(params.feedbackOptions)}}),`
  52. : ''
  53. }${
  54. params.isReplaySelected
  55. ? `
  56. Sentry.replayIntegration(${getReplayConfigOptions(params.replayOptions)}),`
  57. : ''
  58. }
  59. ],${
  60. params.isPerformanceSelected
  61. ? `
  62. // Performance Monitoring
  63. tracesSampleRate: 1.0, // Capture 100% of the transactions
  64. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  65. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  66. : ''
  67. }${
  68. params.isReplaySelected
  69. ? `
  70. // Session Replay
  71. 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.
  72. replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.`
  73. : ''
  74. }${
  75. params.isProfilingSelected
  76. ? `
  77. // Set profilesSampleRate to 1.0 to profile every transaction.
  78. // Since profilesSampleRate is relative to tracesSampleRate,
  79. // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  80. // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  81. // results in 25% of transactions being profiled (0.5*0.5=0.25)
  82. profilesSampleRate: 1.0,`
  83. : ''
  84. }
  85. });
  86. mount(() => <StartClient />, document.getElementById("app"));
  87. `;
  88. const getSdkServerSetupSnippet = (params: Params) => `
  89. import * as Sentry from "@sentry/solidstart";
  90. Sentry.init({
  91. dsn: "__PUBLIC_DSN__",
  92. ${
  93. params.isPerformanceSelected
  94. ? `
  95. // Performance Monitoring
  96. tracesSampleRate: 1.0, // Capture 100% of the transactions
  97. // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
  98. tracePropagationTargets: ["localhost", /^https:\\/\\/yourserver\\.io\\/api/],`
  99. : ''
  100. }${
  101. params.isProfilingSelected
  102. ? `
  103. // Set profilesSampleRate to 1.0 to profile every transaction.
  104. // Since profilesSampleRate is relative to tracesSampleRate,
  105. // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  106. // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  107. // results in 25% of transactions being profiled (0.5*0.5=0.25)
  108. profilesSampleRate: 1.0,`
  109. : ''
  110. }
  111. });
  112. `;
  113. const getSdkMiddlewareSetup = () => `
  114. import { sentryBeforeResponseMiddleware } from '@sentry/solidstart/middleware';
  115. import { createMiddleware } from '@solidjs/start/middleware';
  116. export default createMiddleware({
  117. onBeforeResponse: [
  118. sentryBeforeResponseMiddleware(),
  119. // Add your other middleware handlers after \`sentryBeforeResponseMiddleware\`
  120. ],
  121. });
  122. `;
  123. const getSdkRouterWrappingSetup = () => `
  124. import { Router } from "@solidjs/router";
  125. import { FileRoutes } from "@solidjs/start/router";
  126. import { withSentryRouterRouting } from "@sentry/solidstart/solidrouter";
  127. const SentryRouter = withSentryRouterRouting(Router);
  128. export default function App() {
  129. return (
  130. <SentryRouter>
  131. <FileRoutes />
  132. </SentryRouter>
  133. );
  134. }
  135. `;
  136. const getSdkRun = () => `
  137. {
  138. "scripts": {
  139. "start": "NODE_OPTIONS='--import ./public/instrument.server.mjs' vinxi start"
  140. }
  141. }
  142. `;
  143. const getVerifySolidSnippet = () => `
  144. <button
  145. type="button"
  146. onClick={() => {
  147. throw new Error("Sentry Frontend Error");
  148. }}
  149. >
  150. Throw error
  151. </button>`;
  152. const getInstallConfig = () => [
  153. {
  154. language: 'bash',
  155. code: [
  156. {
  157. label: 'npm',
  158. value: 'npm',
  159. language: 'bash',
  160. code: 'npm install --save @sentry/solidstart',
  161. },
  162. {
  163. label: 'yarn',
  164. value: 'yarn',
  165. language: 'bash',
  166. code: 'yarn add @sentry/solidstart',
  167. },
  168. {
  169. label: 'pnpm',
  170. value: 'pnpm',
  171. language: 'bash',
  172. code: `pnpm add @sentry/solidstart`,
  173. },
  174. ],
  175. },
  176. ];
  177. const onboarding: OnboardingConfig = {
  178. introduction: MaybeBrowserProfilingBetaWarning,
  179. install: () => [
  180. {
  181. type: StepType.INSTALL,
  182. description: tct(
  183. 'Add the Sentry SDK as a dependency using [codeNpm:npm] or [codeYarn:yarn]:',
  184. {
  185. codeYarn: <code />,
  186. codeNpm: <code />,
  187. }
  188. ),
  189. configurations: getInstallConfig(),
  190. },
  191. ],
  192. configure: (params: Params) => [
  193. {
  194. type: StepType.CONFIGURE,
  195. description: t(
  196. "Initialize Sentry as early as possible in your application's lifecycle."
  197. ),
  198. configurations: [
  199. {
  200. description: tct(
  201. 'For the client, initialize the Sentry SDK in your [code:src/entry-client.tsx] file',
  202. {code: <code />}
  203. ),
  204. code: [
  205. {
  206. label: 'TypeScript',
  207. // value and language are in JS to get consistent syntax highlighting
  208. // we aren't using any Typescript specific code in these snippets but
  209. // want a typescript ending.
  210. value: 'javascript',
  211. language: 'javascript',
  212. code: getSdkClientSetupSnippet(params),
  213. },
  214. ],
  215. },
  216. {
  217. description: tct(
  218. 'For the server, create an instrument file [codeFile:instrument.server.mjs], initialize the Sentry SDK and deploy it alongside your application. For example by placing it in the [codeFolder:public] folder.',
  219. {codeFile: <code />, codeFolder: <code />}
  220. ),
  221. code: [
  222. {
  223. label: 'JavaScript',
  224. value: 'javascript',
  225. language: 'javascript',
  226. code: getSdkServerSetupSnippet(params),
  227. },
  228. ],
  229. additionalInfo: tct(
  230. 'Note: Placing [codeFile:instrument.server.mjs] inside the [codeFolder:public] folder makes it accessible to the outside world. Consider blocking requests to this file or finding a more appropriate location which your backend can access.',
  231. {codeFile: <code />, codeFolder: <code />}
  232. ),
  233. },
  234. ...(params.isPerformanceSelected
  235. ? [
  236. {
  237. description: tct(
  238. 'Complete the setup by adding the Sentry middleware to your [code:src/middleware.ts] file',
  239. {code: <code />}
  240. ),
  241. code: [
  242. {
  243. label: 'TypeScript',
  244. // value and language are in JS to get consistent syntax highlighting
  245. // we aren't using any Typescript specific code in these snippets but
  246. // want a typescript ending.
  247. value: 'javascript',
  248. language: 'javascript',
  249. code: getSdkMiddlewareSetup(),
  250. },
  251. ],
  252. },
  253. {
  254. description: tct(
  255. "If you're using [solidRouterLink:Solid Router], wrap your [codeRouter:Router] with [codeRouterWrapping:withSentryRouterRouting]. This creates a higher order component, which will enable Sentry to collect navigation spans.",
  256. {
  257. codeRouter: <code />,
  258. codeRouterWrapping: <code />,
  259. solidRouterLink: (
  260. <ExternalLink href="https://docs.solidjs.com/solid-router" />
  261. ),
  262. }
  263. ),
  264. code: [
  265. {
  266. label: 'TypeScript',
  267. value: 'typescript',
  268. language: 'typescript',
  269. code: getSdkRouterWrappingSetup(),
  270. },
  271. ],
  272. },
  273. ]
  274. : []),
  275. ...(params.isProfilingSelected
  276. ? [getProfilingDocumentHeaderConfigurationStep()]
  277. : []),
  278. {
  279. description: tct(
  280. 'Add an [codeFlag:--import] flag to the [codeNodeOptions:NODE_OPTIONS] environment variable wherever you run your application to import [codeInstrument:public/instrument.server.mjs]. For example, update your [codeScripts:scripts] entry in [codePackageJson:package.json]',
  281. {
  282. codeFlag: <code />,
  283. codeNodeOptions: <code />,
  284. codeInstrument: <code />,
  285. codeScripts: <code />,
  286. codePackageJson: <code />,
  287. }
  288. ),
  289. code: [
  290. {
  291. label: 'JSON',
  292. value: 'json',
  293. language: 'json',
  294. code: getSdkRun(),
  295. },
  296. ],
  297. },
  298. ],
  299. },
  300. {
  301. title: t('Upload Source Maps'),
  302. description: tct(
  303. 'To upload source maps to Sentry, follow the [link:instructions in our documentation].',
  304. {
  305. link: (
  306. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/solidstart/#add-readable-stack-traces-to-errors" />
  307. ),
  308. }
  309. ),
  310. },
  311. ],
  312. verify: () => [
  313. {
  314. type: StepType.VERIFY,
  315. description: t(
  316. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  317. ),
  318. configurations: [
  319. {
  320. code: [
  321. {
  322. label: 'JavaScript',
  323. value: 'javascript',
  324. language: 'javascript',
  325. code: getVerifySolidSnippet(),
  326. },
  327. ],
  328. },
  329. ],
  330. },
  331. ],
  332. nextSteps: () => [
  333. {
  334. id: 'solid-features',
  335. name: t('Solid Features'),
  336. description: t('Learn about our first class integration with the Solid framework.'),
  337. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/features/',
  338. },
  339. {
  340. id: 'performance-monitoring',
  341. name: t('Performance Monitoring'),
  342. description: t(
  343. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  344. ),
  345. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/tracing/',
  346. },
  347. {
  348. id: 'session-replay',
  349. name: t('Session Replay'),
  350. description: t(
  351. '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.'
  352. ),
  353. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/session-replay/',
  354. },
  355. ],
  356. };
  357. const replayOnboarding: OnboardingConfig = {
  358. install: () => [
  359. {
  360. type: StepType.INSTALL,
  361. description: tct(
  362. '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.',
  363. {
  364. code: <code />,
  365. }
  366. ),
  367. configurations: getInstallConfig(),
  368. },
  369. ],
  370. configure: (params: Params) => [
  371. {
  372. type: StepType.CONFIGURE,
  373. description: getReplayConfigureDescription({
  374. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/session-replay/',
  375. }),
  376. configurations: [
  377. {
  378. code: [
  379. {
  380. label: 'JavaScript',
  381. value: 'javascript',
  382. language: 'javascript',
  383. code: getSdkClientSetupSnippet(params),
  384. },
  385. ],
  386. additionalInfo: <TracePropagationMessage />,
  387. },
  388. ],
  389. },
  390. ],
  391. verify: () => [],
  392. nextSteps: () => [],
  393. };
  394. const feedbackOnboarding: OnboardingConfig = {
  395. install: () => [
  396. {
  397. type: StepType.INSTALL,
  398. description: tct(
  399. '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.',
  400. {
  401. code: <code />,
  402. }
  403. ),
  404. configurations: getInstallConfig(),
  405. },
  406. ],
  407. configure: (params: Params) => [
  408. {
  409. type: StepType.CONFIGURE,
  410. description: getFeedbackConfigureDescription({
  411. linkConfig:
  412. 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/configuration/',
  413. linkButton:
  414. 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/configuration/#bring-your-own-button',
  415. }),
  416. configurations: [
  417. {
  418. code: [
  419. {
  420. label: 'JavaScript',
  421. value: 'javascript',
  422. language: 'javascript',
  423. code: getSdkClientSetupSnippet(params),
  424. },
  425. ],
  426. },
  427. ],
  428. additionalInfo: crashReportCallout({
  429. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/#crash-report-modal',
  430. }),
  431. },
  432. ],
  433. verify: () => [],
  434. nextSteps: () => [],
  435. };
  436. const crashReportOnboarding: OnboardingConfig = {
  437. introduction: () => getCrashReportModalIntroduction(),
  438. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  439. configure: () => [
  440. {
  441. type: StepType.CONFIGURE,
  442. description: getCrashReportModalConfigDescription({
  443. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/configuration/#crash-report-modal',
  444. }),
  445. additionalInfo: widgetCallout({
  446. link: 'https://docs.sentry.io/platforms/javascript/guides/solid/user-feedback/#user-feedback-widget',
  447. }),
  448. },
  449. ],
  450. verify: () => [],
  451. nextSteps: () => [],
  452. };
  453. const docs: Docs = {
  454. onboarding,
  455. feedbackOnboardingNpm: feedbackOnboarding,
  456. replayOnboardingNpm: replayOnboarding,
  457. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  458. crashReportOnboarding,
  459. };
  460. export default docs;