gcpfunctions.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  12. import {t, tct} from 'sentry/locale';
  13. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  14. type Params = DocsParams;
  15. const getInstallSnippetPackageManager = (params: Params) => `
  16. Install-Package Sentry.Google.Cloud.Functions -Version ${getPackageVersion(
  17. params,
  18. 'sentry.dotnet.google-cloud-function',
  19. '3.34.0'
  20. )}`;
  21. const getInstallSnippetCoreCli = (params: Params) => `
  22. dotnet add package Sentry.Google.Cloud.Functions -v ${getPackageVersion(
  23. params,
  24. 'sentry.dotnet.google-cloud-function',
  25. '3.34.0'
  26. )}`;
  27. const getInstallSnippetManual = (params: Params) => `
  28. <ItemGroup>
  29. <PackageReference Include="Sentry.Google.Cloud.Functions" Version="${getPackageVersion(
  30. params,
  31. 'sentry.dotnet.google-cloud-function',
  32. '3.34.0'
  33. )}"/>
  34. </ItemGroup>`;
  35. const getConfigureCSharpSnippet = () => `
  36. // Add the following line:
  37. [assembly: FunctionsStartup(typeof(SentryStartup))]
  38. public class Function : IHttpFunction
  39. {
  40. public Task HandleAsync(HttpContext context)
  41. {
  42. // Your function code here.
  43. }
  44. }`;
  45. const getConfigureJsonSnippet = (params: Params) => `
  46. {
  47. "Sentry": {
  48. "Dsn": "${params.dsn}",
  49. // Sends Cookies, User Id when one is logged on and user IP address to sentry. It's turned off by default.
  50. "SendDefaultPii": true,
  51. // When configuring for the first time, to see what the SDK is doing:
  52. "Debug": true,
  53. // Opt-in for payload submission.
  54. "MaxRequestBodySize": "Always",
  55. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  56. // We recommend adjusting this value in production.
  57. "TracesSampleRate": 1
  58. }
  59. }`;
  60. const getVerifySnippet = () => `
  61. using System.Threading.Tasks;
  62. using Microsoft.AspNetCore.Http;
  63. using Sentry;
  64. public Task HandleAsync(HttpContext context)
  65. {
  66. SentrySdk.CaptureMessage("Hello Sentry");
  67. }`;
  68. const onboarding: OnboardingConfig = {
  69. install: params => [
  70. {
  71. type: StepType.INSTALL,
  72. configurations: [
  73. {
  74. description: tct(
  75. 'Install the [strong:NuGet] package with Package Manager or .NET Core CLI:',
  76. {
  77. strong: <strong />,
  78. }
  79. ),
  80. partialLoading: params.sourcePackageRegistries.isLoading,
  81. code: [
  82. {
  83. language: 'shell',
  84. label: 'Package Manager',
  85. value: 'packageManager',
  86. code: getInstallSnippetPackageManager(params),
  87. },
  88. {
  89. language: 'shell',
  90. label: '.NET Core CLI',
  91. value: 'coreCli',
  92. code: getInstallSnippetCoreCli(params),
  93. },
  94. ],
  95. },
  96. {
  97. language: 'xml',
  98. partialLoading: params.sourcePackageRegistries?.isLoading,
  99. description: t('Or, manually add the Sentry dependency into your csproj file:'),
  100. code: getInstallSnippetManual(params),
  101. },
  102. ],
  103. },
  104. ],
  105. configure: params => [
  106. {
  107. type: StepType.CONFIGURE,
  108. description: tct(
  109. 'Then, add Sentry to the [functionCode:Function] class through [functionStartupCode:FunctionsStartup]:',
  110. {
  111. functionCode: <code />,
  112. functionStartupCode: <code />,
  113. }
  114. ),
  115. configurations: [
  116. {
  117. language: 'csharp',
  118. code: getConfigureCSharpSnippet(),
  119. },
  120. {
  121. language: 'json',
  122. description: (
  123. <p>
  124. {tct(
  125. "Additionally, you'll need to set up your [sentryCode:Sentry] settings on [appsettingsCode:appsettings.json]:",
  126. {sentryCode: <code />, appsettingsCode: <code />}
  127. )}
  128. </p>
  129. ),
  130. code: getConfigureJsonSnippet(params),
  131. },
  132. ],
  133. },
  134. ],
  135. verify: () => [
  136. {
  137. type: StepType.VERIFY,
  138. description: t('To verify your setup, you can capture a message with the SDK:'),
  139. configurations: [
  140. {
  141. language: 'csharp',
  142. code: getVerifySnippet(),
  143. },
  144. ],
  145. },
  146. {
  147. title: t('Samples'),
  148. description: (
  149. <Fragment>
  150. {t(
  151. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  152. )}
  153. <List symbol="bullet">
  154. <ListItem>
  155. {tct('[link:Google Cloud Functions sample]', {
  156. link: (
  157. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples/Sentry.Samples.Google.Cloud.Functions" />
  158. ),
  159. })}
  160. </ListItem>
  161. <ListItem>
  162. {tct(
  163. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  164. {
  165. link: (
  166. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  167. ),
  168. strong: <strong />,
  169. code: <code />,
  170. }
  171. )}
  172. </ListItem>
  173. <ListItem>
  174. {tct('[link:Basic F# sample] [strong:(F#)]', {
  175. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  176. strong: <strong />,
  177. })}
  178. </ListItem>
  179. </List>
  180. </Fragment>
  181. ),
  182. },
  183. ],
  184. };
  185. const docs: Docs = {
  186. onboarding,
  187. customMetricsOnboarding: getDotnetMetricsOnboarding({
  188. packageName: 'Sentry.Google.Cloud.Functions',
  189. }),
  190. };
  191. export default docs;