azurefunctions.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  2. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import {PlatformKey} from 'sentry/data/platformCategories';
  5. import {t, tct} from 'sentry/locale';
  6. import type {Organization} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. export const steps = ({
  15. sentryInitContent,
  16. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  17. {
  18. type: StepType.INSTALL,
  19. description: (
  20. <p>{tct('Add [code:@sentry/node] as a dependency:', {code: <code />})}</p>
  21. ),
  22. configurations: [
  23. {
  24. language: 'bash',
  25. code: `
  26. # Using yarn
  27. yarn add @sentry/node
  28. # Using npm
  29. npm install --save @sentry/node
  30. `,
  31. },
  32. ],
  33. },
  34. {
  35. type: StepType.CONFIGURE,
  36. description: t('To set up Sentry error logging for an Azure Function:'),
  37. configurations: [
  38. {
  39. language: 'javascript',
  40. code: `
  41. "use strict";
  42. const Sentry = require("@sentry/node");
  43. Sentry.init({
  44. ${sentryInitContent},
  45. });
  46. module.exports = async function (context, req) {
  47. try {
  48. await notExistFunction();
  49. } catch (e) {
  50. Sentry.captureException(e);
  51. await Sentry.flush(2000);
  52. }
  53. context.res = {
  54. status: 200,
  55. body: "Hello from Azure Cloud Function!",
  56. };
  57. };
  58. `,
  59. },
  60. {
  61. language: 'javascript',
  62. description: (
  63. <p>
  64. {tct(
  65. 'Note: You need to call both [captureExceptionCode:captureException] and [flushCode:flush] for captured events to be successfully delivered to Sentry.',
  66. {captureExceptionCode: <code />, flushCode: <code />}
  67. )}
  68. </p>
  69. ),
  70. },
  71. ],
  72. },
  73. ];
  74. export function GettingStartedWithAzurefunctions({
  75. dsn,
  76. organization,
  77. newOrg,
  78. platformKey,
  79. projectId,
  80. }: ModuleProps) {
  81. const sentryInitContent: string[] = [`dsn: "${dsn}"`];
  82. return (
  83. <Layout
  84. steps={steps({
  85. sentryInitContent: sentryInitContent.join('\n'),
  86. organization,
  87. newOrg,
  88. platformKey,
  89. projectId,
  90. })}
  91. newOrg={newOrg}
  92. platformKey={platformKey}
  93. />
  94. );
  95. }
  96. export default GettingStartedWithAzurefunctions;