winforms.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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;
  24. using System.Windows.Forms;
  25. using Sentry;
  26. static class Program
  27. {
  28. [STAThread]
  29. static void Main()
  30. {
  31. // Init the Sentry SDK
  32. SentrySdk.Init(o =>
  33. {
  34. // Tells which project in Sentry to send events to:
  35. o.Dsn = "${params.dsn}";
  36. // When configuring for the first time, to see what the SDK is doing:
  37. o.Debug = true;
  38. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  39. // We recommend adjusting this value in production.
  40. o.TracesSampleRate = 1.0;
  41. });
  42. // Configure WinForms to throw exceptions so Sentry can capture them.
  43. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
  44. // Any other configuration you might have goes here...
  45. Application.Run(new Form1());
  46. }
  47. }`;
  48. const getPerformanceInstrumentationSnippet = () => `
  49. // Transaction can be started by providing, at minimum, the name and the operation
  50. var transaction = SentrySdk.StartTransaction(
  51. "test-transaction-name",
  52. "test-transaction-operation"
  53. );
  54. // Transactions can have child spans (and those spans can have child spans as well)
  55. var span = transaction.StartChild("test-child-operation");
  56. // ...
  57. // (Perform the operation represented by the span/transaction)
  58. // ...
  59. span.Finish(); // Mark the span as finished
  60. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  61. const onboarding: OnboardingConfig = {
  62. install: params => [
  63. {
  64. type: StepType.INSTALL,
  65. description: tct('Install the [strong:NuGet] package:', {
  66. strong: <strong />,
  67. }),
  68. configurations: [
  69. {
  70. partialLoading: params.sourcePackageRegistries.isLoading,
  71. code: [
  72. {
  73. language: 'shell',
  74. label: 'Package Manager',
  75. value: 'packageManager',
  76. code: getInstallSnippetPackageManager(params),
  77. },
  78. {
  79. language: 'shell',
  80. label: '.NET Core CLI',
  81. value: 'coreCli',
  82. code: getInstallSnippetCoreCli(params),
  83. },
  84. ],
  85. },
  86. ],
  87. additionalInfo: (
  88. <AlertWithoutMarginBottom type="info">
  89. {tct(
  90. '[strong:Using .NET Framework prior to 4.6.1?] Our legacy SDK supports .NET Framework as early as 3.5.',
  91. {strong: <strong />}
  92. )}
  93. </AlertWithoutMarginBottom>
  94. ),
  95. },
  96. ],
  97. configure: params => [
  98. {
  99. type: StepType.CONFIGURE,
  100. description: tct(
  101. 'Initialize the SDK as early as possible, like in the constructor of the [code:App]:',
  102. {
  103. code: <code />,
  104. }
  105. ),
  106. configurations: [
  107. {
  108. language: 'csharp',
  109. code: getConfigureSnippet(params),
  110. },
  111. ],
  112. },
  113. ],
  114. verify: () => [
  115. {
  116. type: StepType.VERIFY,
  117. description: t('To verify your set up, you can capture a message with the SDK:'),
  118. configurations: [
  119. {
  120. language: 'csharp',
  121. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  122. },
  123. ],
  124. },
  125. {
  126. title: t('Performance Monitoring'),
  127. description: t(
  128. 'You can measure the performance of your code by capturing transactions and spans.'
  129. ),
  130. configurations: [
  131. {
  132. language: 'csharp',
  133. code: getPerformanceInstrumentationSnippet(),
  134. },
  135. ],
  136. additionalInfo: tct(
  137. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  138. {
  139. link: (
  140. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/performance/instrumentation/" />
  141. ),
  142. }
  143. ),
  144. },
  145. {
  146. title: t('Documentation'),
  147. description: tct(
  148. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete WinForms docs].",
  149. {
  150. link: (
  151. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/winforms/" />
  152. ),
  153. }
  154. ),
  155. },
  156. {
  157. title: t('Samples'),
  158. description: (
  159. <Fragment>
  160. {t(
  161. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  162. )}
  163. <List symbol="bullet">
  164. <ListItem>
  165. {tct(
  166. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  167. {
  168. link: (
  169. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  170. ),
  171. code: <code />,
  172. strong: <strong />,
  173. }
  174. )}
  175. </ListItem>
  176. <ListItem>
  177. {tct('[link:Basic F# sample] [strong:(F#)]', {
  178. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  179. strong: <strong />,
  180. })}
  181. </ListItem>
  182. </List>
  183. </Fragment>
  184. ),
  185. },
  186. ],
  187. };
  188. const docs: Docs = {
  189. onboarding,
  190. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  191. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  192. };
  193. export default docs;
  194. const AlertWithoutMarginBottom = styled(Alert)`
  195. margin-bottom: 0;
  196. `;