uwp.tsx 7.9 KB

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