awslambda.tsx 4.7 KB

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