dotnet.tsx 8.9 KB

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