uwp.tsx 8.4 KB

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