uwp.tsx 7.3 KB

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