gcpfunctions.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. const performanceOtherConfig = `// Performance Monitoring
  15. tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`;
  16. export const steps = ({
  17. sentryInitContent,
  18. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  19. {
  20. type: StepType.INSTALL,
  21. description: (
  22. <p>
  23. {tct(
  24. 'Add the Sentry Serverless SDK as a dependency to your [code:package.json]:',
  25. {code: <code />}
  26. )}
  27. </p>
  28. ),
  29. configurations: [
  30. {
  31. language: 'json',
  32. code: `
  33. dependencies: {
  34. //...
  35. "@sentry/serverless": "^7"
  36. }
  37. `,
  38. },
  39. ],
  40. },
  41. {
  42. title: t('Configure SDK for Http Functions'),
  43. description: (
  44. <p>
  45. {tct('Use [code:wrapHttpFunction] to wrap your http function:', {
  46. code: <code />,
  47. })}
  48. </p>
  49. ),
  50. configurations: [
  51. {
  52. language: 'javascript',
  53. code: `
  54. const Sentry = require("@sentry/serverless");
  55. Sentry.GCPFunction.init({
  56. ${sentryInitContent}
  57. });
  58. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  59. /* Your function code */
  60. });
  61. `,
  62. },
  63. ],
  64. },
  65. {
  66. title: t('Configure SDK for Background Functions'),
  67. description: (
  68. <p>
  69. {tct('Use [code:wrapEventFunction] to wrap your background function:', {
  70. code: <code />,
  71. })}
  72. </p>
  73. ),
  74. configurations: [
  75. {
  76. language: 'javascript',
  77. code: `
  78. const Sentry = require("@sentry/serverless");
  79. Sentry.GCPFunction.init({
  80. ${sentryInitContent}
  81. });
  82. exports.helloEvents = Sentry.GCPFunction.wrapEventFunction(
  83. (data, context, callback) => {
  84. /* Your function code */
  85. }
  86. );
  87. `,
  88. },
  89. ],
  90. },
  91. {
  92. title: t('Configure SDK for CloudEvent Functions'),
  93. description: (
  94. <p>
  95. {tct('Use [code:wrapCloudEventFunction] to wrap your CloudEvent function:', {
  96. code: <code />,
  97. })}
  98. </p>
  99. ),
  100. configurations: [
  101. {
  102. language: 'javascript',
  103. code: `
  104. const Sentry = require("@sentry/serverless");
  105. Sentry.GCPFunction.init({
  106. ${sentryInitContent}
  107. });
  108. exports.helloEvents = Sentry.GCPFunction.wrapCloudEventFunction(
  109. (context, callback) => {
  110. /* Your function code */
  111. }
  112. );
  113. `,
  114. },
  115. ],
  116. },
  117. {
  118. type: StepType.VERIFY,
  119. description: t(
  120. "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
  121. ),
  122. configurations: [
  123. {
  124. language: 'javascript',
  125. code: `
  126. exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  127. throw new Error("oh, hello there!");
  128. });
  129. `,
  130. },
  131. ],
  132. },
  133. ];
  134. export function GettingStartedWithGCPFunctions({dsn, newOrg, platformKey}: ModuleProps) {
  135. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  136. const otherConfigs = [performanceOtherConfig];
  137. if (otherConfigs.length > 0) {
  138. sentryInitContent = sentryInitContent.concat(otherConfigs);
  139. }
  140. return (
  141. <Layout
  142. steps={steps({
  143. sentryInitContent: sentryInitContent.join('\n'),
  144. })}
  145. newOrg={newOrg}
  146. platformKey={platformKey}
  147. />
  148. );
  149. }
  150. export default GettingStartedWithGCPFunctions;