uwp.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {
  12. getCrashReportGenericInstallStep,
  13. getCrashReportModalConfigDescription,
  14. getCrashReportModalIntroduction,
  15. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  16. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  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(params, 'sentry.dotnet', '3.34.0')}`;
  23. const getInstallSnippetCoreCli = (params: Params) => `
  24. dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  25. const getConfigureSnippet = (params: Params) => `
  26. using System.Windows;
  27. using Sentry.Protocol;
  28. using Sentry;
  29. sealed partial class App : Application
  30. {
  31. protected override void OnLaunched(LaunchActivatedEventArgs e)
  32. {
  33. SentrySdk.Init(o =>
  34. {
  35. // Tells which project in Sentry to send events to:
  36. o.Dsn = "${params.dsn.public}";
  37. // When configuring for the first time, to see what the SDK is doing:
  38. o.Debug = true;${
  39. params.isPerformanceSelected
  40. ? `
  41. // Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
  42. // We recommend adjusting this value in production.
  43. o.TracesSampleRate = 1.0;`
  44. : ''
  45. }
  46. });
  47. Current.UnhandledException += UnhandledExceptionHandler;
  48. }
  49. [HandleProcessCorruptedStateExceptions, SecurityCritical]
  50. internal void ExceptionHandler(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
  51. {
  52. // We need to hold the reference, because the Exception property is cleared when accessed.
  53. var exception = e.Exception;
  54. if (exception != null)
  55. {
  56. // Tells Sentry this was an Unhandled Exception
  57. exception.Data[Mechanism.HandledKey] = false;
  58. exception.Data[Mechanism.MechanismKey] = "Application.UnhandledException";
  59. SentrySdk.CaptureException(exception);
  60. // Make sure the event is flushed to disk or to Sentry
  61. SentrySdk.FlushAsync(TimeSpan.FromSeconds(3)).Wait();
  62. }
  63. }
  64. }`;
  65. const getPerformanceInstrumentationSnippet = () => `
  66. // Transaction can be started by providing, at minimum, the name and the operation
  67. var transaction = SentrySdk.StartTransaction(
  68. "test-transaction-name",
  69. "test-transaction-operation"
  70. );
  71. // Transactions can have child spans (and those spans can have child spans as well)
  72. var span = transaction.StartChild("test-child-operation");
  73. // ...
  74. // (Perform the operation represented by the span/transaction)
  75. // ...
  76. span.Finish(); // Mark the span as finished
  77. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  78. const onboarding: OnboardingConfig = {
  79. install: params => [
  80. {
  81. type: StepType.INSTALL,
  82. description: tct('Install the [strong:NuGet] package:', {
  83. strong: <strong />,
  84. }),
  85. configurations: [
  86. {
  87. partialLoading: params.sourcePackageRegistries.isLoading,
  88. code: [
  89. {
  90. language: 'shell',
  91. label: 'Package Manager',
  92. value: 'packageManager',
  93. code: getInstallSnippetPackageManager(params),
  94. },
  95. {
  96. language: 'shell',
  97. label: '.NET Core CLI',
  98. value: 'coreCli',
  99. code: getInstallSnippetCoreCli(params),
  100. },
  101. ],
  102. },
  103. ],
  104. },
  105. ],
  106. configure: params => [
  107. {
  108. type: StepType.CONFIGURE,
  109. description: tct(
  110. 'Initialize the SDK as early as possible, like in the constructor of the [code:App]:',
  111. {
  112. code: <code />,
  113. }
  114. ),
  115. configurations: [
  116. {
  117. language: 'csharp',
  118. code: getConfigureSnippet(params),
  119. },
  120. ],
  121. },
  122. ],
  123. verify: () => [
  124. {
  125. type: StepType.VERIFY,
  126. description: t('To verify your set up, you can capture a message with the SDK:'),
  127. configurations: [
  128. {
  129. language: 'csharp',
  130. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  131. },
  132. ],
  133. additionalInfo: tct(
  134. "If you don't want to depend on the static class, the SDK registers a client in the DI container. In this case, you can [link:take [code:IHub] as a dependency].",
  135. {
  136. code: <code />,
  137. link: (
  138. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/unit-testing/" />
  139. ),
  140. }
  141. ),
  142. },
  143. {
  144. title: t('Tracing'),
  145. description: t(
  146. 'You can measure the performance of your code by capturing transactions and spans.'
  147. ),
  148. configurations: [
  149. {
  150. language: 'csharp',
  151. code: getPerformanceInstrumentationSnippet(),
  152. },
  153. ],
  154. additionalInfo: tct(
  155. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  156. {
  157. link: (
  158. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/tracing/instrumentation/" />
  159. ),
  160. }
  161. ),
  162. },
  163. {
  164. title: t('Documentation'),
  165. description: tct(
  166. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete UWP docs].",
  167. {
  168. link: (
  169. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/uwp/" />
  170. ),
  171. }
  172. ),
  173. },
  174. {
  175. title: t('Samples'),
  176. description: (
  177. <Fragment>
  178. <p>
  179. {tct(
  180. 'You can find an example UWP app with Sentry integrated [link:on this GitHub repository].',
  181. {
  182. link: (
  183. <ExternalLink href="https://github.com/getsentry/examples/tree/master/dotnet/UwpCSharp" />
  184. ),
  185. }
  186. )}
  187. </p>
  188. {t(
  189. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  190. )}
  191. <List symbol="bullet">
  192. <ListItem>
  193. {tct(
  194. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  195. {
  196. link: (
  197. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  198. ),
  199. code: <code />,
  200. strong: <strong />,
  201. }
  202. )}
  203. </ListItem>
  204. <ListItem>
  205. {tct('[link:Basic F# sample] [strong:(F#)]', {
  206. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  207. strong: <strong />,
  208. })}
  209. </ListItem>
  210. </List>
  211. </Fragment>
  212. ),
  213. },
  214. ],
  215. };
  216. const crashReportOnboarding: OnboardingConfig = {
  217. introduction: () => getCrashReportModalIntroduction(),
  218. install: (params: Params) => getCrashReportGenericInstallStep(params),
  219. configure: () => [
  220. {
  221. type: StepType.CONFIGURE,
  222. description: getCrashReportModalConfigDescription({
  223. link: 'https://docs.sentry.io/platforms/dotnet/guides/uwp/user-feedback/configuration/#crash-report-modal',
  224. }),
  225. },
  226. ],
  227. verify: () => [],
  228. nextSteps: () => [],
  229. };
  230. const docs: Docs = {
  231. onboarding,
  232. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  233. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  234. crashReportOnboarding,
  235. };
  236. export default docs;