maui.tsx 6.3 KB

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