maui.tsx 6.6 KB

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