winforms.tsx 5.5 KB

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