awslambda.tsx 4.9 KB

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