maui.tsx 6.8 KB

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