awslambda.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  46. // We recommend adjusting this value in production.
  47. o.TracesSampleRate = 1.0;
  48. })
  49. .UseStartup<Startup>();
  50. }
  51. }`;
  52. const getVerifySnippet = () => `
  53. [Route("api/[controller]")]
  54. public class BadController
  55. {
  56. [HttpGet]
  57. public string Get() => throw null;
  58. }`;
  59. const onboarding: OnboardingConfig = {
  60. introduction: () =>
  61. tct(
  62. 'Sentry provides an integration with AWS Lambda ASP.NET Core Server through the Sentry.AspNetCore NuGet package.',
  63. {
  64. link: <ExternalLink href="https://www.nuget.org/packages/Sentry.AspNetCore" />,
  65. }
  66. ),
  67. install: params => [
  68. {
  69. type: StepType.INSTALL,
  70. description: t('Add the Sentry dependency:'),
  71. configurations: [
  72. {
  73. partialLoading: params.sourcePackageRegistries.isLoading,
  74. code: [
  75. {
  76. language: 'powershell',
  77. label: 'Package Manager',
  78. value: 'packageManager',
  79. code: getInstallSnippetPackageManager(params),
  80. },
  81. {
  82. language: 'shell',
  83. label: '.NET Core CLI',
  84. value: 'coreCli',
  85. code: getInstallSnippetCoreCli(params),
  86. },
  87. ],
  88. },
  89. ],
  90. additionalInfo: tct(
  91. '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.',
  92. {strong: <strong />}
  93. ),
  94. },
  95. ],
  96. configure: params => [
  97. {
  98. type: StepType.CONFIGURE,
  99. description: (
  100. <Fragment>
  101. <p>
  102. {tct(
  103. 'All [code:ASP.NET Core] configurations are valid here. But one configuration in particular is relevant.',
  104. {
  105. code: <code />,
  106. }
  107. )}
  108. </p>
  109. <p>
  110. {tct(
  111. '[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.',
  112. {
  113. code: <code />,
  114. }
  115. )}
  116. </p>
  117. </Fragment>
  118. ),
  119. configurations: [
  120. {
  121. language: 'csharp',
  122. code: getConfigureSnippet(params),
  123. },
  124. ],
  125. },
  126. ],
  127. verify: () => [
  128. {
  129. type: StepType.VERIFY,
  130. description: t(
  131. 'You can verify your setup by throwing an exception from a function:'
  132. ),
  133. configurations: [
  134. {
  135. language: 'csharp',
  136. code: getVerifySnippet(),
  137. },
  138. {
  139. language: 'shell',
  140. description: t('And make a request to that lambda:'),
  141. code: 'curl -X GET -I https://url.of.server.aws/api/bad',
  142. },
  143. ],
  144. additionalInfo: tct(
  145. 'Check out the [link:Sentry ASP.NET Core] documentation for the complete set of options.',
  146. {
  147. link: (
  148. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/" />
  149. ),
  150. }
  151. ),
  152. },
  153. ],
  154. };
  155. const crashReportOnboarding: OnboardingConfig = {
  156. introduction: () => getCrashReportModalIntroduction(),
  157. install: (params: Params) => getCrashReportGenericInstallStep(params),
  158. configure: () => [
  159. {
  160. type: StepType.CONFIGURE,
  161. description: getCrashReportModalConfigDescription({
  162. link: 'https://docs.sentry.io/platforms/dotnet/guides/aws-lambda/user-feedback/configuration/#crash-report-modal',
  163. }),
  164. },
  165. ],
  166. verify: () => [],
  167. nextSteps: () => [],
  168. };
  169. const docs: Docs = {
  170. onboarding,
  171. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  172. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry.AspNetCore'}),
  173. crashReportOnboarding,
  174. };
  175. export default docs;