aspnetcore.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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.AspNetCore -Version ${getPackageVersion(
  23. params,
  24. 'sentry.dotnet.aspnetcore',
  25. '3.34.0'
  26. )}`;
  27. const getInstallSnippetCoreCli = (params: Params) => `
  28. dotnet add package Sentry.AspNetCore -v ${getPackageVersion(
  29. params,
  30. 'sentry.dotnet.aspnetcore',
  31. '3.34.0'
  32. )}`;
  33. const getConfigureSnippet = (params: Params) => `
  34. public static IHostBuilder CreateHostBuilder(string[] args) =>
  35. Host.CreateDefaultBuilder(args)
  36. .ConfigureWebHostDefaults(webBuilder =>
  37. {
  38. // Add the following line:
  39. webBuilder.UseSentry(o =>
  40. {
  41. o.Dsn = "${params.dsn}";
  42. // When configuring for the first time, to see what the SDK is doing:
  43. o.Debug = true;
  44. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  45. // We recommend adjusting this value in production.
  46. o.TracesSampleRate = 1.0;
  47. });
  48. });`;
  49. const getPerformanceSpansSnippet = () => `
  50. using Microsoft.AspNetCore.Mvc;
  51. using Microsoft.Extensions.Logging;
  52. using Sentry;
  53. public class HomeController : Controller
  54. {
  55. private readonly IHub _sentryHub;
  56. public HomeController(IHub sentryHub) => _sentryHub = sentryHub;
  57. [HttpGet("/person/{id}")]
  58. public IActionResult Person(string id)
  59. {
  60. var childSpan = _sentryHub.GetSpan()?.StartChild("additional-work");
  61. try
  62. {
  63. // Do the work that gets measured.
  64. childSpan?.Finish(SpanStatus.Ok);
  65. }
  66. catch (Exception e)
  67. {
  68. childSpan?.Finish(e);
  69. throw;
  70. }
  71. }
  72. }`;
  73. const onboarding: OnboardingConfig = {
  74. install: params => [
  75. {
  76. type: StepType.INSTALL,
  77. description: tct('Install the [strong:NuGet] package:', {
  78. strong: <strong />,
  79. }),
  80. configurations: [
  81. {
  82. partialLoading: params.sourcePackageRegistries.isLoading,
  83. code: [
  84. {
  85. language: 'shell',
  86. label: 'Package Manager',
  87. value: 'packageManager',
  88. code: getInstallSnippetPackageManager(params),
  89. },
  90. {
  91. language: 'shell',
  92. label: '.NET Core CLI',
  93. value: 'coreCli',
  94. code: getInstallSnippetCoreCli(params),
  95. },
  96. ],
  97. },
  98. ],
  99. },
  100. ],
  101. configure: params => [
  102. {
  103. type: StepType.CONFIGURE,
  104. description: tct(
  105. 'Add Sentry to [programCode:Program.cs] through the [webHostCode:WebHostBuilder]:',
  106. {
  107. webHostCode: <code />,
  108. programCode: <code />,
  109. }
  110. ),
  111. configurations: [
  112. {
  113. language: 'csharp',
  114. code: getConfigureSnippet(params),
  115. },
  116. ],
  117. },
  118. ],
  119. verify: () => [
  120. {
  121. type: StepType.VERIFY,
  122. description: t('To verify your set up, you can capture a message with the SDK:'),
  123. configurations: [
  124. {
  125. language: 'csharp',
  126. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  127. },
  128. ],
  129. additionalInfo: tct(
  130. "If you don't want to depend on the static class, the SDK registers a client in the DI container. In this case, you can [link:take [code:IHub] as a dependency].",
  131. {
  132. code: <code />,
  133. link: (
  134. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/unit-testing/" />
  135. ),
  136. }
  137. ),
  138. },
  139. {
  140. title: t('Performance Monitoring'),
  141. description: tct(
  142. 'You can measure the performance of your endpoints by adding a middleware to [code:Startup.cs]:',
  143. {
  144. code: <code />,
  145. }
  146. ),
  147. configurations: [
  148. {
  149. description: t(
  150. "You'll be able to monitor the performance of your actions automatically. To add additional spans to it, you can use the API:"
  151. ),
  152. language: 'csharp',
  153. code: getPerformanceSpansSnippet(),
  154. },
  155. ],
  156. },
  157. {
  158. title: t('Samples'),
  159. description: (
  160. <Fragment>
  161. {t(
  162. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  163. )}
  164. <List symbol="bullet">
  165. <ListItem>
  166. {tct(
  167. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  168. {
  169. link: (
  170. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  171. ),
  172. code: <code />,
  173. strong: <strong />,
  174. }
  175. )}
  176. </ListItem>
  177. <ListItem>
  178. {tct('[link:Basic F# sample] [strong:(F#)]', {
  179. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  180. strong: <strong />,
  181. })}
  182. </ListItem>
  183. <ListItem>
  184. {tct('[link:Giraffe F# sample] [strong:(F#)]', {
  185. link: <ExternalLink href="https://github.com/sentry-demos/giraffe" />,
  186. strong: <strong />,
  187. })}
  188. </ListItem>
  189. </List>
  190. </Fragment>
  191. ),
  192. },
  193. ],
  194. };
  195. const crashReportOnboarding: OnboardingConfig = {
  196. introduction: () => getCrashReportModalIntroduction(),
  197. install: (params: Params) => [
  198. {
  199. type: StepType.INSTALL,
  200. configurations: [
  201. getCrashReportSDKInstallFirstStep(params),
  202. {
  203. description: tct(
  204. 'If you are rendering the page from the server, for example on ASP.NET MVC, the [code:Error.cshtml] razor page can be:',
  205. {code: <code />}
  206. ),
  207. code: [
  208. {
  209. label: 'cshtml',
  210. value: 'html',
  211. language: 'html',
  212. code: `@using Sentry
  213. @using Sentry.AspNetCore
  214. @inject Microsoft.Extensions.Options.IOptions<SentryAspNetCoreOptions> SentryOptions
  215. @if (SentrySdk.LastEventId != SentryId.Empty) {
  216. <script>
  217. Sentry.init({ dsn: "@(SentryOptions.Value.Dsn)" });
  218. Sentry.showReportDialog({ eventId: "@SentrySdk.LastEventId" });
  219. </script>
  220. }`,
  221. },
  222. ],
  223. },
  224. ],
  225. },
  226. ],
  227. configure: () => [
  228. {
  229. type: StepType.CONFIGURE,
  230. description: getCrashReportModalConfigDescription({
  231. link: 'https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/user-feedback/configuration/#crash-report-modal',
  232. }),
  233. },
  234. ],
  235. verify: () => [],
  236. nextSteps: () => [],
  237. };
  238. const docs: Docs = {
  239. onboarding,
  240. replayOnboardingJsLoader,
  241. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry.AspNetCore'}),
  242. crashReportOnboarding,
  243. };
  244. export default docs;