winforms.tsx 6.0 KB

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