bun.tsx 6.5 KB

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