uwp.tsx 7.7 KB

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