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