aspnetcore.tsx 7.0 KB

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