awslambda.tsx 5.0 KB

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