aspnet.tsx 5.4 KB

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