dotnet.tsx 12 KB

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