dotnet.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 altCrashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/altCrashReportCallout';
  6. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  7. import type {
  8. Docs,
  9. DocsParams,
  10. OnboardingConfig,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  12. import {
  13. getCrashReportApiIntroduction,
  14. getCrashReportInstallDescription,
  15. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  16. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  17. import {t, tct} from 'sentry/locale';
  18. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  19. type Params = DocsParams;
  20. const getInstallSnippetPackageManager = (params: Params) => `
  21. Install-Package Sentry -Version ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  22. const getInstallSnippetCoreCli = (params: Params) => `
  23. dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  24. const getConfigureSnippet = (params: Params) => `
  25. using Sentry;
  26. SentrySdk.Init(options =>
  27. {
  28. // A Sentry Data Source Name (DSN) is required.
  29. // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
  30. // You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
  31. options.Dsn = "${params.dsn}";
  32. // When debug is enabled, the Sentry client will emit detailed debugging information to the console.
  33. // This might be helpful, or might interfere with the normal operation of your application.
  34. // We enable it here for demonstration purposes when first trying Sentry.
  35. // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
  36. options.Debug = true;
  37. // This option is recommended. It enables Sentry's "Release Health" feature.
  38. options.AutoSessionTracking = true;
  39. // This option is recommended for client applications only. It ensures all threads use the same global scope.
  40. // If you're writing a background service of any kind, you should remove this.
  41. options.IsGlobalModeEnabled = true;
  42. // This option will enable Sentry's tracing features. You still need to start transactions and spans.
  43. options.EnableTracing = true;
  44. });`;
  45. const getPerformanceMonitoringSnippet = () => `
  46. // Transaction can be started by providing, at minimum, the name and the operation
  47. var transaction = SentrySdk.StartTransaction(
  48. "test-transaction-name",
  49. "test-transaction-operation"
  50. );
  51. // Transactions can have child spans (and those spans can have child spans as well)
  52. var span = transaction.StartChild("test-child-operation");
  53. // ...
  54. // (Perform the operation represented by the span/transaction)
  55. // ...
  56. span.Finish(); // Mark the span as finished
  57. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  58. const onboarding: OnboardingConfig = {
  59. introduction: () =>
  60. tct(
  61. '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.',
  62. {
  63. strong: <strong />,
  64. link: <ExternalLink href="https://docs.sentry.io/platforms/dotnet/" />,
  65. }
  66. ),
  67. install: params => [
  68. {
  69. type: StepType.INSTALL,
  70. description: tct('Install the [strong:NuGet] package:', {
  71. strong: <strong />,
  72. }),
  73. configurations: [
  74. {
  75. partialLoading: params.sourcePackageRegistries.isLoading,
  76. code: [
  77. {
  78. language: 'shell',
  79. label: 'Package Manager',
  80. value: 'packageManager',
  81. code: getInstallSnippetPackageManager(params),
  82. },
  83. {
  84. language: 'shell',
  85. label: '.NET Core CLI',
  86. value: 'coreCli',
  87. code: getInstallSnippetCoreCli(params),
  88. },
  89. ],
  90. },
  91. ],
  92. },
  93. ],
  94. configure: params => [
  95. {
  96. type: StepType.CONFIGURE,
  97. description: tct(
  98. 'Initialize the SDK as early as possible. For example, call [sentrySdkCode:SentrySdk.Init] in your [programCode:Program.cs] file:',
  99. {
  100. sentrySdkCode: <code />,
  101. programCode: <code />,
  102. }
  103. ),
  104. configurations: [
  105. {
  106. language: 'csharp',
  107. code: getConfigureSnippet(params),
  108. },
  109. ],
  110. },
  111. ],
  112. verify: () => [
  113. {
  114. type: StepType.VERIFY,
  115. description: t('Verify Sentry is correctly configured by sending a message:'),
  116. configurations: [
  117. {
  118. language: 'csharp',
  119. code: 'SentrySdk.CaptureMessage("Something went wrong");',
  120. },
  121. ],
  122. },
  123. {
  124. title: t('Performance Monitoring'),
  125. description: t(
  126. 'You can measure the performance of your code by capturing transactions and spans.'
  127. ),
  128. configurations: [
  129. {
  130. language: 'csharp',
  131. code: getPerformanceMonitoringSnippet(),
  132. },
  133. ],
  134. additionalInfo: 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. },
  143. {
  144. title: t('Samples'),
  145. description: (
  146. <Fragment>
  147. <p>
  148. {tct(
  149. 'You can find an example ASP.NET MVC 5 app with Sentry integrated [link:on this GitHub repository].',
  150. {
  151. link: (
  152. <ExternalLink href="https://github.com/getsentry/examples/tree/master/dotnet/AspNetMvc5Ef6" />
  153. ),
  154. }
  155. )}
  156. </p>
  157. {t(
  158. 'In addition, these examples demonstrate how to integrate Sentry with various frameworks:'
  159. )}
  160. </Fragment>
  161. ),
  162. configurations: [
  163. {
  164. description: (
  165. <List symbol="bullet">
  166. <ListItem>
  167. {tct(
  168. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  169. {
  170. link: (
  171. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  172. ),
  173. code: <code />,
  174. strong: <strong />,
  175. }
  176. )}
  177. </ListItem>
  178. <ListItem>
  179. {tct('[link:Basic F# sample] [strong:(F#)]', {
  180. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  181. strong: <strong />,
  182. })}
  183. </ListItem>
  184. </List>
  185. ),
  186. },
  187. ],
  188. },
  189. ],
  190. };
  191. export const csharpFeedbackOnboarding: OnboardingConfig = {
  192. introduction: () => getCrashReportApiIntroduction(),
  193. install: () => [
  194. {
  195. type: StepType.INSTALL,
  196. description: getCrashReportInstallDescription(),
  197. configurations: [
  198. {
  199. code: [
  200. {
  201. label: 'C#',
  202. value: 'csharp',
  203. language: 'csharp',
  204. code: `using Sentry;
  205. var eventId = SentrySdk.CaptureMessage("An event that will receive user feedback.");
  206. SentrySdk.CaptureUserFeedback(eventId, "user@example.com", "It broke.", "The User");`,
  207. },
  208. {
  209. label: 'F#',
  210. value: 'fsharp',
  211. language: 'fsharp',
  212. code: `open Sentry
  213. let eventId = SentrySdk.CaptureMessage("An event that will receive user feedback.")
  214. SentrySdk.CaptureUserFeedback(eventId, "user@example.com", "It broke.", "The User")`,
  215. },
  216. ],
  217. },
  218. ],
  219. additionalInfo: altCrashReportCallout(),
  220. },
  221. ],
  222. configure: () => [],
  223. verify: () => [],
  224. nextSteps: () => [],
  225. };
  226. const docs: Docs = {
  227. onboarding,
  228. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  229. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  230. };
  231. export default docs;