uwp.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 {t, tct} from 'sentry/locale';
  14. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  15. type Params = DocsParams;
  16. const getInstallSnippetPackageManager = (params: Params) => `
  17. Install-Package Sentry -Version ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  18. const getInstallSnippetCoreCli = (params: Params) => `
  19. dotnet add package Sentry -v ${getPackageVersion(params, 'sentry.dotnet', '3.34.0')}`;
  20. const getConfigureSnippet = (params: Params) => `
  21. using System.Windows;
  22. using Sentry.Protocol;
  23. using Sentry;
  24. sealed partial class App : Application
  25. {
  26. protected override void OnLaunched(LaunchActivatedEventArgs e)
  27. {
  28. SentrySdk.Init(o =>
  29. {
  30. // Tells which project in Sentry to send events to:
  31. o.Dsn = "${params.dsn}";
  32. // When configuring for the first time, to see what the SDK is doing:
  33. o.Debug = true;
  34. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  35. // We recommend adjusting this value in production.
  36. o.TracesSampleRate = 1.0;
  37. });
  38. Current.UnhandledException += UnhandledExceptionHandler;
  39. }
  40. [HandleProcessCorruptedStateExceptions, SecurityCritical]
  41. internal void ExceptionHandler(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
  42. {
  43. // We need to hold the reference, because the Exception property is cleared when accessed.
  44. var exception = e.Exception;
  45. if (exception != null)
  46. {
  47. // Tells Sentry this was an Unhandled Exception
  48. exception.Data[Mechanism.HandledKey] = false;
  49. exception.Data[Mechanism.MechanismKey] = "Application.UnhandledException";
  50. SentrySdk.CaptureException(exception);
  51. // Make sure the event is flushed to disk or to Sentry
  52. SentrySdk.FlushAsync(TimeSpan.FromSeconds(3)).Wait();
  53. }
  54. }
  55. }`;
  56. const getPerformanceInstrumentationSnippet = () => `
  57. // Transaction can be started by providing, at minimum, the name and the operation
  58. var transaction = SentrySdk.StartTransaction(
  59. "test-transaction-name",
  60. "test-transaction-operation"
  61. );
  62. // Transactions can have child spans (and those spans can have child spans as well)
  63. var span = transaction.StartChild("test-child-operation");
  64. // ...
  65. // (Perform the operation represented by the span/transaction)
  66. // ...
  67. span.Finish(); // Mark the span as finished
  68. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  69. const onboarding: OnboardingConfig = {
  70. install: params => [
  71. {
  72. type: StepType.INSTALL,
  73. description: tct('Install the [strong:NuGet] package:', {
  74. strong: <strong />,
  75. }),
  76. configurations: [
  77. {
  78. partialLoading: params.sourcePackageRegistries.isLoading,
  79. code: [
  80. {
  81. language: 'shell',
  82. label: 'Package Manager',
  83. value: 'packageManager',
  84. code: getInstallSnippetPackageManager(params),
  85. },
  86. {
  87. language: 'shell',
  88. label: '.NET Core CLI',
  89. value: 'coreCli',
  90. code: getInstallSnippetCoreCli(params),
  91. },
  92. ],
  93. },
  94. ],
  95. additionalInfo: (
  96. <AlertWithoutMarginBottom type="info">
  97. {tct(
  98. '[strong:Using .NET Framework prior to 4.6.1?] Our legacy SDK supports .NET Framework as early as 3.5.',
  99. {strong: <strong />}
  100. )}
  101. </AlertWithoutMarginBottom>
  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('Performance Monitoring'),
  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/performance/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 docs: Docs = {
  216. onboarding,
  217. };
  218. export default docs;
  219. const AlertWithoutMarginBottom = styled(Alert)`
  220. margin-bottom: 0;
  221. `;