winforms.tsx 6.3 KB

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