dotnet.tsx 6.6 KB

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