aspnetcore.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 replayOnboardingJsLoader from 'sentry/gettingStartedDocs/javascript/jsLoader/jsLoader';
  12. import {t, tct} from 'sentry/locale';
  13. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  14. type Params = DocsParams;
  15. const getInstallSnippetPackageManager = (params: Params) => `
  16. Install-Package Sentry.AspNetCore -Version ${getPackageVersion(
  17. params,
  18. 'sentry.dotnet.aspnetcore',
  19. '3.34.0'
  20. )}`;
  21. const getInstallSnippetCoreCli = (params: Params) => `
  22. dotnet add package Sentry.AspNetCore -v ${getPackageVersion(
  23. params,
  24. 'sentry.dotnet.aspnetcore',
  25. '3.34.0'
  26. )}`;
  27. const getConfigureSnippet = (params: Params) => `
  28. public static IHostBuilder CreateHostBuilder(string[] args) =>
  29. Host.CreateDefaultBuilder(args)
  30. .ConfigureWebHostDefaults(webBuilder =>
  31. {
  32. // Add the following line:
  33. webBuilder.UseSentry(o =>
  34. {
  35. o.Dsn = "${params.dsn}";
  36. // When configuring for the first time, to see what the SDK is doing:
  37. o.Debug = true;
  38. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  39. // We recommend adjusting this value in production.
  40. o.TracesSampleRate = 1.0;
  41. });
  42. });`;
  43. const getPerformanceMiddlewareSnippet = () => `
  44. using Microsoft.AspNetCore.Builder;
  45. using Microsoft.AspNetCore.Hosting;
  46. using Microsoft.Extensions.Configuration;
  47. using Microsoft.Extensions.DependencyInjection;
  48. using Microsoft.Extensions.Hosting;
  49. using Sentry.AspNetCore;
  50. public class Startup
  51. {
  52. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  53. {
  54. app.UseRouting();
  55. // Enable automatic tracing integration.
  56. // If running with .NET 5 or below, make sure to put this middleware
  57. // right after "UseRouting()".
  58. app.UseSentryTracing();
  59. app.UseEndpoints(endpoints =>
  60. {
  61. endpoints.MapControllerRoute(
  62. name: "default",
  63. pattern: "{controller=Home}/{action=Index}/{id?}");
  64. });
  65. }
  66. }`;
  67. const getPerformanceSpansSnippet = () => `
  68. using Microsoft.AspNetCore.Mvc;
  69. using Microsoft.Extensions.Logging;
  70. using Sentry;
  71. public class HomeController : Controller
  72. {
  73. private readonly IHub _sentryHub;
  74. public HomeController(IHub sentryHub) => _sentryHub = sentryHub;
  75. [HttpGet("/person/{id}")]
  76. public IActionResult Person(string id)
  77. {
  78. var childSpan = _sentryHub.GetSpan()?.StartChild("additional-work");
  79. try
  80. {
  81. // Do the work that gets measured.
  82. childSpan?.Finish(SpanStatus.Ok);
  83. }
  84. catch (Exception e)
  85. {
  86. childSpan?.Finish(e);
  87. throw;
  88. }
  89. }
  90. }`;
  91. const onboarding: OnboardingConfig = {
  92. install: params => [
  93. {
  94. type: StepType.INSTALL,
  95. description: tct('Install the [strong:NuGet] package:', {
  96. strong: <strong />,
  97. }),
  98. configurations: [
  99. {
  100. partialLoading: params.sourcePackageRegistries.isLoading,
  101. code: [
  102. {
  103. language: 'shell',
  104. label: 'Package Manager',
  105. value: 'packageManager',
  106. code: getInstallSnippetPackageManager(params),
  107. },
  108. {
  109. language: 'shell',
  110. label: '.NET Core CLI',
  111. value: 'coreCli',
  112. code: getInstallSnippetCoreCli(params),
  113. },
  114. ],
  115. },
  116. ],
  117. },
  118. ],
  119. configure: params => [
  120. {
  121. type: StepType.CONFIGURE,
  122. description: tct(
  123. 'Add Sentry to [programCode:Program.cs] through the [webHostCode:WebHostBuilder]:',
  124. {
  125. webHostCode: <code />,
  126. programCode: <code />,
  127. }
  128. ),
  129. configurations: [
  130. {
  131. language: 'csharp',
  132. code: getConfigureSnippet(params),
  133. },
  134. ],
  135. },
  136. ],
  137. verify: () => [
  138. {
  139. type: StepType.VERIFY,
  140. description: t('To verify your set up, you can capture a message with the SDK:'),
  141. configurations: [
  142. {
  143. language: 'csharp',
  144. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  145. },
  146. ],
  147. additionalInfo: tct(
  148. "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].",
  149. {
  150. code: <code />,
  151. link: (
  152. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/unit-testing/" />
  153. ),
  154. }
  155. ),
  156. },
  157. {
  158. title: t('Performance Monitoring'),
  159. description: tct(
  160. 'You can measure the performance of your endpoints by adding a middleware to [code:Startup.cs]:',
  161. {
  162. code: <code />,
  163. }
  164. ),
  165. configurations: [
  166. {
  167. language: 'csharp',
  168. code: getPerformanceMiddlewareSnippet(),
  169. },
  170. {
  171. description: t(
  172. "You'll be able to monitor the performance of your actions automatically. To add additional spans to it, you can use the API:"
  173. ),
  174. language: 'csharp',
  175. code: getPerformanceSpansSnippet(),
  176. },
  177. ],
  178. },
  179. {
  180. title: t('Samples'),
  181. description: (
  182. <Fragment>
  183. {t(
  184. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  185. )}
  186. <List symbol="bullet">
  187. <ListItem>
  188. {tct(
  189. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  190. {
  191. link: (
  192. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  193. ),
  194. code: <code />,
  195. strong: <strong />,
  196. }
  197. )}
  198. </ListItem>
  199. <ListItem>
  200. {tct('[link:Basic F# sample] [strong:(F#)]', {
  201. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  202. strong: <strong />,
  203. })}
  204. </ListItem>
  205. <ListItem>
  206. {tct('[link:Giraffe F# sample] [strong:(F#)]', {
  207. link: <ExternalLink href="https://github.com/sentry-demos/giraffe" />,
  208. strong: <strong />,
  209. })}
  210. </ListItem>
  211. </List>
  212. </Fragment>
  213. ),
  214. },
  215. ],
  216. };
  217. const docs: Docs = {
  218. onboarding,
  219. replayOnboardingJsLoader,
  220. };
  221. export default docs;