awslambda.tsx 4.0 KB

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