aspnet.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. ${
  67. params.isPerformanceSelected
  68. ? `
  69. protected void Application_BeginRequest()
  70. {
  71. Context.StartSentryTransaction();
  72. }
  73. protected void Application_EndRequest()
  74. {
  75. Context.FinishSentryTransaction();
  76. }`
  77. : ''
  78. }
  79. protected void Application_End()
  80. {
  81. // Flushes out events before shutting down.
  82. _sentry?.Dispose();
  83. }
  84. }
  85. `;
  86. const onboarding: OnboardingConfig = {
  87. install: params => [
  88. {
  89. type: StepType.INSTALL,
  90. description: tct('Install the [strong:NuGet] package:', {
  91. strong: <strong />,
  92. }),
  93. configurations: [
  94. {
  95. language: 'shell',
  96. partialLoading: params.sourcePackageRegistries.isLoading,
  97. description: t('Package Manager:'),
  98. code: getInstallSnippetPackageManager(params),
  99. },
  100. {
  101. language: 'shell',
  102. partialLoading: params.sourcePackageRegistries.isLoading,
  103. description: t('Using Entity Framework 6?'),
  104. code: getInstallSnippetEntityFramework(params),
  105. },
  106. ],
  107. },
  108. ],
  109. configure: params => [
  110. {
  111. type: StepType.CONFIGURE,
  112. description: tct(
  113. 'You should [initCode:init] the Sentry SDK as soon as possible during your application load by adding Sentry to [globalCode:Global.asax.cs]:',
  114. {
  115. initCode: <code />,
  116. globalCode: <code />,
  117. }
  118. ),
  119. configurations: [
  120. {
  121. language: 'csharp',
  122. code: getConfigureSnippet(params),
  123. },
  124. ],
  125. },
  126. ],
  127. // TODO: Add proper verify step
  128. verify: () => [
  129. {
  130. title: t('Documentation'),
  131. description: tct(
  132. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete ASP.NET docs].",
  133. {
  134. link: (
  135. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnet/" />
  136. ),
  137. }
  138. ),
  139. },
  140. {
  141. title: t('Samples'),
  142. description: (
  143. <Fragment>
  144. {t(
  145. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  146. )}
  147. <List symbol="bullet">
  148. <ListItem>
  149. {tct(
  150. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  151. {
  152. link: (
  153. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  154. ),
  155. code: <code />,
  156. strong: <strong />,
  157. }
  158. )}
  159. </ListItem>
  160. <ListItem>
  161. {tct('[link:Basic F# sample] [strong:(F#)]', {
  162. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  163. strong: <strong />,
  164. })}
  165. </ListItem>
  166. </List>
  167. </Fragment>
  168. ),
  169. },
  170. ],
  171. };
  172. const crashReportOnboarding: OnboardingConfig = {
  173. introduction: () => getCrashReportModalIntroduction(),
  174. install: (params: Params) => [
  175. {
  176. type: StepType.INSTALL,
  177. configurations: [
  178. getCrashReportSDKInstallFirstStep(params),
  179. {
  180. description: tct(
  181. 'If you are rendering the page from the server, for example on ASP.NET MVC, the [code:Error.cshtml] razor page can be:',
  182. {code: <code />}
  183. ),
  184. code: [
  185. {
  186. label: 'cshtml',
  187. value: 'html',
  188. language: 'html',
  189. code: `@if (SentrySdk.LastEventId != SentryId.Empty) {
  190. <script>
  191. Sentry.init({ dsn: "${params.dsn}" });
  192. Sentry.showReportDialog({ eventId: "@SentrySdk.LastEventId" });
  193. </script>
  194. }`,
  195. },
  196. ],
  197. },
  198. ],
  199. },
  200. ],
  201. configure: () => [
  202. {
  203. type: StepType.CONFIGURE,
  204. description: getCrashReportModalConfigDescription({
  205. link: 'https://docs.sentry.io/platforms/dotnet/guides/aspnet/user-feedback/configuration/#crash-report-modal',
  206. }),
  207. },
  208. ],
  209. verify: () => [],
  210. nextSteps: () => [],
  211. };
  212. const docs: Docs = {
  213. onboarding,
  214. replayOnboardingJsLoader,
  215. crashReportOnboarding,
  216. };
  217. export default docs;