Skip to content

Commit 6c4e3f8

Browse files
Guides for .NET for Android and .NET for apple platforms
1 parent 8af147d commit 6c4e3f8

File tree

2 files changed

+216
-0
lines changed

2 files changed

+216
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: .NET for Android
3+
sdk: sentry.dotnet.android
4+
description: "Learn about Sentry's .NET integration with .NET for Android"
5+
---
6+
7+
Sentry supports [.NET for Android](https://learn.microsoft.com/dotnet/android/getting-started/installation/) directly from the [Sentry NuGet package](https://www.nuget.org/packages/Sentry).
8+
9+
## Overview of the features
10+
11+
- All the features of our main [.NET SDK](/platforms/dotnet), for your managed code
12+
- Attach LogCat logs to events
13+
- Java crash reporting for Android, leveraging our [Android SDK](/platforms/android) including:
14+
- [Capture Application Not Responding (ANR) errors](/platforms/android/configuration/app-not-respond/) when the app is unresponsive
15+
- Automatically [attach screenshots to Java exceptions](/platforms/android/enriching-events/screenshots/)
16+
- Automatic breadcrumbs for Activity lifecycle, App lifecycle, System and Network events and User Interactions
17+
- Automatic [Activity lifecycle tracing](/platforms/android/tracing/instrumentation/automatic-instrumentation/#activity-instrumentation) and [User Interaction tracing](/platforms/android/performance/instrumentation/automatic-instrumentation/#user-interaction-instrumentation)
18+
- Device Root checking
19+
- Native crash reporting for Android, leveraging our [Android NDK](/platforms/android/configuration/using-ndk/)
20+
- Automatic session tracking and [release health](/product/releases/)
21+
- _Session Replay for Android_ (currently experimental)
22+
23+
## Install
24+
25+
Add the Sentry dependency to your .NET for Android application:
26+
27+
```shell {tabTitle:.NET Core CLI}
28+
dotnet add package Sentry.Maui -v {{@inject packages.version('sentry.dotnet') }}
29+
```
30+
31+
```powershell {tabTitle:Package Manager}
32+
Install-Package Sentry.Maui -Version {{@inject packages.version('sentry.dotnet') }}
33+
```
34+
35+
## Configure
36+
37+
In your `MainActivity.cs` file, call `SentrySdk.Init` in the `OnCreate` event and include any options you would like to set. The `Dsn` is the only required parameter.
38+
39+
40+
```csharp
41+
[Activity(Label = "@string/app_name", MainLauncher = true)]
42+
public class MainActivity : Activity
43+
{
44+
protected override void OnCreate(Bundle? savedInstanceState)
45+
{
46+
SentrySdk.Init(options =>
47+
{
48+
options.Dsn = "___PUBLIC_DSN___";
49+
options.SendDefaultPii = true; // adds the user's IP address automatically
50+
51+
// Android specific .NET features are under the Android properties:
52+
options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only
53+
options.Android.LogCatMaxLines = 1000; // Defaults to 1000
54+
55+
// All the native Android SDK options are available below
56+
// https://docs.sentry.io/platforms/android/configuration/
57+
// Enable Native Android SDK ANR detection
58+
options.Native.AnrEnabled = true;
59+
60+
// Session Replay is currently available via the ExperimentalOptions
61+
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0;
62+
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0;
63+
options.Native.ExperimentalOptions.SessionReplay.MaskAllImages = false;
64+
options.Native.ExperimentalOptions.SessionReplay.MaskAllText = false;
65+
66+
options.SetBeforeSend(evt =>
67+
{
68+
if (evt.Exception?.Message.Contains("Something you don't care want logged?") ?? false)
69+
{
70+
// return null to filter out an event
71+
return null;
72+
}
73+
// or add additional data
74+
evt.SetTag("dotnet-Android-Native-Before", "Hello World");
75+
return evt;
76+
});
77+
});
78+
79+
// Here's an example of adding custom scope information.
80+
// This can be done at any time, and will be passed through to the Native Android SDK as well.
81+
SentrySdk.ConfigureScope(scope =>
82+
{
83+
scope.AddBreadcrumb("Custom Breadcrumb");
84+
scope.SetExtra("Test", "Custom Extra Data");
85+
scope.User = new SentryUser
86+
{
87+
Username = "SomeUser",
88+
Email = "[email protected]",
89+
Other =
90+
{
91+
["CustomInfo"] = "Custom User Info"
92+
}
93+
};
94+
});
95+
96+
base.OnCreate(savedInstanceState);
97+
}
98+
}
99+
```
100+
101+
### Options
102+
103+
The .NET for Android integration is part of [Sentry](/platforms/dotnet/). Please refer to the documentation for that package for information about platform agnostic options.
104+
105+
Android specific options are described below.
106+
107+
### LogCatIntegration
108+
109+
Can be set to control whether when LogCat logs are attached to events. It can be set to one of the following values:
110+
111+
- `None`: The LogCat integration is disabled.
112+
- `Unhandled`: LogCat logs are attached to events only when the event is unhandled.
113+
- `Errors`: LogCat logs are attached to events with an exception.
114+
- `All`: LogCat logs are attached to all events.
115+
116+
The default is `LogCatIntegrationType.None`
117+
118+
<Alert level="warning">
119+
120+
Use caution when enabling `LogCatIntegrationType.All`, as this may result in a lot of data being sent to Sentry and performance issues if the SDK generates a lot of events.
121+
122+
</Alert>
123+
124+
### LogCatMaxLines
125+
126+
The maximum number of lines to read from LogCat logs.
127+
128+
The default value is 1000.
129+
130+
## Verify
131+
132+
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
133+
134+
<PlatformContent includePath="getting-started-verify" />
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: .NET for iOS, macOS, and Mac Catalyst
3+
sdk: sentry.dotnet.apple
4+
description: "Learn about Sentry's .NET integration with .NET for iOS, macOS, and Mac Catalyst"
5+
---
6+
7+
Sentry supports [.NET for iOS, macOS, and Mac Catalyst](https://learn.microsoft.com/dotnet/ios/) directly from the [Sentry NuGet package](https://www.nuget.org/packages/Sentry).
8+
9+
## Overview of the features
10+
11+
- All the features of our main [.NET SDK](/platforms/dotnet), for your managed code
12+
- Native crash reporting for Apple platforms, leveraging our [Cocoa SDK](/platforms/apple) including:
13+
- Automatically [attach screenshots to Native exceptions](/platforms/apple/guides/ios/configuration/options/#attach-screenshot)
14+
- Detect [App Hangs](/platforms/apple/configuration/app-hangs/)
15+
- [Automatic performance tracing](/platforms/apple/performance/)
16+
- [Automatic breadcrumbs](/platforms/apple/enriching-events/breadcrumbs/#automatic-breadcrumbs)
17+
- [Swizzling](/platforms/apple/configuration/swizzling/)
18+
- Automatic session tracking and [release health](/product/releases/)
19+
20+
## Install
21+
22+
Add the Sentry dependency to your .NET for iOS, macOS, and/or Mac Catalyst application:
23+
24+
```shell {tabTitle:.NET Core CLI}
25+
dotnet add package Sentry.Maui -v {{@inject packages.version('sentry.dotnet') }}
26+
```
27+
28+
```powershell {tabTitle:Package Manager}
29+
Install-Package Sentry.Maui -Version {{@inject packages.version('sentry.dotnet') }}
30+
```
31+
32+
## Configure
33+
34+
In your `AppDelegate.cs` file, call `SentrySdk.Init` in the `FinishedLaunching` event and include any options you would like to set. The `Dsn` is the only required parameter.
35+
36+
37+
```csharp
38+
[Register("AppDelegate")]
39+
public class AppDelegate : UIApplicationDelegate
40+
{
41+
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
42+
{
43+
// Init the Sentry SDK
44+
SentrySdk.Init(options =>
45+
{
46+
options.Dsn = "___PUBLIC_DSN___";
47+
options.Debug = true;
48+
49+
// All the native iOS SDK options are available below
50+
// https://docs.sentry.io/platforms/apple/guides/ios/configuration/
51+
// Enable Native iOS SDK App Hangs detection
52+
options.Native.EnableAppHangTracking = true;
53+
54+
options.SetBeforeSend(evt =>
55+
{
56+
if (evt.Exception?.Message.Contains("Something you don't care want logged?") ?? false)
57+
{
58+
return null; // return null to filter out event
59+
}
60+
// or add additional data
61+
evt.SetTag("dotnet-iOS-Native-Before", "Hello World");
62+
return evt;
63+
});
64+
65+
options.OnCrashedLastRun = e =>
66+
{
67+
Console.WriteLine(e);
68+
};
69+
});
70+
}
71+
}
72+
```
73+
74+
### Options
75+
76+
The .NET for iOS, macOS, and Mac Catalyst integration is part of [Sentry](/platforms/dotnet/). Please refer to the documentation for that package for information about platform agnostic options.
77+
78+
## Verify
79+
80+
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
81+
82+
<PlatformContent includePath="getting-started-verify" />

0 commit comments

Comments
 (0)