gcpfunctions.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.public}",
  44. // Only needed for SDK versions < 8.0.0
  45. // _experiments: {
  46. // metricsAggregator: true,
  47. // },
  48. });`;
  49. const onboarding: OnboardingConfig = {
  50. introduction: () =>
  51. tct('In this quick guide you’ll use [strong:npm] or [strong:yarn] to set up:', {
  52. strong: <strong />,
  53. }),
  54. install: params => [
  55. {
  56. type: StepType.INSTALL,
  57. description: tct(
  58. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  59. {code: <code />}
  60. ),
  61. configurations: [
  62. {
  63. language: 'json',
  64. configurations: getInstallConfig(params, {
  65. basePackage: '@sentry/google-cloud-serverless',
  66. }),
  67. },
  68. ],
  69. },
  70. ],
  71. configure: params => [
  72. {
  73. type: StepType.CONFIGURE,
  74. description: tct(
  75. 'Ensure that Sentry is imported and initialized at the beginning of your file, prior to any other [code:require] or [code:import] statements. Then, use the Sentry SDK to wrap your functions:',
  76. {
  77. code: <code />,
  78. }
  79. ),
  80. configurations: [
  81. {
  82. language: 'javascript',
  83. code: getSdkSetupSnippet(params),
  84. },
  85. ],
  86. },
  87. getUploadSourceMapsStep({
  88. guideLink:
  89. 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/sourcemaps/',
  90. ...params,
  91. }),
  92. ],
  93. verify: () => [
  94. {
  95. type: StepType.VERIFY,
  96. description: t(
  97. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  98. ),
  99. configurations: [
  100. {
  101. language: 'javascript',
  102. code: getVerifySnippet(),
  103. },
  104. ],
  105. },
  106. ],
  107. };
  108. const customMetricsOnboarding: OnboardingConfig = {
  109. install: params => [
  110. {
  111. type: StepType.INSTALL,
  112. description: tct(
  113. 'You need a minimum version [code:8.0.0] of [code:@sentry/google-cloud-serverless]:',
  114. {
  115. code: <code />,
  116. }
  117. ),
  118. configurations: getInstallConfig(params, {
  119. basePackage: '@sentry/google-cloud-serverless',
  120. }),
  121. },
  122. ],
  123. configure: params => [
  124. {
  125. type: StepType.CONFIGURE,
  126. description: t(
  127. 'With the default snippet in place, there is no need for any further configuration.'
  128. ),
  129. configurations: [
  130. {
  131. code: getMetricsConfigureSnippet(params),
  132. language: 'javascript',
  133. },
  134. ],
  135. },
  136. ],
  137. verify: getJSServerMetricsOnboarding().verify,
  138. };
  139. const crashReportOnboarding: OnboardingConfig = {
  140. introduction: () => getCrashReportModalIntroduction(),
  141. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  142. configure: () => [
  143. {
  144. type: StepType.CONFIGURE,
  145. description: getCrashReportModalConfigDescription({
  146. link: 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/user-feedback/configuration/#crash-report-modal',
  147. }),
  148. },
  149. ],
  150. verify: () => [],
  151. nextSteps: () => [],
  152. };
  153. const docs: Docs = {
  154. onboarding,
  155. customMetricsOnboarding,
  156. crashReportOnboarding,
  157. };
  158. export default docs;