bun.tsx 5.9 KB

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