aspnet.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.public}";
  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 tracing.
  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 [code:init] the Sentry SDK as soon as possible during your application load by adding Sentry to [code:Global.asax.cs]:',
  115. {
  116. code: <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.public}" });
  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. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry.AspNet'}),
  216. crashReportOnboarding,
  217. };
  218. export default docs;