azurefunctions.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepProps, StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  5. import {t, tct} from 'sentry/locale';
  6. import {
  7. getDefaultInitParams,
  8. getDefaultNodeImports,
  9. getInstallSnippet,
  10. getProductInitParams,
  11. getProductIntegrations,
  12. getProductSelectionMap,
  13. joinWithIndentation,
  14. } from 'sentry/utils/gettingStartedDocs/node';
  15. interface StepsParams {
  16. importContent: string;
  17. initContent: string;
  18. installSnippet: string;
  19. sourceMapStep: StepProps;
  20. }
  21. export const steps = ({
  22. installSnippet,
  23. importContent,
  24. initContent,
  25. sourceMapStep,
  26. }: StepsParams): LayoutProps['steps'] => [
  27. {
  28. type: StepType.INSTALL,
  29. description: t('Add the Sentry Node SDK as a dependency:'),
  30. configurations: [
  31. {
  32. language: 'bash',
  33. code: installSnippet,
  34. },
  35. ],
  36. },
  37. {
  38. type: StepType.CONFIGURE,
  39. description: t('To set up Sentry error logging for an Azure Function:'),
  40. configurations: [
  41. {
  42. language: 'javascript',
  43. code: `
  44. "use strict";
  45. ${importContent}
  46. Sentry.init({
  47. ${initContent}
  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. },
  63. {
  64. language: 'javascript',
  65. description: (
  66. <p>
  67. {tct(
  68. 'Note: You need to call both [captureExceptionCode:captureException] and [flushCode:flush] for captured events to be successfully delivered to Sentry.',
  69. {captureExceptionCode: <code />, flushCode: <code />}
  70. )}
  71. </p>
  72. ),
  73. },
  74. ],
  75. },
  76. sourceMapStep,
  77. ];
  78. export function GettingStartedWithAzurefunctions({
  79. dsn,
  80. newOrg,
  81. platformKey,
  82. activeProductSelection = [],
  83. organization,
  84. projectId,
  85. ...props
  86. }: ModuleProps) {
  87. const productSelection = getProductSelectionMap(activeProductSelection);
  88. const installSnippet = getInstallSnippet({productSelection});
  89. const imports = getDefaultNodeImports({productSelection});
  90. const integrations = getProductIntegrations({productSelection});
  91. const integrationParam =
  92. integrations.length > 0
  93. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  94. : null;
  95. const initContent = joinWithIndentation([
  96. ...getDefaultInitParams({dsn}),
  97. ...(integrationParam ? [integrationParam] : []),
  98. ...getProductInitParams({productSelection}),
  99. ]);
  100. return (
  101. <Layout
  102. steps={steps({
  103. installSnippet,
  104. importContent: imports.join('\n'),
  105. initContent,
  106. sourceMapStep: getUploadSourceMapsStep({
  107. guideLink:
  108. 'https://docs.sentry.io/platforms/node/guides/azure-functions/sourcemaps/',
  109. organization,
  110. platformKey,
  111. projectId,
  112. newOrg,
  113. }),
  114. })}
  115. newOrg={newOrg}
  116. platformKey={platformKey}
  117. {...props}
  118. />
  119. );
  120. }
  121. export default GettingStartedWithAzurefunctions;