bun.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  5. import {t} from 'sentry/locale';
  6. import type {Organization, PlatformKey} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. const performanceOtherConfig = `
  15. // Performance Monitoring
  16. tracesSampleRate: 1.0, // Capture 100% of the transactions`;
  17. export const steps = ({
  18. sentryInitContent,
  19. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: t(
  23. "Sentry captures data by using an SDK within your application's runtime."
  24. ),
  25. configurations: [
  26. {
  27. language: 'bash',
  28. code: 'bun add @sentry/bun',
  29. },
  30. ],
  31. },
  32. {
  33. type: StepType.CONFIGURE,
  34. description: t(
  35. "Initialize Sentry as early as possible in your application's lifecycle."
  36. ),
  37. configurations: [
  38. {
  39. language: 'javascript',
  40. code: `
  41. //...
  42. import * as Sentry from "@sentry/bun";
  43. Sentry.init({
  44. ${sentryInitContent}
  45. });
  46. `,
  47. },
  48. ],
  49. },
  50. {
  51. type: StepType.VERIFY,
  52. description: t(
  53. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  54. ),
  55. configurations: [
  56. {
  57. language: 'javascript',
  58. code: `try {
  59. throw new Error('Sentry Bun test');
  60. } catch (e) {
  61. Sentry.captureException(e);
  62. }`,
  63. },
  64. ],
  65. },
  66. ];
  67. export const nextSteps = [
  68. {
  69. id: 'performance-monitoring',
  70. name: t('Performance Monitoring'),
  71. description: t(
  72. 'Track down transactions to connect the dots between 10-second page loads and poor-performing API calls or slow database queries.'
  73. ),
  74. link: 'https://docs.sentry.io/platforms/javascript/guides/bun/performance/',
  75. },
  76. ];
  77. // Configuration End
  78. export function GettingStartedWithBun({
  79. dsn,
  80. activeProductSelection = [],
  81. newOrg,
  82. platformKey,
  83. ...props
  84. }: ModuleProps) {
  85. const integrations: string[] = [];
  86. const otherConfigs: string[] = [];
  87. let nextStepDocs = [...nextSteps];
  88. if (activeProductSelection.includes(ProductSolution.PERFORMANCE_MONITORING)) {
  89. otherConfigs.push(performanceOtherConfig.trim());
  90. nextStepDocs = nextStepDocs.filter(
  91. step => step.id !== ProductSolution.PERFORMANCE_MONITORING
  92. );
  93. }
  94. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  95. if (integrations.length > 0) {
  96. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  97. }
  98. if (otherConfigs.length > 0) {
  99. sentryInitContent = sentryInitContent.concat(otherConfigs);
  100. }
  101. return (
  102. <Layout
  103. steps={steps({
  104. sentryInitContent: sentryInitContent.join('\n'),
  105. })}
  106. nextSteps={nextStepDocs}
  107. platformKey={platformKey}
  108. newOrg={newOrg}
  109. {...props}
  110. />
  111. );
  112. }
  113. export default GettingStartedWithBun;