bun.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getCrashReportJavaScriptInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import exampleSnippets from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsExampleSnippets';
  15. import {metricTagsExplanation} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  16. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  17. import {t, tct} from 'sentry/locale';
  18. type Params = DocsParams;
  19. const getInstallConfig = () => [
  20. {
  21. language: 'bash',
  22. code: 'bun add @sentry/bun',
  23. },
  24. ];
  25. const getConfigureSnippet = (params: Params) => `
  26. //...
  27. import * as Sentry from "@sentry/bun";
  28. Sentry.init({
  29. dsn: "${params.dsn}",${
  30. params.isPerformanceSelected
  31. ? `
  32. // Performance Monitoring
  33. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  34. : ''
  35. }
  36. });`;
  37. const getVerifySnippet = () => `try {
  38. throw new Error('Sentry Bun test');
  39. } catch (e) {
  40. Sentry.captureException(e);
  41. }`;
  42. const getMetricsConfigureSnippet = (params: DocsParams) => `
  43. Sentry.init({
  44. dsn: "${params.dsn}",
  45. _experiments: {
  46. metricsAggregator: true,
  47. },
  48. });`;
  49. const onboarding: OnboardingConfig = {
  50. install: () => [
  51. {
  52. type: StepType.INSTALL,
  53. description: t(
  54. "Sentry captures data by using an SDK within your application's runtime."
  55. ),
  56. configurations: getInstallConfig(),
  57. },
  58. ],
  59. configure: params => [
  60. {
  61. type: StepType.CONFIGURE,
  62. description: t(
  63. "Initialize Sentry as early as possible in your application's lifecycle."
  64. ),
  65. configurations: [
  66. {
  67. language: 'javascript',
  68. code: getConfigureSnippet(params),
  69. },
  70. ],
  71. },
  72. ],
  73. verify: () => [
  74. {
  75. type: StepType.VERIFY,
  76. description: t(
  77. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  78. ),
  79. configurations: [
  80. {
  81. language: 'javascript',
  82. code: getVerifySnippet(),
  83. },
  84. ],
  85. },
  86. ],
  87. nextSteps: params =>
  88. params.isPerformanceSelected
  89. ? []
  90. : [
  91. {
  92. id: 'performance-monitoring',
  93. name: t('Performance Monitoring'),
  94. description: t(
  95. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  96. ),
  97. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/performance/',
  98. },
  99. ],
  100. };
  101. const customMetricsOnboarding: OnboardingConfig = {
  102. install: () => [
  103. {
  104. type: StepType.INSTALL,
  105. description: tct(
  106. 'You need a minimum version [codeVersion:7.91.0] of [codePackage:@sentry/bun].',
  107. {
  108. codeVersion: <code />,
  109. codePackage: <code />,
  110. }
  111. ),
  112. configurations: getInstallConfig(),
  113. },
  114. ],
  115. configure: params => [
  116. {
  117. type: StepType.CONFIGURE,
  118. description: tct(
  119. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  120. {
  121. codeIntegration: <code />,
  122. codeNamespace: <code />,
  123. }
  124. ),
  125. configurations: [
  126. {
  127. code: [
  128. {
  129. label: 'JavaScript',
  130. value: 'javascript',
  131. language: 'javascript',
  132. code: getMetricsConfigureSnippet(params),
  133. },
  134. ],
  135. },
  136. ],
  137. },
  138. ],
  139. verify: () => [
  140. {
  141. type: StepType.VERIFY,
  142. description: tct(
  143. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. These are available under the [codeNamespace:Sentry.metrics] namespace. This API is available in both renderer and main processes.",
  144. {
  145. codeCounters: <code />,
  146. codeSets: <code />,
  147. codeDistribution: <code />,
  148. codeGauge: <code />,
  149. codeNamespace: <code />,
  150. }
  151. ),
  152. configurations: [
  153. {
  154. description: metricTagsExplanation,
  155. },
  156. {
  157. description: t('Try out these examples:'),
  158. code: [
  159. {
  160. label: 'Counter',
  161. value: 'counter',
  162. language: 'javascript',
  163. code: exampleSnippets.javascript.counter,
  164. },
  165. {
  166. label: 'Distribution',
  167. value: 'distribution',
  168. language: 'javascript',
  169. code: exampleSnippets.javascript.distribution,
  170. },
  171. {
  172. label: 'Set',
  173. value: 'set',
  174. language: 'javascript',
  175. code: exampleSnippets.javascript.set,
  176. },
  177. {
  178. label: 'Gauge',
  179. value: 'gauge',
  180. language: 'javascript',
  181. code: exampleSnippets.javascript.gauge,
  182. },
  183. ],
  184. },
  185. {
  186. description: t(
  187. 'With a bit of delay you can see the data appear in the Sentry UI.'
  188. ),
  189. },
  190. {
  191. description: tct(
  192. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  193. {
  194. docsLink: (
  195. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/bun/metrics/" />
  196. ),
  197. }
  198. ),
  199. },
  200. ],
  201. },
  202. ],
  203. };
  204. const crashReportOnboarding: OnboardingConfig = {
  205. introduction: () => getCrashReportModalIntroduction(),
  206. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  207. configure: () => [
  208. {
  209. type: StepType.CONFIGURE,
  210. description: getCrashReportModalConfigDescription({
  211. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/user-feedback/configuration/#crash-report-modal',
  212. }),
  213. additionalInfo: widgetCallout({
  214. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/user-feedback/#user-feedback-widget',
  215. }),
  216. },
  217. ],
  218. verify: () => [],
  219. nextSteps: () => [],
  220. };
  221. const docs: Docs = {
  222. onboarding,
  223. replayOnboardingJsLoader,
  224. customMetricsOnboarding,
  225. crashReportOnboarding,
  226. };
  227. export default docs;