aspnet.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Alert} from 'sentry/components/alert';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import List from 'sentry/components/list';
  6. import ListItem from 'sentry/components/list/listItem';
  7. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  8. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  9. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  10. import {t, tct} from 'sentry/locale';
  11. // Configuration Start
  12. export const steps = ({
  13. dsn,
  14. }: {
  15. dsn?: string;
  16. } = {}): LayoutProps['steps'] => [
  17. {
  18. type: StepType.INSTALL,
  19. description: (
  20. <p>
  21. {tct('Install the [strong:NuGet] package:', {
  22. strong: <strong />,
  23. })}
  24. </p>
  25. ),
  26. configurations: [
  27. {
  28. language: 'shell',
  29. description: t('Package Manager:'),
  30. code: 'Install-Package Sentry.AspNet -Version 3.34.0',
  31. },
  32. {
  33. language: 'shell',
  34. description: t('Using Entity Framework 6?'),
  35. code: 'Install-Package Sentry.EntityFramework -Version 3.34.0',
  36. },
  37. ],
  38. additionalInfo: (
  39. <AlertWithoutMarginBottom type="info">
  40. {tct(
  41. '[strong:Using .NET Framework prior to 4.6.1?] Our legacy SDK supports .NET Framework as early as 3.5.',
  42. {strong: <strong />}
  43. )}
  44. </AlertWithoutMarginBottom>
  45. ),
  46. },
  47. {
  48. type: StepType.CONFIGURE,
  49. description: (
  50. <p>
  51. {tct(
  52. 'You should [initCode:init] the Sentry SDK as soon as possible during your application load by adding Sentry to [globalCode:Global.asax.cs]:',
  53. {
  54. initCode: <code />,
  55. globalCode: <code />,
  56. }
  57. )}
  58. </p>
  59. ),
  60. configurations: [
  61. {
  62. language: 'csharp',
  63. code: `
  64. using System;
  65. using System.Configuration;
  66. using System.Web.Mvc;
  67. using System.Web.Routing;
  68. using Sentry;
  69. using Sentry.AspNet;
  70. using Sentry.EntityFramework; // if you installed Sentry.EntityFramework
  71. public class MvcApplication : HttpApplication
  72. {
  73. private IDisposable _sentry;
  74. protected void Application_Start()
  75. {
  76. // Initialize Sentry to capture AppDomain unhandled exceptions and more.
  77. _sentry = SentrySdk.Init(o =>
  78. {
  79. o.AddAspNet();
  80. o.Dsn = "${dsn}";
  81. // When configuring for the first time, to see what the SDK is doing:
  82. o.Debug = true;
  83. // Set TracesSampleRate to 1.0 to capture 100%
  84. // of transactions for performance monitoring.
  85. // We recommend adjusting this value in production
  86. o.TracesSampleRate = 1.0;
  87. // If you are using EF (and installed the NuGet package):
  88. o.AddEntityFramework();
  89. });
  90. }
  91. // Global error catcher
  92. protected void Application_Error() => Server.CaptureLastError();
  93. protected void Application_BeginRequest()
  94. {
  95. Context.StartSentryTransaction();
  96. }
  97. protected void Application_EndRequest()
  98. {
  99. Context.FinishSentryTransaction();
  100. }
  101. protected void Application_End()
  102. {
  103. // Flushes out events before shutting down.
  104. _sentry?.Dispose();
  105. }
  106. }
  107. `,
  108. },
  109. ],
  110. },
  111. {
  112. title: t('Documentation'),
  113. description: (
  114. <p>
  115. {tct(
  116. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete ASP.NET docs].",
  117. {
  118. link: (
  119. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnet/" />
  120. ),
  121. }
  122. )}
  123. </p>
  124. ),
  125. },
  126. {
  127. title: t('Samples'),
  128. description: (
  129. <Fragment>
  130. {t(
  131. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  132. )}
  133. <List symbol="bullet">
  134. <ListItem>
  135. {tct(
  136. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  137. {
  138. link: (
  139. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  140. ),
  141. code: <code />,
  142. strong: <strong />,
  143. }
  144. )}
  145. </ListItem>
  146. <ListItem>
  147. {tct('[link:Basic F# sample] [strong:(F#)]', {
  148. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  149. strong: <strong />,
  150. })}
  151. </ListItem>
  152. </List>
  153. </Fragment>
  154. ),
  155. },
  156. ];
  157. // Configuration End
  158. export function GettingStartedWithAspnet({dsn, ...props}: ModuleProps) {
  159. return <Layout steps={steps({dsn})} {...props} />;
  160. }
  161. export default GettingStartedWithAspnet;
  162. const AlertWithoutMarginBottom = styled(Alert)`
  163. margin-bottom: 0;
  164. `;