aspnet.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  17. import {t, tct} from 'sentry/locale';
  18. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  19. type Params = DocsParams;
  20. const getInstallSnippetPackageManager = (params: Params) => `
  21. Install-Package Sentry.AspNet -Version ${getPackageVersion(
  22. params,
  23. 'sentry.dotnet.aspnet',
  24. '3.34.0'
  25. )}`;
  26. const getInstallSnippetEntityFramework = (params: Params) => `
  27. Install-Package Sentry.EntityFramework -Version ${getPackageVersion(
  28. params,
  29. 'sentry.dotnet.aspnet',
  30. '3.34.0'
  31. )}`;
  32. const getConfigureSnippet = (params: Params) => `
  33. using System;
  34. using System.Configuration;
  35. using System.Web.Mvc;
  36. using System.Web.Routing;
  37. using Sentry;
  38. using Sentry.AspNet;
  39. using Sentry.EntityFramework; // if you installed Sentry.EntityFramework
  40. public class MvcApplication : HttpApplication
  41. {
  42. private IDisposable _sentry;
  43. protected void Application_Start()
  44. {
  45. // Initialize Sentry to capture AppDomain unhandled exceptions and more.
  46. _sentry = SentrySdk.Init(o =>
  47. {
  48. o.AddAspNet();
  49. o.Dsn = "${params.dsn}";
  50. // When configuring for the first time, to see what the SDK is doing:
  51. o.Debug = true;${
  52. params.isPerformanceSelected
  53. ? `
  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. : ''
  59. }
  60. // If you are using EF (and installed the NuGet package):
  61. o.AddEntityFramework();
  62. });
  63. }
  64. // Global error catcher
  65. protected void Application_Error() => Server.CaptureLastError();
  66. protected void Application_BeginRequest()
  67. {
  68. Context.StartSentryTransaction();
  69. }
  70. protected void Application_EndRequest()
  71. {
  72. Context.FinishSentryTransaction();
  73. }
  74. protected void Application_End()
  75. {
  76. // Flushes out events before shutting down.
  77. _sentry?.Dispose();
  78. }
  79. }
  80. `;
  81. const onboarding: OnboardingConfig = {
  82. install: params => [
  83. {
  84. type: StepType.INSTALL,
  85. description: tct('Install the [strong:NuGet] package:', {
  86. strong: <strong />,
  87. }),
  88. configurations: [
  89. {
  90. language: 'shell',
  91. partialLoading: params.sourcePackageRegistries.isLoading,
  92. description: t('Package Manager:'),
  93. code: getInstallSnippetPackageManager(params),
  94. },
  95. {
  96. language: 'shell',
  97. partialLoading: params.sourcePackageRegistries.isLoading,
  98. description: t('Using Entity Framework 6?'),
  99. code: getInstallSnippetEntityFramework(params),
  100. },
  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 crashReportOnboarding: OnboardingConfig = {
  168. introduction: () => getCrashReportModalIntroduction(),
  169. install: (params: Params) => [
  170. {
  171. type: StepType.INSTALL,
  172. configurations: [
  173. getCrashReportSDKInstallFirstStep(params),
  174. {
  175. description: tct(
  176. 'If you are rendering the page from the server, for example on ASP.NET MVC, the [code:Error.cshtml] razor page can be:',
  177. {code: <code />}
  178. ),
  179. code: [
  180. {
  181. label: 'cshtml',
  182. value: 'html',
  183. language: 'html',
  184. code: `@if (SentrySdk.LastEventId != SentryId.Empty) {
  185. <script>
  186. Sentry.init({ dsn: "${params.dsn}" });
  187. Sentry.showReportDialog({ eventId: "@SentrySdk.LastEventId" });
  188. </script>
  189. }`,
  190. },
  191. ],
  192. },
  193. ],
  194. },
  195. ],
  196. configure: () => [
  197. {
  198. type: StepType.CONFIGURE,
  199. description: getCrashReportModalConfigDescription({
  200. link: 'https://docs.sentry.io/platforms/dotnet/guides/aspnet/user-feedback/configuration/#crash-report-modal',
  201. }),
  202. },
  203. ],
  204. verify: () => [],
  205. nextSteps: () => [],
  206. };
  207. const docs: Docs = {
  208. onboarding,
  209. replayOnboardingJsLoader,
  210. crashReportOnboarding,
  211. };
  212. export default docs;