gcpfunctions.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 {ProductSolution} from 'sentry/components/onboarding/productSelection';
  15. import {t, tct} from 'sentry/locale';
  16. import type {ProductSelectionMap} from 'sentry/utils/gettingStartedDocs/node';
  17. import {getDefaulServerlessImports} from 'sentry/utils/gettingStartedDocs/node';
  18. type Params = DocsParams;
  19. const productSelection = (params: Params): ProductSelectionMap => {
  20. return {
  21. [ProductSolution.ERROR_MONITORING]: true,
  22. [ProductSolution.PROFILING]: params.isProfilingSelected,
  23. [ProductSolution.PERFORMANCE_MONITORING]: params.isPerformanceSelected,
  24. [ProductSolution.SESSION_REPLAY]: params.isReplaySelected,
  25. };
  26. };
  27. const getInstallSnippet = (params: Params) => `
  28. dependencies: {
  29. //...
  30. "@sentry/serverless": "^7",${
  31. params.isProfilingSelected
  32. ? `
  33. "@sentry/profiling-node": "^1",`
  34. : ''
  35. }
  36. //...
  37. }`;
  38. const getSdkSetupSnippet = (params: Params) => `
  39. ${getDefaulServerlessImports({productSelection: productSelection(params)}).join('\n')}
  40. Sentry.GCPFunction.init({
  41. dsn: "${params.dsn}",
  42. integrations: [${
  43. params.isProfilingSelected
  44. ? `
  45. nodeProfilingIntegration(),`
  46. : ''
  47. }
  48. ],${
  49. params.isPerformanceSelected
  50. ? `
  51. // Performance Monitoring
  52. tracesSampleRate: 1.0, // Capture 100% of the transactions`
  53. : ''
  54. }${
  55. params.isProfilingSelected
  56. ? `
  57. // Set sampling rate for profiling - this is relative to tracesSampleRate
  58. profilesSampleRate: 1.0,`
  59. : ''
  60. }
  61. });
  62. // Use wrapHttpFunction to instrument your http functions
  63. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  64. /* Your function code */
  65. });
  66. // Use wrapEventFunction to instrument your background functions
  67. exports.helloEvents = Sentry.GCPFunction.wrapEventFunction(
  68. (data, context, callback) => {
  69. /* Your function code */
  70. }
  71. );
  72. // Use wrapCloudEventFunction to instrument your CloudEvent functions
  73. exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction(
  74. (context, callback) => {
  75. /* Your function code */
  76. }
  77. );`;
  78. const getVerifySnippet = () => `
  79. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  80. throw new Error("oh, hello there!");
  81. });`;
  82. const getMetricsConfigureSnippet = (params: DocsParams) => `
  83. Sentry.GCPFunction.init({
  84. dsn: "${params.dsn}",
  85. _experiments: {
  86. metricsAggregator: true,
  87. },
  88. });`;
  89. const onboarding: OnboardingConfig = {
  90. install: params => [
  91. {
  92. type: StepType.INSTALL,
  93. description: tct(
  94. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  95. {code: <code />}
  96. ),
  97. configurations: [
  98. {
  99. language: 'json',
  100. code: getInstallSnippet(params),
  101. },
  102. ],
  103. },
  104. ],
  105. configure: params => [
  106. {
  107. type: StepType.CONFIGURE,
  108. description: tct('Use the Sentry SDK to wrap your functions:', {
  109. code: <code />,
  110. }),
  111. configurations: [
  112. {
  113. language: 'javascript',
  114. code: getSdkSetupSnippet(params),
  115. },
  116. ],
  117. },
  118. getUploadSourceMapsStep({
  119. guideLink:
  120. 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/sourcemaps/',
  121. ...params,
  122. }),
  123. ],
  124. verify: () => [
  125. {
  126. type: StepType.VERIFY,
  127. description: t(
  128. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  129. ),
  130. configurations: [
  131. {
  132. language: 'javascript',
  133. code: getVerifySnippet(),
  134. },
  135. ],
  136. },
  137. ],
  138. };
  139. const customMetricsOnboarding: OnboardingConfig = {
  140. install: params => [
  141. {
  142. type: StepType.INSTALL,
  143. description: tct(
  144. 'You need a minimum version [codeVersion:7.91.0] of [codePackage:@sentry/serverless]:',
  145. {
  146. codeVersion: <code />,
  147. codePackage: <code />,
  148. }
  149. ),
  150. configurations: [{language: 'json', code: getInstallSnippet(params)}],
  151. },
  152. ],
  153. configure: params => [
  154. {
  155. type: StepType.CONFIGURE,
  156. description: tct(
  157. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  158. {
  159. codeIntegration: <code />,
  160. codeNamespace: <code />,
  161. }
  162. ),
  163. configurations: [
  164. {
  165. code: [
  166. {
  167. label: 'JavaScript',
  168. value: 'javascript',
  169. language: 'javascript',
  170. code: getMetricsConfigureSnippet(params),
  171. },
  172. ],
  173. },
  174. ],
  175. },
  176. ],
  177. verify: getJSServerMetricsOnboarding().verify,
  178. };
  179. const crashReportOnboarding: OnboardingConfig = {
  180. introduction: () => getCrashReportModalIntroduction(),
  181. install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
  182. configure: () => [
  183. {
  184. type: StepType.CONFIGURE,
  185. description: getCrashReportModalConfigDescription({
  186. link: 'https://docs.sentry.io/platforms/javascript/guides/gcp-functions/user-feedback/configuration/#crash-report-modal',
  187. }),
  188. },
  189. ],
  190. verify: () => [],
  191. nextSteps: () => [],
  192. };
  193. const docs: Docs = {
  194. onboarding,
  195. customMetricsOnboarding,
  196. crashReportOnboarding,
  197. };
  198. export default docs;