winforms.tsx 6.1 KB

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