aspnetcore.tsx 6.1 KB

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