wpf.tsx 9.4 KB

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