aspnet.tsx 6.8 KB

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