aspnet.tsx 6.7 KB

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