maui.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {t, tct} from 'sentry/locale';
  10. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  11. type Params = DocsParams;
  12. const getInstallSnippetPackageManager = (params: Params) => `
  13. Install-Package Sentry.Maui -Version ${getPackageVersion(
  14. params,
  15. 'sentry.dotnet.maui',
  16. '3.34.0'
  17. )}`;
  18. const getInstallSnippetCoreCli = (params: Params) => `
  19. dotnet add package Sentry.Maui -v ${getPackageVersion(
  20. params,
  21. 'sentry.dotnet.maui',
  22. '3.34.0'
  23. )}`;
  24. const getConfigureSnippet = (params: Params) => `
  25. public static MauiApp CreateMauiApp()
  26. {
  27. var builder = MauiApp.CreateBuilder();
  28. builder
  29. .UseMauiApp<App>()
  30. // Add this section anywhere on the builder:
  31. .UseSentry(options => {
  32. // The DSN is the only required setting.
  33. options.Dsn = "${params.dsn}";
  34. // Use debug mode if you want to see what the SDK is doing.
  35. // Debug messages are written to stdout with Console.Writeline,
  36. // and are viewable in your IDE's debug console or with 'adb logcat', etc.
  37. // This option is not recommended when deploying your application.
  38. options.Debug = true;
  39. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  40. // We recommend adjusting this value in production.
  41. options.TracesSampleRate = 1.0;
  42. // Other Sentry options can be set here.
  43. })
  44. // ... the remainder of your MAUI app setup
  45. return builder.Build();
  46. }`;
  47. const getPerformanceMessageHandlerSnippet = () => `
  48. var httpHandler = new SentryHttpMessageHandler();
  49. var httpClient = new HttpClient(httpHandler);`;
  50. const getPerformanceInstrumentationSnippet = () => `
  51. // Transaction can be started by providing, at minimum, the name and the operation
  52. var transaction = SentrySdk.StartTransaction(
  53. "test-transaction-name",
  54. "test-transaction-operation"
  55. );
  56. // Transactions can have child spans (and those spans can have child spans as well)
  57. var span = transaction.StartChild("test-child-operation");
  58. // ...
  59. // (Perform the operation represented by the span/transaction)
  60. // ...
  61. span.Finish(); // Mark the span as finished
  62. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  63. const onboarding: OnboardingConfig = {
  64. install: params => [
  65. {
  66. type: StepType.INSTALL,
  67. description: tct('Install the [strong:NuGet] package:', {
  68. strong: <strong />,
  69. }),
  70. configurations: [
  71. {
  72. partialLoading: params.sourcePackageRegistries.isLoading,
  73. code: [
  74. {
  75. language: 'shell',
  76. label: 'Package Manager',
  77. value: 'packageManager',
  78. code: getInstallSnippetPackageManager(params),
  79. },
  80. {
  81. language: 'shell',
  82. label: '.NET Core CLI',
  83. value: 'coreCli',
  84. code: getInstallSnippetCoreCli(params),
  85. },
  86. ],
  87. },
  88. ],
  89. },
  90. ],
  91. configure: params => [
  92. {
  93. type: StepType.CONFIGURE,
  94. description: tct(
  95. 'Then add Sentry to [mauiProgram:MauiProgram.cs] through the [mauiAppBuilderCode:MauiAppBuilder]:',
  96. {
  97. mauiAppBuilderCode: <code />,
  98. mauiProgram: <code />,
  99. }
  100. ),
  101. configurations: [
  102. {
  103. language: 'csharp',
  104. code: getConfigureSnippet(params),
  105. },
  106. ],
  107. },
  108. ],
  109. verify: () => [
  110. {
  111. type: StepType.VERIFY,
  112. description: t(
  113. 'To verify your set up, you can capture a message with the SDK, anywhere in your code after the application is built, such as in a page constructor or button click event handler:'
  114. ),
  115. configurations: [
  116. {
  117. language: 'csharp',
  118. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  119. },
  120. ],
  121. },
  122. {
  123. title: t('Performance Monitoring'),
  124. description: (
  125. <Fragment>
  126. {t(
  127. 'We do not yet have automatic performance instrumentation for .NET MAUI. We will be adding that in a future release. However, if desired you can still manually instrument parts of your application.'
  128. )}
  129. <p>
  130. {tct(
  131. 'For some parts of your code, [automaticInstrumentationLink:automatic instrumentation] is available across all of our .NET SDKs, and can be used with MAUI as well:',
  132. {
  133. automaticInstrumentationLink: (
  134. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/maui/performance/instrumentation/automatic-instrumentation/" />
  135. ),
  136. }
  137. )}
  138. </p>
  139. </Fragment>
  140. ),
  141. configurations: [
  142. {
  143. description: tct(
  144. 'If your app uses [code:HttpClient], you can instrument your HTTP calls by passing our HTTP message handler:',
  145. {code: <code />}
  146. ),
  147. language: 'csharp',
  148. code: getPerformanceMessageHandlerSnippet(),
  149. },
  150. {
  151. description: (
  152. <Fragment>
  153. {t(
  154. 'If your app uses Entity Framework Core or SQL Client, we will automatically instrument that for you without any additional code.'
  155. )}
  156. <p>
  157. {tct(
  158. 'For other parts of your code, you can use [customInstrumentationLink:custom instrumentation], such as in the following example:',
  159. {
  160. customInstrumentationLink: (
  161. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/maui/performance/instrumentation/custom-instrumentation/" />
  162. ),
  163. }
  164. )}
  165. </p>
  166. </Fragment>
  167. ),
  168. language: 'csharp',
  169. code: getPerformanceInstrumentationSnippet(),
  170. },
  171. ],
  172. },
  173. {
  174. title: t('Sample Application'),
  175. description: tct(
  176. 'See the [mauiSampleLink:MAUI Sample in the [code:sentry-dotnet] repository].',
  177. {
  178. mauiSampleLink: (
  179. <ExternalLink href="https://github.com/getsentry/sentry-dotnet/tree/main/samples/Sentry.Samples.Maui" />
  180. ),
  181. code: <code />,
  182. }
  183. ),
  184. },
  185. ],
  186. };
  187. const docs: Docs = {
  188. onboarding,
  189. };
  190. export default docs;