azurefunctions.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 {t, tct} from 'sentry/locale';
  15. import {getInstallConfig, getSdkInitSnippet} from 'sentry/utils/gettingStartedDocs/node';
  16. type Params = DocsParams;
  17. const getSdkSetupSnippet = (params: Params) => `
  18. "use strict";
  19. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  20. ${getSdkInitSnippet(params, 'node')}
  21. // Place any other require/import statements here
  22. module.exports = async function (context, req) {
  23. try {
  24. await notExistFunction();
  25. } catch (e) {
  26. Sentry.captureException(e);
  27. await Sentry.flush(2000);
  28. }
  29. context.res = {
  30. status: 200,
  31. body: "Hello from Azure Cloud Function!",
  32. };
  33. };
  34. `;
  35. const onboarding: OnboardingConfig = {
  36. introduction: () =>
  37. tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  38. strong: <strong />,
  39. }),
  40. install: params => [
  41. {
  42. type: StepType.INSTALL,
  43. description: t('Add the Sentry Node SDK as a dependency:'),
  44. configurations: getInstallConfig(params),
  45. },
  46. ],
  47. configure: params => [
  48. {
  49. type: StepType.CONFIGURE,
  50. description: tct(
  51. 'Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [code:require] or [code:import] statements.',
  52. {code: <code />}
  53. ),
  54. configurations: [
  55. {
  56. language: 'javascript',
  57. description: tct(
  58. 'Note: You need to call both [code:captureException] and [code:flush] for captured events to be successfully delivered to Sentry.',
  59. {code: <code />}
  60. ),
  61. },
  62. {
  63. language: 'javascript',
  64. code: getSdkSetupSnippet(params),
  65. },
  66. ],
  67. },
  68. getUploadSourceMapsStep({
  69. guideLink:
  70. 'https://docs.sentry.io/platforms/javascript/guides/azure-functions/sourcemaps/',
  71. ...params,
  72. }),
  73. ],
  74. verify: () => [],
  75. };
  76. const crashReportOnboarding: OnboardingConfig = {
  77. introduction: () => getCrashReportModalIntroduction(),
  78. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  79. configure: () => [
  80. {
  81. type: StepType.CONFIGURE,
  82. description: getCrashReportModalConfigDescription({
  83. link: 'https://docs.sentry.io/platforms/javascript/guides/azure-functions/user-feedback/configuration/#crash-report-modal',
  84. }),
  85. },
  86. ],
  87. verify: () => [],
  88. nextSteps: () => [],
  89. };
  90. const docs: Docs = {
  91. onboarding,
  92. customMetricsOnboarding: getJSServerMetricsOnboarding(),
  93. crashReportOnboarding,
  94. };
  95. export default docs;