aspnetcore.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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.AspNetCore -Version ${getPackageVersion(
  25. params,
  26. 'sentry.dotnet.aspnetcore',
  27. params.isProfilingSelected ? '4.3.0' : '3.34.0'
  28. )}`;
  29. const getInstallSnippetCoreCli = (params: Params) => `
  30. dotnet add package Sentry.AspNetCore -v ${getPackageVersion(
  31. params,
  32. 'sentry.dotnet.aspnetcore',
  33. params.isProfilingSelected ? '4.3.0' : '3.34.0'
  34. )}`;
  35. const getInstallProfilingSnippetPackageManager = (params: Params) => `
  36. Install-Package Sentry.Profiling -Version ${getPackageVersion(
  37. params,
  38. 'sentry.dotnet.profiling',
  39. '4.3.0'
  40. )}`;
  41. const getInstallProfilingSnippetCoreCli = (params: Params) => `
  42. dotnet add package Sentry.Profiling -v ${getPackageVersion(
  43. params,
  44. 'sentry.dotnet.profiling',
  45. '4.3.0'
  46. )}`;
  47. const getConfigureSnippet = (params: Params) => `
  48. public static IHostBuilder CreateHostBuilder(string[] args) =>
  49. Host.CreateDefaultBuilder(args)
  50. .ConfigureWebHostDefaults(webBuilder =>
  51. {
  52. // Add the following line:
  53. webBuilder.UseSentry(o =>
  54. {
  55. o.Dsn = "${params.dsn.public}";
  56. // When configuring for the first time, to see what the SDK is doing:
  57. o.Debug = true;${
  58. params.isPerformanceSelected
  59. ? `
  60. // Set TracesSampleRate to 1.0 to capture 100%
  61. // of transactions for tracing.
  62. // We recommend adjusting this value in production
  63. o.TracesSampleRate = 1.0;`
  64. : ''
  65. }${
  66. params.isProfilingSelected
  67. ? `
  68. // Sample rate for profiling, applied on top of othe TracesSampleRate,
  69. // e.g. 0.2 means we want to profile 20 % of the captured transactions.
  70. // We recommend adjusting this value in production.
  71. o.ProfilesSampleRate = 1.0;
  72. // Requires NuGet package: Sentry.Profiling
  73. // Note: By default, the profiler is initialized asynchronously. This can
  74. // be tuned by passing a desired initialization timeout to the constructor.
  75. o.AddIntegration(new ProfilingIntegration(
  76. // During startup, wait up to 500ms to profile the app startup code.
  77. // This could make launching the app a bit slower so comment it out if you
  78. // prefer profiling to start asynchronously.
  79. TimeSpan.FromMilliseconds(500)
  80. ));`
  81. : ''
  82. }
  83. });
  84. });`;
  85. const getPerformanceSpansSnippet = () => `
  86. using Microsoft.AspNetCore.Mvc;
  87. using Microsoft.Extensions.Logging;
  88. using Sentry;
  89. public class HomeController : Controller
  90. {
  91. private readonly IHub _sentryHub;
  92. public HomeController(IHub sentryHub) => _sentryHub = sentryHub;
  93. [HttpGet("/person/{id}")]
  94. public IActionResult Person(string id)
  95. {
  96. var childSpan = _sentryHub.GetSpan()?.StartChild("additional-work");
  97. try
  98. {
  99. // Do the work that gets measured.
  100. childSpan?.Finish(SpanStatus.Ok);
  101. }
  102. catch (Exception e)
  103. {
  104. childSpan?.Finish(e);
  105. throw;
  106. }
  107. }
  108. }`;
  109. const onboarding: OnboardingConfig = {
  110. install: params => [
  111. {
  112. type: StepType.INSTALL,
  113. description: tct('Install the [strong:NuGet] package:', {
  114. strong: <strong />,
  115. }),
  116. configurations: [
  117. {
  118. partialLoading: params.sourcePackageRegistries.isLoading,
  119. code: [
  120. {
  121. language: 'shell',
  122. label: 'Package Manager',
  123. value: 'packageManager',
  124. code: getInstallSnippetPackageManager(params),
  125. },
  126. {
  127. language: 'shell',
  128. label: '.NET Core CLI',
  129. value: 'coreCli',
  130. code: getInstallSnippetCoreCli(params),
  131. },
  132. ],
  133. },
  134. ...(params.isProfilingSelected
  135. ? [
  136. {
  137. code: [
  138. {
  139. language: 'shell',
  140. label: 'Package Manager',
  141. value: 'packageManager',
  142. code: getInstallProfilingSnippetPackageManager(params),
  143. },
  144. {
  145. language: 'shell',
  146. label: '.NET Core CLI',
  147. value: 'coreCli',
  148. code: getInstallProfilingSnippetCoreCli(params),
  149. },
  150. ],
  151. },
  152. ]
  153. : []),
  154. ],
  155. },
  156. ],
  157. configure: params => [
  158. {
  159. type: StepType.CONFIGURE,
  160. description: tct(
  161. 'Add Sentry to [code:Program.cs] through the [code:WebHostBuilder]:',
  162. {
  163. code: <code />,
  164. }
  165. ),
  166. configurations: [
  167. {
  168. language: 'csharp',
  169. code: getConfigureSnippet(params),
  170. },
  171. ],
  172. },
  173. ],
  174. verify: params => [
  175. {
  176. type: StepType.VERIFY,
  177. description: t('To verify your set up, you can capture a message with the SDK:'),
  178. configurations: [
  179. {
  180. language: 'csharp',
  181. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  182. },
  183. ],
  184. additionalInfo: tct(
  185. "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].",
  186. {
  187. code: <code />,
  188. link: (
  189. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/unit-testing/" />
  190. ),
  191. }
  192. ),
  193. },
  194. ...(params.isPerformanceSelected
  195. ? [
  196. {
  197. title: t('Tracing'),
  198. description: tct(
  199. 'You can measure the performance of your endpoints by adding a middleware to [code:Startup.cs]:',
  200. {
  201. code: <code />,
  202. }
  203. ),
  204. configurations: [
  205. {
  206. description: t(
  207. "You'll be able to monitor the performance of your actions automatically. To add additional spans to it, you can use the API:"
  208. ),
  209. language: 'csharp',
  210. code: getPerformanceSpansSnippet(),
  211. },
  212. ],
  213. },
  214. ]
  215. : []),
  216. {
  217. title: t('Samples'),
  218. description: (
  219. <Fragment>
  220. {t(
  221. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  222. )}
  223. <List symbol="bullet">
  224. <ListItem>
  225. {tct(
  226. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  227. {
  228. link: (
  229. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  230. ),
  231. code: <code />,
  232. strong: <strong />,
  233. }
  234. )}
  235. </ListItem>
  236. <ListItem>
  237. {tct('[link:Basic F# sample] [strong:(F#)]', {
  238. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  239. strong: <strong />,
  240. })}
  241. </ListItem>
  242. <ListItem>
  243. {tct('[link:Giraffe F# sample] [strong:(F#)]', {
  244. link: <ExternalLink href="https://github.com/sentry-demos/giraffe" />,
  245. strong: <strong />,
  246. })}
  247. </ListItem>
  248. </List>
  249. </Fragment>
  250. ),
  251. },
  252. ],
  253. };
  254. const crashReportOnboarding: OnboardingConfig = {
  255. introduction: () => getCrashReportModalIntroduction(),
  256. install: (params: Params) => [
  257. {
  258. type: StepType.INSTALL,
  259. configurations: [
  260. getCrashReportSDKInstallFirstStep(params),
  261. {
  262. description: tct(
  263. 'If you are rendering the page from the server, for example on ASP.NET MVC, the [code:Error.cshtml] razor page can be:',
  264. {code: <code />}
  265. ),
  266. code: [
  267. {
  268. label: 'cshtml',
  269. value: 'html',
  270. language: 'html',
  271. code: `@using Sentry
  272. @using Sentry.AspNetCore
  273. @inject Microsoft.Extensions.Options.IOptions<SentryAspNetCoreOptions> SentryOptions
  274. @if (SentrySdk.LastEventId != SentryId.Empty) {
  275. <script>
  276. Sentry.init({ dsn: "@(SentryOptions.Value.Dsn)" });
  277. Sentry.showReportDialog({ eventId: "@SentrySdk.LastEventId" });
  278. </script>
  279. }`,
  280. },
  281. ],
  282. },
  283. ],
  284. },
  285. ],
  286. configure: () => [
  287. {
  288. type: StepType.CONFIGURE,
  289. description: getCrashReportModalConfigDescription({
  290. link: 'https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/user-feedback/configuration/#crash-report-modal',
  291. }),
  292. },
  293. ],
  294. verify: () => [],
  295. nextSteps: () => [],
  296. };
  297. const docs: Docs = {
  298. onboarding,
  299. replayOnboardingJsLoader,
  300. crashReportOnboarding,
  301. feedbackOnboardingJsLoader,
  302. };
  303. export default docs;