aspnet.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {
  12. getCrashReportModalConfigDescription,
  13. getCrashReportModalIntroduction,
  14. getCrashReportSDKInstallFirstStep,
  15. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  16. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  17. import replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  18. import {t, tct} from 'sentry/locale';
  19. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  20. type Params = DocsParams;
  21. const getInstallSnippetPackageManager = (params: Params) => `
  22. Install-Package Sentry.AspNet -Version ${getPackageVersion(
  23. params,
  24. 'sentry.dotnet.aspnet',
  25. '3.34.0'
  26. )}`;
  27. const getInstallSnippetEntityFramework = (params: Params) => `
  28. Install-Package Sentry.EntityFramework -Version ${getPackageVersion(
  29. params,
  30. 'sentry.dotnet.aspnet',
  31. '3.34.0'
  32. )}`;
  33. const getConfigureSnippet = (params: Params) => `
  34. using System;
  35. using System.Configuration;
  36. using System.Web.Mvc;
  37. using System.Web.Routing;
  38. using Sentry;
  39. using Sentry.AspNet;
  40. using Sentry.EntityFramework; // if you installed Sentry.EntityFramework
  41. public class MvcApplication : HttpApplication
  42. {
  43. private IDisposable _sentry;
  44. protected void Application_Start()
  45. {
  46. // Initialize Sentry to capture AppDomain unhandled exceptions and more.
  47. _sentry = SentrySdk.Init(o =>
  48. {
  49. o.AddAspNet();
  50. o.Dsn = "${params.dsn}";
  51. // When configuring for the first time, to see what the SDK is doing:
  52. o.Debug = true;${
  53. params.isPerformanceSelected
  54. ? `
  55. // Set TracesSampleRate to 1.0 to capture 100%
  56. // of transactions for performance monitoring.
  57. // We recommend adjusting this value in production
  58. o.TracesSampleRate = 1.0;`
  59. : ''
  60. }
  61. // If you are using EF (and installed the NuGet package):
  62. o.AddEntityFramework();
  63. });
  64. }
  65. // Global error catcher
  66. protected void Application_Error() => Server.CaptureLastError();
  67. ${
  68. params.isPerformanceSelected
  69. ? `
  70. protected void Application_BeginRequest()
  71. {
  72. Context.StartSentryTransaction();
  73. }
  74. protected void Application_EndRequest()
  75. {
  76. Context.FinishSentryTransaction();
  77. }`
  78. : ''
  79. }
  80. protected void Application_End()
  81. {
  82. // Flushes out events before shutting down.
  83. _sentry?.Dispose();
  84. }
  85. }
  86. `;
  87. const onboarding: OnboardingConfig = {
  88. install: params => [
  89. {
  90. type: StepType.INSTALL,
  91. description: tct('Install the [strong:NuGet] package:', {
  92. strong: <strong />,
  93. }),
  94. configurations: [
  95. {
  96. language: 'shell',
  97. partialLoading: params.sourcePackageRegistries.isLoading,
  98. description: t('Package Manager:'),
  99. code: getInstallSnippetPackageManager(params),
  100. },
  101. {
  102. language: 'shell',
  103. partialLoading: params.sourcePackageRegistries.isLoading,
  104. description: t('Using Entity Framework 6?'),
  105. code: getInstallSnippetEntityFramework(params),
  106. },
  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. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry.AspNet'}),
  217. crashReportOnboarding,
  218. };
  219. export default docs;