azurefunctions.tsx 3.0 KB

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