bun.tsx 3.2 KB

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