uwp.tsx 6.8 KB

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