wpf.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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 {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. getCrashReportGenericInstallStep,
  15. getCrashReportModalConfigDescription,
  16. getCrashReportModalIntroduction,
  17. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  18. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  19. import {csharpFeedbackOnboarding} from 'sentry/gettingStartedDocs/dotnet/dotnet';
  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. const getConfigureSnippet = (params: Params) => `
  48. using System.Windows.Threading;
  49. using System.Windows;
  50. using Sentry;
  51. public partial class App : Application
  52. {
  53. public App()
  54. {
  55. DispatcherUnhandledException += App_DispatcherUnhandledException;
  56. SentrySdk.Init(o =>
  57. {
  58. // Tells which project in Sentry to send events to:
  59. o.Dsn = "${params.dsn.public}";
  60. // When configuring for the first time, to see what the SDK is doing:
  61. o.Debug = true;${
  62. params.isPerformanceSelected
  63. ? `
  64. // Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
  65. // We recommend adjusting this value in production.
  66. o.TracesSampleRate = 1.0;`
  67. : ''
  68. }${
  69. params.isProfilingSelected
  70. ? `
  71. // Sample rate for profiling, applied on top of othe TracesSampleRate,
  72. // e.g. 0.2 means we want to profile 20 % of the captured transactions.
  73. // We recommend adjusting this value in production.
  74. o.ProfilesSampleRate = 1.0;
  75. // Requires NuGet package: Sentry.Profiling
  76. // Note: By default, the profiler is initialized asynchronously. This can
  77. // be tuned by passing a desired initialization timeout to the constructor.
  78. o.AddIntegration(new ProfilingIntegration(
  79. // During startup, wait up to 500ms to profile the app startup code.
  80. // This could make launching the app a bit slower so comment it out if you
  81. // prefer profiling to start asynchronously
  82. TimeSpan.FromMilliseconds(500)
  83. ));`
  84. : ''
  85. }
  86. });
  87. }
  88. void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  89. {
  90. SentrySdk.CaptureException(e.Exception);
  91. // If you want to avoid the application from crashing:
  92. e.Handled = true;
  93. }`;
  94. const getPerformanceInstrumentationSnippet = () => `
  95. // Transaction can be started by providing, at minimum, the name and the operation
  96. var transaction = SentrySdk.StartTransaction(
  97. "test-transaction-name",
  98. "test-transaction-operation"
  99. );
  100. // Transactions can have child spans (and those spans can have child spans as well)
  101. var span = transaction.StartChild("test-child-operation");
  102. // ...
  103. // (Perform the operation represented by the span/transaction)
  104. // ...
  105. span.Finish(); // Mark the span as finished
  106. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  107. const onboarding: OnboardingConfig = {
  108. install: params => [
  109. {
  110. type: StepType.INSTALL,
  111. description: tct('Install the [strong:NuGet] package:', {
  112. strong: <strong />,
  113. }),
  114. configurations: [
  115. {
  116. partialLoading: params.sourcePackageRegistries.isLoading,
  117. code: [
  118. {
  119. language: 'shell',
  120. label: 'Package Manager',
  121. value: 'packageManager',
  122. code: getInstallSnippetPackageManager(params),
  123. },
  124. {
  125. language: 'shell',
  126. label: '.NET Core CLI',
  127. value: 'coreCli',
  128. code: getInstallSnippetCoreCli(params),
  129. },
  130. ],
  131. },
  132. ...(params.isProfilingSelected
  133. ? [
  134. {
  135. description: tct(
  136. 'Additionally, you need to add a dependency on the [sentryProfilingPackage:Sentry.Profiling] NuGet package.',
  137. {
  138. sentryProfilingPackage: <code />,
  139. }
  140. ),
  141. code: [
  142. {
  143. language: 'shell',
  144. label: 'Package Manager',
  145. value: 'packageManager',
  146. code: getInstallProfilingSnippetPackageManager(params),
  147. },
  148. {
  149. language: 'shell',
  150. label: '.NET Core CLI',
  151. value: 'coreCli',
  152. code: getInstallProfilingSnippetCoreCli(params),
  153. },
  154. ],
  155. },
  156. {
  157. description: (
  158. <AlertWithoutMarginBottom type="info">
  159. {t('Profiling for .NET Framework is not supported.')}
  160. </AlertWithoutMarginBottom>
  161. ),
  162. },
  163. ]
  164. : []),
  165. ],
  166. },
  167. ],
  168. configure: params => [
  169. {
  170. type: StepType.CONFIGURE,
  171. description: tct(
  172. 'Initialize the SDK as early as possible, like in the constructor of the [code:App]:',
  173. {
  174. code: <code />,
  175. }
  176. ),
  177. configurations: [
  178. {
  179. language: 'csharp',
  180. code: getConfigureSnippet(params),
  181. },
  182. ],
  183. },
  184. ],
  185. verify: params => [
  186. {
  187. type: StepType.VERIFY,
  188. description: t('To verify your set up, you can capture a message with the SDK:'),
  189. configurations: [
  190. {
  191. language: 'csharp',
  192. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  193. },
  194. ],
  195. },
  196. ...(params.isPerformanceSelected
  197. ? [
  198. {
  199. title: t('Tracing'),
  200. description: t(
  201. 'You can measure the performance of your code by capturing transactions and spans.'
  202. ),
  203. configurations: [
  204. {
  205. language: 'csharp',
  206. code: getPerformanceInstrumentationSnippet(),
  207. },
  208. ],
  209. additionalInfo: tct(
  210. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  211. {
  212. link: (
  213. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/tracing/instrumentation/" />
  214. ),
  215. }
  216. ),
  217. },
  218. {
  219. title: t('Documentation'),
  220. description: tct(
  221. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete WPF docs].",
  222. {
  223. link: (
  224. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/wpf/" />
  225. ),
  226. }
  227. ),
  228. },
  229. ]
  230. : []),
  231. {
  232. title: t('Samples'),
  233. description: (
  234. <Fragment>
  235. {t(
  236. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  237. )}
  238. <List symbol="bullet">
  239. <ListItem>
  240. {tct(
  241. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  242. {
  243. link: (
  244. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  245. ),
  246. code: <code />,
  247. strong: <strong />,
  248. }
  249. )}
  250. </ListItem>
  251. <ListItem>
  252. {tct('[link:Basic F# sample] [strong:(F#)]', {
  253. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  254. strong: <strong />,
  255. })}
  256. </ListItem>
  257. </List>
  258. </Fragment>
  259. ),
  260. },
  261. ],
  262. };
  263. const crashReportOnboarding: OnboardingConfig = {
  264. introduction: () => getCrashReportModalIntroduction(),
  265. install: (params: Params) => getCrashReportGenericInstallStep(params),
  266. configure: () => [
  267. {
  268. type: StepType.CONFIGURE,
  269. description: getCrashReportModalConfigDescription({
  270. link: 'https://docs.sentry.io/platforms/dotnet/guides/wpf/user-feedback/configuration/#crash-report-modal',
  271. }),
  272. },
  273. ],
  274. verify: () => [],
  275. nextSteps: () => [],
  276. };
  277. const docs: Docs = {
  278. onboarding,
  279. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  280. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  281. crashReportOnboarding,
  282. };
  283. export default docs;
  284. const AlertWithoutMarginBottom = styled(Alert)`
  285. margin-bottom: 0;
  286. `;