gcpfunctions.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. getDefaulServerlessImports,
  8. getDefaultInitParams,
  9. getProductInitParams,
  10. getProductIntegrations,
  11. getProductSelectionMap,
  12. joinWithIndentation,
  13. } from 'sentry/utils/gettingStartedDocs/node';
  14. interface StepsParams {
  15. importContent: string;
  16. initContent: string;
  17. installSnippet: string;
  18. sourceMapStep: StepProps;
  19. }
  20. export const steps = ({
  21. installSnippet,
  22. importContent,
  23. initContent,
  24. sourceMapStep,
  25. }: StepsParams): LayoutProps['steps'] => [
  26. {
  27. type: StepType.INSTALL,
  28. description: (
  29. <p>
  30. {tct(
  31. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  32. {code: <code />}
  33. )}
  34. </p>
  35. ),
  36. configurations: [
  37. {
  38. language: 'json',
  39. code: installSnippet,
  40. },
  41. ],
  42. },
  43. {
  44. type: StepType.CONFIGURE,
  45. description: (
  46. <p>
  47. {tct('Use the Sentry SDK to wrap your functions:', {
  48. code: <code />,
  49. })}
  50. </p>
  51. ),
  52. configurations: [
  53. {
  54. language: 'javascript',
  55. code: `
  56. ${importContent}
  57. Sentry.GCPFunction.init({
  58. ${initContent}
  59. });
  60. // Use wrapHttpFunction to instrument your http functions
  61. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  62. /* Your function code */
  63. });
  64. // Use wrapEventFunction to instrument your background functions
  65. exports.helloEvents = Sentry.GCPFunction.wrapEventFunction(
  66. (data, context, callback) => {
  67. /* Your function code */
  68. }
  69. );
  70. // Use wrapCloudEventFunction to instrument your CloudEvent functions
  71. exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction(
  72. (context, callback) => {
  73. /* Your function code */
  74. }
  75. );
  76. `,
  77. },
  78. ],
  79. },
  80. sourceMapStep,
  81. {
  82. type: StepType.VERIFY,
  83. description: t(
  84. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  85. ),
  86. configurations: [
  87. {
  88. language: 'javascript',
  89. code: `
  90. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  91. throw new Error("oh, hello there!");
  92. });
  93. `,
  94. },
  95. ],
  96. },
  97. ];
  98. export function GettingStartedWithGCPFunctions({
  99. dsn,
  100. newOrg,
  101. platformKey,
  102. activeProductSelection = [],
  103. organization,
  104. projectId,
  105. }: ModuleProps) {
  106. const productSelection = getProductSelectionMap(activeProductSelection);
  107. const installSnippet: string[] = [
  108. 'dependencies: {',
  109. ' //...',
  110. ` "@sentry/serverless": "^7",`,
  111. ];
  112. if (productSelection.profiling) {
  113. installSnippet.push(` "@sentry/profiling-node": "^1",`);
  114. }
  115. installSnippet.push(' //...', '}');
  116. const imports = getDefaulServerlessImports({productSelection});
  117. const integrations = getProductIntegrations({productSelection});
  118. const integrationParam =
  119. integrations.length > 0
  120. ? `integrations: [\n${joinWithIndentation(integrations)}\n],`
  121. : null;
  122. const initContent = joinWithIndentation([
  123. ...getDefaultInitParams({dsn}),
  124. ...(integrationParam ? [integrationParam] : []),
  125. ...getProductInitParams({productSelection}),
  126. ]);
  127. return (
  128. <Layout
  129. steps={steps({
  130. installSnippet: installSnippet.join('\n'),
  131. importContent: imports.join('\n'),
  132. initContent,
  133. sourceMapStep: getUploadSourceMapsStep({
  134. guideLink:
  135. 'https://docs.sentry.io/platforms/node/guides/gcp-functions/sourcemaps/',
  136. organization,
  137. platformKey,
  138. projectId,
  139. newOrg,
  140. }),
  141. })}
  142. newOrg={newOrg}
  143. platformKey={platformKey}
  144. />
  145. );
  146. }
  147. export default GettingStartedWithGCPFunctions;