azurefunctions.tsx 3.7 KB

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