awslambda.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getCrashReportGenericInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  15. import {csharpFeedbackOnboarding} from 'sentry/gettingStartedDocs/dotnet/dotnet';
  16. import {t, tct} from 'sentry/locale';
  17. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  18. type Params = DocsParams;
  19. const getInstallSnippetPackageManager = (params: Params) => `
  20. Install-Package Sentry.AspNetCore -Version ${getPackageVersion(
  21. params,
  22. 'sentry.dotnet.aspnetcore',
  23. '3.34.0'
  24. )}`;
  25. const getInstallSnippetCoreCli = (params: Params) => `
  26. dotnet add package Sentry.AspNetCore -v ${getPackageVersion(
  27. params,
  28. 'sentry.dotnet.aspnetcore',
  29. '3.34.0'
  30. )}`;
  31. const getConfigureSnippet = (params: Params) => `
  32. public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
  33. {
  34. protected override void Init(IWebHostBuilder builder)
  35. {
  36. builder
  37. // Add Sentry
  38. .UseSentry(o =>
  39. {
  40. o.Dsn = "${params.dsn}";
  41. // When configuring for the first time, to see what the SDK is doing:
  42. o.Debug = true;
  43. // Required in Serverless environments
  44. o.FlushOnCompletedRequest = true;${
  45. params.isPerformanceSelected
  46. ? `
  47. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  48. // We recommend adjusting this value in production.
  49. o.TracesSampleRate = 1.0;`
  50. : ''
  51. }
  52. })
  53. .UseStartup<Startup>();
  54. }
  55. }`;
  56. const getVerifySnippet = () => `
  57. [Route("api/[controller]")]
  58. public class BadController
  59. {
  60. [HttpGet]
  61. public string Get() => throw null;
  62. }`;
  63. const onboarding: OnboardingConfig = {
  64. introduction: () =>
  65. tct(
  66. 'Sentry provides an integration with AWS Lambda ASP.NET Core Server through the Sentry.AspNetCore NuGet package.',
  67. {
  68. link: <ExternalLink href="https://www.nuget.org/packages/Sentry.AspNetCore" />,
  69. }
  70. ),
  71. install: params => [
  72. {
  73. type: StepType.INSTALL,
  74. description: t('Add the Sentry dependency:'),
  75. configurations: [
  76. {
  77. partialLoading: params.sourcePackageRegistries.isLoading,
  78. code: [
  79. {
  80. language: 'powershell',
  81. label: 'Package Manager',
  82. value: 'packageManager',
  83. code: getInstallSnippetPackageManager(params),
  84. },
  85. {
  86. language: 'shell',
  87. label: '.NET Core CLI',
  88. value: 'coreCli',
  89. code: getInstallSnippetCoreCli(params),
  90. },
  91. ],
  92. },
  93. {
  94. description: tct(
  95. 'You can combine this integration with a logging library like [strong:log4net, NLog, or Serilog] to include both request data as well as your logs as breadcrumbs. The logging ingrations also capture events when an error is logged.',
  96. {strong: <strong />}
  97. ),
  98. },
  99. ],
  100. },
  101. ],
  102. configure: params => [
  103. {
  104. type: StepType.CONFIGURE,
  105. description: (
  106. <Fragment>
  107. <p>
  108. {tct(
  109. 'All [code:ASP.NET Core] configurations are valid here. But one configuration in particular is relevant.',
  110. {
  111. code: <code />,
  112. }
  113. )}
  114. </p>
  115. <p>
  116. {tct(
  117. '[code:FlushOnCompletedRequest] ensures all events are flushed out. This is because the general ASP.NET Core hooks for when the process is exiting are not guaranteed to run in a serverless environment. This setting ensures that no event is lost if AWS recycles the process.',
  118. {
  119. code: <code />,
  120. }
  121. )}
  122. </p>
  123. </Fragment>
  124. ),
  125. configurations: [
  126. {
  127. language: 'csharp',
  128. code: getConfigureSnippet(params),
  129. },
  130. ],
  131. },
  132. ],
  133. verify: () => [
  134. {
  135. type: StepType.VERIFY,
  136. description: t(
  137. 'You can verify your setup by throwing an exception from a function:'
  138. ),
  139. configurations: [
  140. {
  141. language: 'csharp',
  142. code: getVerifySnippet(),
  143. },
  144. {
  145. language: 'shell',
  146. description: t('And make a request to that lambda:'),
  147. code: 'curl -X GET -I https://url.of.server.aws/api/bad',
  148. },
  149. ],
  150. additionalInfo: tct(
  151. 'Check out the [link:Sentry ASP.NET Core] documentation for the complete set of options.',
  152. {
  153. link: (
  154. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/" />
  155. ),
  156. }
  157. ),
  158. },
  159. ],
  160. };
  161. const crashReportOnboarding: OnboardingConfig = {
  162. introduction: () => getCrashReportModalIntroduction(),
  163. install: (params: Params) => getCrashReportGenericInstallStep(params),
  164. configure: () => [
  165. {
  166. type: StepType.CONFIGURE,
  167. description: getCrashReportModalConfigDescription({
  168. link: 'https://docs.sentry.io/platforms/dotnet/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  169. }),
  170. },
  171. ],
  172. verify: () => [],
  173. nextSteps: () => [],
  174. };
  175. const docs: Docs = {
  176. onboarding,
  177. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  178. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry.AspNetCore'}),
  179. crashReportOnboarding,
  180. };
  181. export default docs;