aspnetcore.tsx 6.7 KB

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