wpf.tsx 7.2 KB

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