azurefunctions.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  8. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  9. import {t, tct} from 'sentry/locale';
  10. import {
  11. getDefaultNodeImports,
  12. getInstallSnippet,
  13. ProductSelectionMap,
  14. } from 'sentry/utils/gettingStartedDocs/node';
  15. type Params = DocsParams;
  16. const productSelection = (params: Params): ProductSelectionMap => {
  17. return {
  18. [ProductSolution.ERROR_MONITORING]: true,
  19. [ProductSolution.PROFILING]: params.isProfilingSelected,
  20. [ProductSolution.PERFORMANCE_MONITORING]: params.isPerformanceSelected,
  21. [ProductSolution.SESSION_REPLAY]: params.isReplaySelected,
  22. };
  23. };
  24. const getSdkSetupSnippet = (params: Params) => `
  25. "use strict";
  26. ${getDefaultNodeImports({productSelection: productSelection(params)}).join('\n')}
  27. Sentry..init({
  28. dsn: "${params.dsn}",
  29. integrations: [${
  30. params.isProfilingSelected
  31. ? `
  32. new ProfilingIntegration(),`
  33. : ''
  34. }
  35. ],${
  36. params.isPerformanceSelected
  37. ? `
  38. // Performance Monitoring
  39. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  40. : ''
  41. }${
  42. params.isProfilingSelected
  43. ? `
  44. // Set sampling rate for profiling - this is relative to tracesSampleRate
  45. profilesSampleRate: 1.0,`
  46. : ''
  47. }
  48. });
  49. module.exports = async function (context, req) {
  50. try {
  51. await notExistFunction();
  52. } catch (e) {
  53. Sentry.captureException(e);
  54. await Sentry.flush(2000);
  55. }
  56. context.res = {
  57. status: 200,
  58. body: "Hello from Azure Cloud Function!",
  59. };
  60. };
  61. `;
  62. const onboarding: OnboardingConfig = {
  63. install: params => [
  64. {
  65. type: StepType.INSTALL,
  66. description: t('Add the Sentry Node SDK as a dependency:'),
  67. configurations: [
  68. {
  69. code: [
  70. {
  71. label: 'npm',
  72. value: 'npm',
  73. language: 'bash',
  74. code: getInstallSnippet({
  75. productSelection: productSelection(params),
  76. packageManager: 'npm',
  77. }),
  78. },
  79. {
  80. label: 'yarn',
  81. value: 'yarn',
  82. language: 'bash',
  83. code: getInstallSnippet({
  84. productSelection: productSelection(params),
  85. packageManager: 'yarn',
  86. }),
  87. },
  88. ],
  89. },
  90. ],
  91. },
  92. ],
  93. configure: params => [
  94. {
  95. type: StepType.CONFIGURE,
  96. description: t('To set up Sentry error logging for an Azure Function:'),
  97. configurations: [
  98. {
  99. language: 'javascript',
  100. code: getSdkSetupSnippet(params),
  101. },
  102. {
  103. language: 'javascript',
  104. description: tct(
  105. 'Note: You need to call both [captureExceptionCode:captureException] and [flushCode:flush] for captured events to be successfully delivered to Sentry.',
  106. {captureExceptionCode: <code />, flushCode: <code />}
  107. ),
  108. },
  109. ],
  110. },
  111. getUploadSourceMapsStep({
  112. guideLink:
  113. 'https://docs.sentry.io/platforms/node/guides/azure-functions/sourcemaps/',
  114. ...params,
  115. }),
  116. ],
  117. verify: () => [],
  118. };
  119. const docs: Docs = {
  120. onboarding,
  121. };
  122. export default docs;