uwp.tsx 7.6 KB

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