aspnet.tsx 5.3 KB

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