dotnet.tsx 6.0 KB

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