maui.tsx 7.5 KB

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