awslambda.tsx 5.6 KB

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