dotnet.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. import {Fragment} from 'react';
  2. import {Alert} from 'sentry/components/core/alert';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import List from 'sentry/components/list';
  5. import ListItem from 'sentry/components/list/listItem';
  6. import altCrashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/altCrashReportCallout';
  7. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  8. import type {
  9. Docs,
  10. DocsParams,
  11. OnboardingConfig,
  12. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  13. import {
  14. getCrashReportApiIntroduction,
  15. getCrashReportGenericInstallStep,
  16. getCrashReportInstallDescription,
  17. getCrashReportModalConfigDescription,
  18. getCrashReportModalIntroduction,
  19. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  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(
  25. params,
  26. 'sentry.dotnet',
  27. params.isProfilingSelected ? '4.3.0' : '3.34.0'
  28. )}`;
  29. const getInstallSnippetCoreCli = (params: Params) => `
  30. dotnet add package Sentry -v ${getPackageVersion(
  31. params,
  32. 'sentry.dotnet',
  33. params.isProfilingSelected ? '4.3.0' : '3.34.0'
  34. )}`;
  35. const getInstallProfilingSnippetPackageManager = (params: Params) => `
  36. Install-Package Sentry.Profiling -Version ${getPackageVersion(
  37. params,
  38. 'sentry.dotnet.profiling',
  39. '4.3.0'
  40. )}`;
  41. const getInstallProfilingSnippetCoreCli = (params: Params) => `
  42. dotnet add package Sentry.Profiling -v ${getPackageVersion(
  43. params,
  44. 'sentry.dotnet.profiling',
  45. '4.3.0'
  46. )}`;
  47. enum DotNetPlatform {
  48. WINDOWS = 0,
  49. IOS_MACCATALYST = 1,
  50. }
  51. const getConfigureSnippet = (params: Params, platform?: DotNetPlatform) => `
  52. using Sentry;
  53. SentrySdk.Init(options =>
  54. {
  55. // A Sentry Data Source Name (DSN) is required.
  56. // See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
  57. // You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
  58. options.Dsn = "${params.dsn.public}";
  59. // When debug is enabled, the Sentry client will emit detailed debugging information to the console.
  60. // This might be helpful, or might interfere with the normal operation of your application.
  61. // We enable it here for demonstration purposes when first trying Sentry.
  62. // You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
  63. options.Debug = true;
  64. // This option is recommended. It enables Sentry's "Release Health" feature.
  65. options.AutoSessionTracking = true;${
  66. params.isPerformanceSelected
  67. ? `
  68. // Set TracesSampleRate to 1.0 to capture 100%
  69. // of transactions for tracing.
  70. // We recommend adjusting this value in production.
  71. options.TracesSampleRate = 1.0;`
  72. : ''
  73. }${
  74. params.isProfilingSelected
  75. ? `
  76. // Sample rate for profiling, applied on top of othe TracesSampleRate,
  77. // e.g. 0.2 means we want to profile 20 % of the captured transactions.
  78. // We recommend adjusting this value in production.
  79. options.ProfilesSampleRate = 1.0;${
  80. platform !== DotNetPlatform.IOS_MACCATALYST
  81. ? `
  82. // Requires NuGet package: Sentry.Profiling
  83. // Note: By default, the profiler is initialized asynchronously. This can
  84. // be tuned by passing a desired initialization timeout to the constructor.
  85. options.AddIntegration(new ProfilingIntegration(
  86. // During startup, wait up to 500ms to profile the app startup code.
  87. // This could make launching the app a bit slower so comment it out if you
  88. // prefer profiling to start asynchronously
  89. TimeSpan.FromMilliseconds(500)
  90. ));`
  91. : ''
  92. }`
  93. : ''
  94. }
  95. });`;
  96. const getPerformanceMonitoringSnippet = () => `
  97. // Transaction can be started by providing, at minimum, the name and the operation
  98. var transaction = SentrySdk.StartTransaction(
  99. "test-transaction-name",
  100. "test-transaction-operation"
  101. );
  102. // Transactions can have child spans (and those spans can have child spans as well)
  103. var span = transaction.StartChild("test-child-operation");
  104. // ...
  105. // (Perform the operation represented by the span/transaction)
  106. // ...
  107. span.Finish(); // Mark the span as finished
  108. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  109. const onboarding: OnboardingConfig = {
  110. introduction: () =>
  111. tct(
  112. '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.',
  113. {
  114. strong: <strong />,
  115. link: <ExternalLink href="https://docs.sentry.io/platforms/dotnet/" />,
  116. }
  117. ),
  118. install: params => [
  119. {
  120. type: StepType.INSTALL,
  121. description: tct('Install the [strong:NuGet] package:', {
  122. strong: <strong />,
  123. }),
  124. configurations: [
  125. {
  126. partialLoading: params.sourcePackageRegistries.isLoading,
  127. code: [
  128. {
  129. language: 'shell',
  130. label: 'Package Manager',
  131. value: 'packageManager',
  132. code: getInstallSnippetPackageManager(params),
  133. },
  134. {
  135. language: 'shell',
  136. label: '.NET Core CLI',
  137. value: 'coreCli',
  138. code: getInstallSnippetCoreCli(params),
  139. },
  140. ],
  141. },
  142. ...(params.isProfilingSelected
  143. ? [
  144. {
  145. description: tct(
  146. 'Additionally, for all platforms except iOS/Mac Catalyst, you need to add a dependency on the [sentryProfilingPackage:Sentry.Profiling] NuGet package.',
  147. {
  148. sentryProfilingPackage: <code />,
  149. }
  150. ),
  151. code: [
  152. {
  153. language: 'shell',
  154. label: 'Package Manager',
  155. value: 'packageManager',
  156. code: getInstallProfilingSnippetPackageManager(params),
  157. },
  158. {
  159. language: 'shell',
  160. label: '.NET Core CLI',
  161. value: 'coreCli',
  162. code: getInstallProfilingSnippetCoreCli(params),
  163. },
  164. ],
  165. },
  166. {
  167. description: (
  168. <Alert type="info">
  169. {t(
  170. 'Profiling for .NET Framework and .NET on Android are not supported.'
  171. )}
  172. </Alert>
  173. ),
  174. },
  175. ]
  176. : []),
  177. ],
  178. },
  179. ],
  180. configure: params => [
  181. {
  182. type: StepType.CONFIGURE,
  183. description: tct(
  184. 'Initialize the SDK as early as possible. For example, call [code:SentrySdk.Init] in your [code:Program.cs] file:',
  185. {
  186. code: <code />,
  187. }
  188. ),
  189. configurations: [
  190. params.isProfilingSelected
  191. ? {
  192. code: [
  193. {
  194. language: 'csharp',
  195. label: 'Windows/Linux/macOS',
  196. value: 'windows/linux/macos',
  197. code: getConfigureSnippet(params, DotNetPlatform.WINDOWS),
  198. },
  199. {
  200. language: 'csharp',
  201. label: 'iOS/Mac Catalyst',
  202. value: 'ios/macCatalyst',
  203. code: getConfigureSnippet(params, DotNetPlatform.IOS_MACCATALYST),
  204. },
  205. ],
  206. }
  207. : {
  208. language: 'csharp',
  209. code: getConfigureSnippet(params),
  210. },
  211. ],
  212. },
  213. ],
  214. verify: (params: Params) => [
  215. {
  216. type: StepType.VERIFY,
  217. description: t('Verify Sentry is correctly configured by sending a message:'),
  218. configurations: [
  219. {
  220. language: 'csharp',
  221. code: 'SentrySdk.CaptureMessage("Something went wrong");',
  222. },
  223. ],
  224. },
  225. ...(params.isPerformanceSelected
  226. ? [
  227. {
  228. title: t('Tracing'),
  229. description: t(
  230. 'You can measure the performance of your code by capturing transactions and spans.'
  231. ),
  232. configurations: [
  233. {
  234. language: 'csharp',
  235. code: getPerformanceMonitoringSnippet(),
  236. },
  237. ],
  238. additionalInfo: tct(
  239. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  240. {
  241. link: (
  242. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/tracing/instrumentation/" />
  243. ),
  244. }
  245. ),
  246. },
  247. ]
  248. : []),
  249. {
  250. title: t('Samples'),
  251. description: (
  252. <Fragment>
  253. <p>
  254. {tct(
  255. 'You can find an example ASP.NET MVC 5 app with Sentry integrated [link:on this GitHub repository].',
  256. {
  257. link: (
  258. <ExternalLink href="https://github.com/getsentry/examples/tree/master/dotnet/AspNetMvc5Ef6" />
  259. ),
  260. }
  261. )}
  262. </p>
  263. {t(
  264. 'In addition, these examples demonstrate how to integrate Sentry with various frameworks:'
  265. )}
  266. </Fragment>
  267. ),
  268. configurations: [
  269. {
  270. description: (
  271. <List symbol="bullet">
  272. <ListItem>
  273. {tct(
  274. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  275. {
  276. link: (
  277. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  278. ),
  279. code: <code />,
  280. strong: <strong />,
  281. }
  282. )}
  283. </ListItem>
  284. <ListItem>
  285. {tct('[link:Basic F# sample] [strong:(F#)]', {
  286. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  287. strong: <strong />,
  288. })}
  289. </ListItem>
  290. </List>
  291. ),
  292. },
  293. ],
  294. },
  295. ],
  296. };
  297. export const csharpFeedbackOnboarding: OnboardingConfig = {
  298. introduction: () => getCrashReportApiIntroduction(),
  299. install: () => [
  300. {
  301. type: StepType.INSTALL,
  302. description: getCrashReportInstallDescription(),
  303. configurations: [
  304. {
  305. code: [
  306. {
  307. label: 'C#',
  308. value: 'csharp',
  309. language: 'csharp',
  310. code: `using Sentry;
  311. var eventId = SentrySdk.CaptureMessage("An event that will receive user feedback.");
  312. SentrySdk.CaptureUserFeedback(eventId, "user@example.com", "It broke.", "The User");`,
  313. },
  314. {
  315. label: 'F#',
  316. value: 'fsharp',
  317. language: 'fsharp',
  318. code: `open Sentry
  319. let eventId = SentrySdk.CaptureMessage("An event that will receive user feedback.")
  320. SentrySdk.CaptureUserFeedback(eventId, "user@example.com", "It broke.", "The User")`,
  321. },
  322. ],
  323. },
  324. ],
  325. additionalInfo: altCrashReportCallout(),
  326. },
  327. ],
  328. configure: () => [],
  329. verify: () => [],
  330. nextSteps: () => [],
  331. };
  332. const crashReportOnboarding: OnboardingConfig = {
  333. introduction: () => getCrashReportModalIntroduction(),
  334. install: (params: Params) => getCrashReportGenericInstallStep(params),
  335. configure: () => [
  336. {
  337. type: StepType.CONFIGURE,
  338. description: getCrashReportModalConfigDescription({
  339. link: 'https://docs.sentry.io/platforms/dotnet/user-feedback/configuration/#crash-report-modal',
  340. }),
  341. },
  342. ],
  343. verify: () => [],
  344. nextSteps: () => [],
  345. };
  346. const docs: Docs = {
  347. onboarding,
  348. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  349. crashReportOnboarding,
  350. };
  351. export default docs;