Skip to content

Commit d670893

Browse files
Add MAUI Wizard page (#5271)
1 parent 583d59f commit d670893

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

src/wizard/dotnet/maui.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
name: Multi-platform App UI (MAUI)
3+
doc_link: https://docs.sentry.io/platforms/dotnet/guides/maui/
4+
support_level: production
5+
type: framework
6+
---
7+
8+
Install the **NuGet** package:
9+
10+
.NET Core CLI:
11+
12+
```shell
13+
dotnet add package Sentry.Maui -v 3.19.0-preview.2
14+
```
15+
16+
Or, with the Visual Studio Package Manager:
17+
18+
```powershell
19+
Install-Package Sentry.Maui -Version 3.19.0-preview.2
20+
```
21+
22+
Then add Sentry to `MauiProgram.cs` through the `MauiAppBuilder`:
23+
24+
```csharp
25+
public static MauiApp CreateMauiApp()
26+
{
27+
var builder = MauiApp.CreateBuilder();
28+
builder
29+
.UseMauiApp<App>()
30+
31+
// Add this section anywhere on the builder:
32+
.UseSentry(options =>
33+
{
34+
// The DSN is the only required setting.
35+
options.Dsn = "___PUBLIC_DSN___";
36+
37+
// Use debug mode if you want to see what the SDK is doing.
38+
// Debug messages are written to stdout with Console.Writeline,
39+
// and are viewable in your IDE's debug console or with 'adb logcat', etc.
40+
// This option is not recommended when deploying your application.
41+
options.Debug = true;
42+
43+
// Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
44+
// We recommend adjusting this value in production.
45+
options.TracesSampleRate = 1.0;
46+
47+
// Other Sentry options can be set here.
48+
})
49+
50+
// ... the remainder of your MAUI app setup
51+
52+
return builder.Build();
53+
}
54+
```
55+
56+
## Verify
57+
58+
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:
59+
60+
```csharp
61+
SentrySdk.CaptureMessage("Hello Sentry");
62+
```
63+
64+
### Performance monitoring
65+
66+
We do not yet have automatic performance instrumentation for .NET MAUI. We will be adding that in a future release.
67+
However, if desired you can still manually instrument parts of your application.
68+
69+
For some parts of your code, [automatic instrumentation](https://docs.sentry.io/platforms/dotnet/guides/maui/performance/instrumentation/automatic-instrumentation/) is available across all of our .NET SDKs, and can be used with MAUI as well:
70+
71+
- If your app uses `HttpClient`, you can instrument your HTTP calls by passing our HTTP message handler:
72+
```csharp
73+
var httpHandler = new SentryHttpMessageHandler();
74+
var httpClient = new HttpClient(httpHandler);
75+
```
76+
- If your app uses Entity Framework Core or SQL Client, we will automatically instrument that for you without any additional code.
77+
78+
For other parts of your code, you can use [custom instrumentation](https://docs.sentry.io/platforms/dotnet/guides/maui/performance/instrumentation/custom-instrumentation/), such as in the following example:
79+
80+
```csharp
81+
// Transaction can be started by providing, at minimum, the name and the operation
82+
var transaction = SentrySdk.StartTransaction(
83+
"test-transaction-name",
84+
"test-transaction-operation"
85+
);
86+
87+
// Transactions can have child spans (and those spans can have child spans as well)
88+
var span = transaction.StartChild("test-child-operation");
89+
90+
// ...
91+
// (Perform the operation represented by the span/transaction)
92+
// ...
93+
94+
span.Finish(); // Mark the span as finished
95+
transaction.Finish(); // Mark the transaction as finished and send it to Sentry
96+
```
97+
98+
## Sample Application
99+
100+
See the [MAUI Sample in the `sentry-dotnet` repository](https://github.com/getsentry/sentry-dotnet/tree/main/samples/Sentry.Samples.Maui).

0 commit comments

Comments
 (0)