winforms.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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 {
  14. getCrashReportGenericInstallStep,
  15. getCrashReportModalConfigDescription,
  16. getCrashReportModalIntroduction,
  17. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  18. import {getDotnetMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  19. import {csharpFeedbackOnboarding} from 'sentry/gettingStartedDocs/dotnet/dotnet';
  20. import {t, tct} from 'sentry/locale';
  21. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  22. type Params = DocsParams;
  23. const getInstallSnippetPackageManager = (params: Params) => `
  24. Install-Package Sentry -Version ${getPackageVersion(
  25. params,
  26. 'sentry.dotnet',
  27. params.isProfilingSelected ? '4.3.0' : '3.34.0'
  28. )}`;
  29. const getInstallSnippetCoreCli = (params: Params) => `
  30. dotnet add package Sentry -v ${getPackageVersion(
  31. params,
  32. 'sentry.dotnet',
  33. params.isProfilingSelected ? '4.3.0' : '3.34.0'
  34. )}`;
  35. const getInstallProfilingSnippetPackageManager = (params: Params) => `
  36. Install-Package Sentry.Profiling -Version ${getPackageVersion(
  37. params,
  38. 'sentry.dotnet.profiling',
  39. '4.3.0'
  40. )}`;
  41. const getInstallProfilingSnippetCoreCli = (params: Params) => `
  42. dotnet add package Sentry.Profiling -v ${getPackageVersion(
  43. params,
  44. 'sentry.dotnet.profiling',
  45. '4.3.0'
  46. )}`;
  47. const getConfigureSnippet = (params: Params) => `
  48. using System;
  49. using System.Windows.Forms;
  50. using Sentry;
  51. static class Program
  52. {
  53. [STAThread]
  54. static void Main()
  55. {
  56. // Init the Sentry SDK
  57. SentrySdk.Init(o =>
  58. {
  59. // Tells which project in Sentry to send events to:
  60. o.Dsn = "${params.dsn}";
  61. // When configuring for the first time, to see what the SDK is doing:
  62. o.Debug = true;${
  63. params.isPerformanceSelected
  64. ? `
  65. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  66. // We recommend adjusting this value in production.
  67. o.TracesSampleRate = 1.0;`
  68. : ''
  69. }${
  70. params.isProfilingSelected
  71. ? `
  72. // Sample rate for profiling, applied on top of othe TracesSampleRate,
  73. // e.g. 0.2 means we want to profile 20 % of the captured transactions.
  74. // We recommend adjusting this value in production.
  75. o.ProfilesSampleRate = 1.0;
  76. // Requires NuGet package: Sentry.Profiling
  77. // Note: By default, the profiler is initialized asynchronously. This can
  78. // be tuned by passing a desired initialization timeout to the constructor.
  79. o.AddIntegration(new ProfilingIntegration(
  80. // During startup, wait up to 500ms to profile the app startup code.
  81. // This could make launching the app a bit slower so comment it out if you
  82. // prefer profiling to start asynchronously
  83. TimeSpan.FromMilliseconds(500)
  84. ));`
  85. : ''
  86. }
  87. }
  88. });
  89. // Configure WinForms to throw exceptions so Sentry can capture them.
  90. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
  91. // Any other configuration you might have goes here...
  92. Application.Run(new Form1());
  93. }
  94. }`;
  95. const getPerformanceInstrumentationSnippet = () => `
  96. // Transaction can be started by providing, at minimum, the name and the operation
  97. var transaction = SentrySdk.StartTransaction(
  98. "test-transaction-name",
  99. "test-transaction-operation"
  100. );
  101. // Transactions can have child spans (and those spans can have child spans as well)
  102. var span = transaction.StartChild("test-child-operation");
  103. // ...
  104. // (Perform the operation represented by the span/transaction)
  105. // ...
  106. span.Finish(); // Mark the span as finished
  107. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  108. const onboarding: OnboardingConfig = {
  109. install: params => [
  110. {
  111. type: StepType.INSTALL,
  112. description: tct('Install the [strong:NuGet] package:', {
  113. strong: <strong />,
  114. }),
  115. configurations: [
  116. {
  117. partialLoading: params.sourcePackageRegistries.isLoading,
  118. code: [
  119. {
  120. language: 'shell',
  121. label: 'Package Manager',
  122. value: 'packageManager',
  123. code: getInstallSnippetPackageManager(params),
  124. },
  125. {
  126. language: 'shell',
  127. label: '.NET Core CLI',
  128. value: 'coreCli',
  129. code: getInstallSnippetCoreCli(params),
  130. },
  131. ],
  132. },
  133. ...(params.isProfilingSelected
  134. ? [
  135. {
  136. description: tct(
  137. 'Additionally, you need to add a dependency on the [sentryProfilingPackage:Sentry.Profiling] NuGet package.',
  138. {
  139. sentryProfilingPackage: <code />,
  140. }
  141. ),
  142. code: [
  143. {
  144. language: 'shell',
  145. label: 'Package Manager',
  146. value: 'packageManager',
  147. code: getInstallProfilingSnippetPackageManager(params),
  148. },
  149. {
  150. language: 'shell',
  151. label: '.NET Core CLI',
  152. value: 'coreCli',
  153. code: getInstallProfilingSnippetCoreCli(params),
  154. },
  155. ],
  156. },
  157. {
  158. description: (
  159. <AlertWithoutMarginBottom type="info">
  160. {t('Profiling for .NET Framework is not supported.')}
  161. </AlertWithoutMarginBottom>
  162. ),
  163. },
  164. ]
  165. : []),
  166. ],
  167. },
  168. ],
  169. configure: params => [
  170. {
  171. type: StepType.CONFIGURE,
  172. description: tct(
  173. 'Initialize the SDK as early as possible, like in the constructor of the [code:App]:',
  174. {
  175. code: <code />,
  176. }
  177. ),
  178. configurations: [
  179. {
  180. language: 'csharp',
  181. code: getConfigureSnippet(params),
  182. },
  183. ],
  184. },
  185. ],
  186. verify: params => [
  187. {
  188. type: StepType.VERIFY,
  189. description: t('To verify your set up, you can capture a message with the SDK:'),
  190. configurations: [
  191. {
  192. language: 'csharp',
  193. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  194. },
  195. ],
  196. },
  197. ...(params.isPerformanceSelected
  198. ? [
  199. {
  200. title: t('Performance Monitoring'),
  201. description: t(
  202. 'You can measure the performance of your code by capturing transactions and spans.'
  203. ),
  204. configurations: [
  205. {
  206. language: 'csharp',
  207. code: getPerformanceInstrumentationSnippet(),
  208. },
  209. ],
  210. additionalInfo: tct(
  211. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  212. {
  213. link: (
  214. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/performance/instrumentation/" />
  215. ),
  216. }
  217. ),
  218. },
  219. {
  220. title: t('Documentation'),
  221. description: tct(
  222. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete WinForms docs].",
  223. {
  224. link: (
  225. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/winforms/" />
  226. ),
  227. }
  228. ),
  229. },
  230. ]
  231. : []),
  232. {
  233. title: t('Samples'),
  234. description: (
  235. <Fragment>
  236. {t(
  237. 'See the following examples that demonstrate how to integrate Sentry with various frameworks.'
  238. )}
  239. <List symbol="bullet">
  240. <ListItem>
  241. {tct(
  242. '[link:Multiple samples in the [code:dotnet] SDK repository] [strong:(C#)]',
  243. {
  244. link: (
  245. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples" />
  246. ),
  247. code: <code />,
  248. strong: <strong />,
  249. }
  250. )}
  251. </ListItem>
  252. <ListItem>
  253. {tct('[link:Basic F# sample] [strong:(F#)]', {
  254. link: <ExternalLink href="https://github.com/sentry-demos/fsharp" />,
  255. strong: <strong />,
  256. })}
  257. </ListItem>
  258. </List>
  259. </Fragment>
  260. ),
  261. },
  262. ],
  263. };
  264. const crashReportOnboarding: OnboardingConfig = {
  265. introduction: () => getCrashReportModalIntroduction(),
  266. install: (params: Params) => getCrashReportGenericInstallStep(params),
  267. configure: () => [
  268. {
  269. type: StepType.CONFIGURE,
  270. description: getCrashReportModalConfigDescription({
  271. link: 'https://docs.sentry.io/platforms/dotnet/guides/winforms/user-feedback/configuration/#crash-report-modal',
  272. }),
  273. },
  274. ],
  275. verify: () => [],
  276. nextSteps: () => [],
  277. };
  278. const docs: Docs = {
  279. onboarding,
  280. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  281. customMetricsOnboarding: getDotnetMetricsOnboarding({packageName: 'Sentry'}),
  282. crashReportOnboarding,
  283. };
  284. export default docs;
  285. const AlertWithoutMarginBottom = styled(Alert)`
  286. margin-bottom: 0;
  287. `;