gcpfunctions.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. // IMPORTANT: Make sure to import and initialize Sentry at the top of your file.
  19. ${getSdkInitSnippet(params, 'gpc')}
  20. // Place any other require/import statements here
  21. // Use wrapHttpFunction to instrument your http functions
  22. exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  23. /* Your function code */
  24. });
  25. // Use wrapEventFunction to instrument your background functions
  26. exports.helloEvents = Sentry.wrapEventFunction(
  27. (data, context, callback) => {
  28. /* Your function code */
  29. }
  30. );
  31. // Use wrapCloudEventFunction to instrument your CloudEvent functions
  32. exports.helloEvents = Sentry.wrapCloudEventFunction(
  33. (context, callback) => {
  34. /* Your function code */
  35. }
  36. );`;
  37. const getVerifySnippet = () => `
  38. exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  39. throw new Error("oh, hello there!");
  40. });`;
  41. const getMetricsConfigureSnippet = (params: DocsParams) => `
  42. Sentry.init({
  43. dsn: "${params.dsn}",
  44. // Only needed for SDK versions < 8.0.0
  45. // _experiments: {
  46. // metricsAggregator: true,
  47. // },
  48. });`;
  49. const onboarding: OnboardingConfig = {
  50. install: params => [
  51. {
  52. type: StepType.INSTALL,
  53. description: tct(
  54. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  55. {code: <code />}
  56. ),
  57. configurations: [
  58. {
  59. language: 'json',
  60. configurations: getInstallConfig(params, {
  61. basePackage: '@sentry/google-cloud-serverless',
  62. }),
  63. },
  64. ],
  65. },
  66. ],
  67. configure: params => [
  68. {
  69. type: StepType.CONFIGURE,
  70. description: tct(
  71. 'Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [require:require] or [import:import] statements. Then, use the Sentry SDK to wrap your functions:',
  72. {
  73. import: <code />,
  74. require: <code />,
  75. }
  76. ),
  77. configurations: [
  78. {
  79. language: 'javascript',
  80. code: getSdkSetupSnippet(params),
  81. },
  82. ],
  83. },
  84. getUploadSourceMapsStep({
  85. guideLink:
  86. 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/sourcemaps/',
  87. ...params,
  88. }),
  89. ],
  90. verify: () => [
  91. {
  92. type: StepType.VERIFY,
  93. description: t(
  94. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  95. ),
  96. configurations: [
  97. {
  98. language: 'javascript',
  99. code: getVerifySnippet(),
  100. },
  101. ],
  102. },
  103. ],
  104. };
  105. const customMetricsOnboarding: OnboardingConfig = {
  106. install: params => [
  107. {
  108. type: StepType.INSTALL,
  109. description: tct(
  110. 'You need a minimum version [codeVersion:8.0.0] of [codePackage:@sentry/google-cloud-serverless]:',
  111. {
  112. codeVersion: <code />,
  113. codePackage: <code />,
  114. }
  115. ),
  116. configurations: getInstallConfig(params, {
  117. basePackage: '@sentry/google-cloud-serverless',
  118. }),
  119. },
  120. ],
  121. configure: params => [
  122. {
  123. type: StepType.CONFIGURE,
  124. description: t(
  125. 'With the default snippet in place, there is no need for any further configuration.'
  126. ),
  127. configurations: [
  128. {
  129. code: getMetricsConfigureSnippet(params),
  130. language: 'javascript',
  131. },
  132. ],
  133. },
  134. ],
  135. verify: getJSServerMetricsOnboarding().verify,
  136. };
  137. const crashReportOnboarding: OnboardingConfig = {
  138. introduction: () => getCrashReportModalIntroduction(),
  139. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  140. configure: () => [
  141. {
  142. type: StepType.CONFIGURE,
  143. description: getCrashReportModalConfigDescription({
  144. link: 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/user-feedback/configuration/#crash-report-modal',
  145. }),
  146. },
  147. ],
  148. verify: () => [],
  149. nextSteps: () => [],
  150. };
  151. const docs: Docs = {
  152. onboarding,
  153. customMetricsOnboarding,
  154. crashReportOnboarding,
  155. };
  156. export default docs;