maui.tsx 5.7 KB

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