wpf.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  14. import {csharpFeedbackOnboarding} from 'sentry/gettingStartedDocs/dotnet/dotnet';
  15. import {t, tct} from 'sentry/locale';
  16. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  17. type Params = DocsParams;
  18. const getInstallSnippetPackageManager = (params: Params) => `
  19. Install-Package Sentry -Version ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  20. const getInstallSnippetCoreCli = (params: Params) => `
  21. dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  22. const getConfigureSnippet = (params: Params) => `
  23. using System.Windows.Threading;
  24. using System.Windows;
  25. using Sentry;
  26. public partial class App : Application
  27. {
  28. public App()
  29. {
  30. DispatcherUnhandledException += App_DispatcherUnhandledException;
  31. SentrySdk.Init(o =>
  32. {
  33. // Tells which project in Sentry to send events to:
  34. o.Dsn = "${params.dsn}";
  35. // When configuring for the first time, to see what the SDK is doing:
  36. o.Debug = true;
  37. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  38. // We recommend adjusting this value in production.
  39. o.TracesSampleRate = 1.0;
  40. });
  41. }
  42. void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
  43. {
  44. SentrySdk.CaptureException(e.Exception);
  45. // If you want to avoid the application from crashing:
  46. e.Handled = true;
  47. }`;
  48. const getPerformanceInstrumentationSnippet = () => `
  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. install: params => [
  63. {
  64. type: StepType.INSTALL,
  65. description: tct('Install the [strong:NuGet] package:', {
  66. strong: <strong />,
  67. }),
  68. configurations: [
  69. {
  70. partialLoading: params.sourcePackageRegistries.isLoading,
  71. code: [
  72. {
  73. language: 'shell',
  74. label: 'Package Manager',
  75. value: 'packageManager',
  76. code: getInstallSnippetPackageManager(params),
  77. },
  78. {
  79. language: 'shell',
  80. label: '.NET Core CLI',
  81. value: 'coreCli',
  82. code: getInstallSnippetCoreCli(params),
  83. },
  84. ],
  85. },
  86. ],
  87. additionalInfo: (
  88. <AlertWithoutMarginBottom type="info">
  89. {tct(
  90. '[strong:Using .NET Framework prior to 4.6.1?] Our legacy SDK supports .NET Framework as early as 3.5.',
  91. {strong: <strong />}
  92. )}
  93. </AlertWithoutMarginBottom>
  94. ),
  95. },
  96. ],
  97. configure: params => [
  98. {
  99. type: StepType.CONFIGURE,
  100. description: tct(
  101. 'Initialize the SDK as early as possible, like in the constructor of the [code:App]:',
  102. {
  103. code: <code />,
  104. }
  105. ),
  106. configurations: [
  107. {
  108. language: 'csharp',
  109. code: getConfigureSnippet(params),
  110. },
  111. ],
  112. },
  113. ],
  114. verify: () => [
  115. {
  116. type: StepType.VERIFY,
  117. description: t('To verify your set up, you can capture a message with the SDK:'),
  118. configurations: [
  119. {
  120. language: 'csharp',
  121. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  122. },
  123. ],
  124. },
  125. {
  126. title: t('Performance Monitoring'),
  127. description: t(
  128. 'You can measure the performance of your code by capturing transactions and spans.'
  129. ),
  130. configurations: [
  131. {
  132. language: 'csharp',
  133. code: getPerformanceInstrumentationSnippet(),
  134. },
  135. ],
  136. additionalInfo: tct(
  137. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  138. {
  139. link: (
  140. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/performance/instrumentation/" />
  141. ),
  142. }
  143. ),
  144. },
  145. {
  146. title: t('Documentation'),
  147. description: tct(
  148. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete WPF docs].",
  149. {
  150. link: (
  151. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/wpf/" />
  152. ),
  153. }
  154. ),
  155. },
  156. {
  157. title: t('Samples'),
  158. description: (
  159. <Fragment>
  160. {t(
  161. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  162. )}
  163. <List symbol="bullet">
  164. <ListItem>
  165. {tct(
  166. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  167. {
  168. link: (
  169. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  170. ),
  171. code: <code />,
  172. strong: <strong />,
  173. }
  174. )}
  175. </ListItem>
  176. <ListItem>
  177. {tct('[link:Basic F# sample] [strong:(F#)]', {
  178. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  179. strong: <strong />,
  180. })}
  181. </ListItem>
  182. </List>
  183. </Fragment>
  184. ),
  185. },
  186. ],
  187. };
  188. const docs: Docs = {
  189. onboarding,
  190. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  191. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  192. };
  193. export default docs;
  194. const AlertWithoutMarginBottom = styled(Alert)`
  195. margin-bottom: 0;
  196. `;