dotnet.tsx 6.8 KB

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