aspnet.tsx 6.5 KB

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