awslambda.tsx 4.7 KB

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