aspnetcore.tsx 6.7 KB

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