bun.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. // Only needed for SDK versions < 8.0.0
  46. // _experiments: {
  47. // metricsAggregator: true,
  48. // },
  49. });`;
  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: t(
  120. 'With the default snippet in place, there is no need for any further configuration.'
  121. ),
  122. configurations: [
  123. {
  124. code: getMetricsConfigureSnippet(params),
  125. language: 'javascript',
  126. },
  127. ],
  128. },
  129. ],
  130. verify: () => [
  131. {
  132. type: StepType.VERIFY,
  133. description: tct(
  134. "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.",
  135. {
  136. codeCounters: <code />,
  137. codeSets: <code />,
  138. codeDistribution: <code />,
  139. codeGauge: <code />,
  140. codeNamespace: <code />,
  141. }
  142. ),
  143. configurations: [
  144. {
  145. description: metricTagsExplanation,
  146. },
  147. {
  148. description: t('Try out these examples:'),
  149. code: [
  150. {
  151. label: 'Counter',
  152. value: 'counter',
  153. language: 'javascript',
  154. code: exampleSnippets.javascript.counter,
  155. },
  156. {
  157. label: 'Distribution',
  158. value: 'distribution',
  159. language: 'javascript',
  160. code: exampleSnippets.javascript.distribution,
  161. },
  162. {
  163. label: 'Set',
  164. value: 'set',
  165. language: 'javascript',
  166. code: exampleSnippets.javascript.set,
  167. },
  168. {
  169. label: 'Gauge',
  170. value: 'gauge',
  171. language: 'javascript',
  172. code: exampleSnippets.javascript.gauge,
  173. },
  174. ],
  175. },
  176. {
  177. description: t(
  178. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  179. ),
  180. },
  181. {
  182. description: tct(
  183. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  184. {
  185. docsLink: (
  186. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/bun/metrics/" />
  187. ),
  188. }
  189. ),
  190. },
  191. ],
  192. },
  193. ],
  194. };
  195. const crashReportOnboarding: OnboardingConfig = {
  196. introduction: () => getCrashReportModalIntroduction(),
  197. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  198. configure: () => [
  199. {
  200. type: StepType.CONFIGURE,
  201. description: getCrashReportModalConfigDescription({
  202. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/user-feedback/configuration/#crash-report-modal',
  203. }),
  204. additionalInfo: widgetCallout({
  205. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/user-feedback/#user-feedback-widget',
  206. }),
  207. },
  208. ],
  209. verify: () => [],
  210. nextSteps: () => [],
  211. };
  212. const docs: Docs = {
  213. onboarding,
  214. replayOnboardingJsLoader,
  215. customMetricsOnboarding,
  216. crashReportOnboarding,
  217. };
  218. export default docs;