dotnet.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 {t, tct} from 'sentry/locale';
  13. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  14. type Params = DocsParams;
  15. const getInstallSnippetPackageManager = (params: Params) => `
  16. Install-Package Sentry -Version ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  17. const getInstallSnippetCoreCli = (params: Params) => `
  18. dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  19. const getConfigureSnippet = (params: Params) => `
  20. using Sentry;
  21. SentrySdk.Init(options =>
  22. {
  23. // A Sentry Data Source Name (DSN) is required.
  24. // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
  25. // You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
  26. options.Dsn = "${params.dsn}";
  27. // When debug is enabled, the Sentry client will emit detailed debugging information to the console.
  28. // This might be helpful, or might interfere with the normal operation of your application.
  29. // We enable it here for demonstration purposes when first trying Sentry.
  30. // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
  31. options.Debug = true;
  32. // This option is recommended. It enables Sentry's "Release Health" feature.
  33. options.AutoSessionTracking = true;
  34. // This option is recommended for client applications only. It ensures all threads use the same global scope.
  35. // If you're writing a background service of any kind, you should remove this.
  36. options.IsGlobalModeEnabled = true;
  37. // This option will enable Sentry's tracing features. You still need to start transactions and spans.
  38. options.EnableTracing = true;
  39. });`;
  40. const getPerformanceMonitoringSnippet = () => `
  41. // Transaction can be started by providing, at minimum, the name and the operation
  42. var transaction = SentrySdk.StartTransaction(
  43. "test-transaction-name",
  44. "test-transaction-operation"
  45. );
  46. // Transactions can have child spans (and those spans can have child spans as well)
  47. var span = transaction.StartChild("test-child-operation");
  48. // ...
  49. // (Perform the operation represented by the span/transaction)
  50. // ...
  51. span.Finish(); // Mark the span as finished
  52. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  53. const onboarding: OnboardingConfig = {
  54. introduction: () =>
  55. tct(
  56. 'Sentry for .NET is a collection of NuGet packages provided by Sentry; it supports .NET Framework 4.6.1 and .NET Core 2.0 and above. At its core, Sentry for .NET provides a raw client for sending events to Sentry. If you use a framework such as [strong:ASP.NET, WinForms, WPF, MAUI, Xamarin, Serilog], or similar, we recommend visiting our [link:Sentry .NET] documentation for installation instructions.',
  57. {
  58. strong: <strong />,
  59. link: <ExternalLink href="https://docs.sentry.io/platforms/dotnet/" />,
  60. }
  61. ),
  62. install: params => [
  63. {
  64. type: StepType.INSTALL,
  65. description: tct('Install the [strong:NuGet] package:', {
  66. strong: <strong />,
  67. }),
  68. configurations: [
  69. {
  70. partialLoading: params.sourcePackageRegistries.isLoading,
  71. code: [
  72. {
  73. language: 'shell',
  74. label: 'Package Manager',
  75. value: 'packageManager',
  76. code: getInstallSnippetPackageManager(params),
  77. },
  78. {
  79. language: 'shell',
  80. label: '.NET Core CLI',
  81. value: 'coreCli',
  82. code: getInstallSnippetCoreCli(params),
  83. },
  84. ],
  85. },
  86. ],
  87. },
  88. ],
  89. configure: params => [
  90. {
  91. type: StepType.CONFIGURE,
  92. description: tct(
  93. 'Initialize the SDK as early as possible. For example, call [sentrySdkCode:SentrySdk.Init] in your [programCode:Program.cs] file:',
  94. {
  95. sentrySdkCode: <code />,
  96. programCode: <code />,
  97. }
  98. ),
  99. configurations: [
  100. {
  101. language: 'csharp',
  102. code: getConfigureSnippet(params),
  103. },
  104. ],
  105. },
  106. ],
  107. verify: () => [
  108. {
  109. type: StepType.VERIFY,
  110. description: t('Verify Sentry is correctly configured by sending a message:'),
  111. configurations: [
  112. {
  113. language: 'csharp',
  114. code: 'SentrySdk.CaptureMessage("Something went wrong");',
  115. },
  116. ],
  117. },
  118. {
  119. title: t('Performance Monitoring'),
  120. description: t(
  121. 'You can measure the performance of your code by capturing transactions and spans.'
  122. ),
  123. configurations: [
  124. {
  125. language: 'csharp',
  126. code: getPerformanceMonitoringSnippet(),
  127. },
  128. ],
  129. additionalInfo: tct(
  130. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  131. {
  132. link: (
  133. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/performance/instrumentation/" />
  134. ),
  135. }
  136. ),
  137. },
  138. {
  139. title: t('Samples'),
  140. description: (
  141. <Fragment>
  142. <p>
  143. {tct(
  144. 'You can find an example ASP.NET MVC 5 app with Sentry integrated [link:on this GitHub repository].',
  145. {
  146. link: (
  147. <ExternalLink href="https://github.com/getsentry/examples/tree/master/dotnet/AspNetMvc5Ef6" />
  148. ),
  149. }
  150. )}
  151. </p>
  152. {t(
  153. 'In addition, these examples demonstrate how to integrate Sentry with various frameworks:'
  154. )}
  155. </Fragment>
  156. ),
  157. configurations: [
  158. {
  159. description: (
  160. <List symbol="bullet">
  161. <ListItem>
  162. {tct(
  163. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  164. {
  165. link: (
  166. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  167. ),
  168. code: <code />,
  169. strong: <strong />,
  170. }
  171. )}
  172. </ListItem>
  173. <ListItem>
  174. {tct('[link:Basic F# sample] [strong:(F#)]', {
  175. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  176. strong: <strong />,
  177. })}
  178. </ListItem>
  179. </List>
  180. ),
  181. },
  182. ],
  183. },
  184. ],
  185. };
  186. const docs: Docs = {
  187. onboarding,
  188. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  189. };
  190. export default docs;