aspnetcore.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 getPerformanceSpansSnippet = () => `
  45. using Microsoft.AspNetCore.Mvc;
  46. using Microsoft.Extensions.Logging;
  47. using Sentry;
  48. public class HomeController : Controller
  49. {
  50. private readonly IHub _sentryHub;
  51. public HomeController(IHub sentryHub) => _sentryHub = sentryHub;
  52. [HttpGet("/person/{id}")]
  53. public IActionResult Person(string id)
  54. {
  55. var childSpan = _sentryHub.GetSpan()?.StartChild("additional-work");
  56. try
  57. {
  58. // Do the work that gets measured.
  59. childSpan?.Finish(SpanStatus.Ok);
  60. }
  61. catch (Exception e)
  62. {
  63. childSpan?.Finish(e);
  64. throw;
  65. }
  66. }
  67. }`;
  68. const onboarding: OnboardingConfig = {
  69. install: params => [
  70. {
  71. type: StepType.INSTALL,
  72. description: tct('Install the [strong:NuGet] package:', {
  73. strong: <strong />,
  74. }),
  75. configurations: [
  76. {
  77. partialLoading: params.sourcePackageRegistries.isLoading,
  78. code: [
  79. {
  80. language: 'shell',
  81. label: 'Package Manager',
  82. value: 'packageManager',
  83. code: getInstallSnippetPackageManager(params),
  84. },
  85. {
  86. language: 'shell',
  87. label: '.NET Core CLI',
  88. value: 'coreCli',
  89. code: getInstallSnippetCoreCli(params),
  90. },
  91. ],
  92. },
  93. ],
  94. },
  95. ],
  96. configure: params => [
  97. {
  98. type: StepType.CONFIGURE,
  99. description: tct(
  100. 'Add Sentry to [programCode:Program.cs] through the [webHostCode:WebHostBuilder]:',
  101. {
  102. webHostCode: <code />,
  103. programCode: <code />,
  104. }
  105. ),
  106. configurations: [
  107. {
  108. language: 'csharp',
  109. code: getConfigureSnippet(params),
  110. },
  111. ],
  112. },
  113. ],
  114. verify: () => [
  115. {
  116. type: StepType.VERIFY,
  117. description: t('To verify your set up, you can capture a message with the SDK:'),
  118. configurations: [
  119. {
  120. language: 'csharp',
  121. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  122. },
  123. ],
  124. additionalInfo: tct(
  125. "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].",
  126. {
  127. code: <code />,
  128. link: (
  129. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/unit-testing/" />
  130. ),
  131. }
  132. ),
  133. },
  134. {
  135. title: t('Performance Monitoring'),
  136. description: tct(
  137. 'You can measure the performance of your endpoints by adding a middleware to [code:Startup.cs]:',
  138. {
  139. code: <code />,
  140. }
  141. ),
  142. configurations: [
  143. {
  144. description: t(
  145. "You'll be able to monitor the performance of your actions automatically. To add additional spans to it, you can use the API:"
  146. ),
  147. language: 'csharp',
  148. code: getPerformanceSpansSnippet(),
  149. },
  150. ],
  151. },
  152. {
  153. title: t('Samples'),
  154. description: (
  155. <Fragment>
  156. {t(
  157. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  158. )}
  159. <List symbol="bullet">
  160. <ListItem>
  161. {tct(
  162. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  163. {
  164. link: (
  165. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  166. ),
  167. code: <code />,
  168. strong: <strong />,
  169. }
  170. )}
  171. </ListItem>
  172. <ListItem>
  173. {tct('[link:Basic F# sample] [strong:(F#)]', {
  174. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  175. strong: <strong />,
  176. })}
  177. </ListItem>
  178. <ListItem>
  179. {tct('[link:Giraffe F# sample] [strong:(F#)]', {
  180. link: <ExternalLink href="https://github.com/sentry-demos/giraffe" />,
  181. strong: <strong />,
  182. })}
  183. </ListItem>
  184. </List>
  185. </Fragment>
  186. ),
  187. },
  188. ],
  189. };
  190. const docs: Docs = {
  191. onboarding,
  192. replayOnboardingJsLoader,
  193. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry.AspNetCore'}),
  194. };
  195. export default docs;