-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathMainActivity.cs
More file actions
109 lines (94 loc) · 4.66 KB
/
MainActivity.cs
File metadata and controls
109 lines (94 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using Sentry.Android;
namespace Sentry.Samples.Android;
[Activity(Label = "@string/app_name", MainLauncher = true)]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
SentrySdk.Init(options =>
{
#if !SENTRY_DSN_DEFINED_IN_ENV
// You must specify a DSN. On mobile platforms, this should be done in code here.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
options.Dsn = SamplesShared.Dsn;
#else
// To make things easier for the SDK maintainers our samples check for a SENTRY_DSN environment variable
// and write this (as a constant) into an EnvironmentVariables class. Generally, you won't want to do
// this in your own mobile projects though - you should set the DSN in code as above
options.Dsn = EnvironmentVariables.Dsn;
#endif
options.SendDefaultPii = true; // adds the user's IP address automatically
// Android specific .NET features are under the Android properties:
options.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only
options.Android.LogCatMaxLines = 1000; // Defaults to 1000
// All the native Android SDK options are available below
// https://docs.sentry.io/platforms/android/configuration/
// Enable Native Android SDK ANR detection
options.Native.AnrEnabled = true;
// If your app doesn't have sensitive data, you can attach screenshots automatically when a Java/native
// error is captured.
// https://docs.sentry.io/platforms/android/configuration/options/#attachScreenshot
options.Native.AttachScreenshot = true;
// Currently experimental support is only available on Android
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.MaskAllImages = false;
options.Native.ExperimentalOptions.SessionReplay.MaskAllText = false;
options.SetBeforeSend(evt =>
{
if (evt.Exception?.Message.Contains("Something you don't care want logged?") ?? false)
{
return null; // return null to filter out event
}
// or add additional data
evt.SetTag("dotnet-Android-Native-Before", "Hello World");
return evt;
});
});
// Here's an example of adding custom scope information.
// This can be done at any time, and will be passed through to the Java SDK as well.
SentrySdk.ConfigureScope(scope =>
{
scope.AddBreadcrumb("Custom Breadcrumb");
scope.SetExtra("Test", "Custom Extra Data");
scope.User = new SentryUser
{
Username = "SomeUser",
Email = "test@example.com",
Other =
{
["CustomInfo"] = "Custom User Info"
}
};
});
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
var captureException = (Button)base.FindViewById(Resource.Id.captureException)!;
captureException.Click += (s, a) =>
{
try
{
throw new Exception("Try, catch");
}
catch (Exception e)
{
SentrySdk.CaptureException(e);
}
};
var throwUnhandledException = (Button)base.FindViewById(Resource.Id.throwUnhandledException)!;
throwUnhandledException.Click += (s, a) => throw new Exception("Unhandled");
var throwJavaException = (Button)base.FindViewById(Resource.Id.throwJavaException)!;
#pragma warning disable CS0618
throwJavaException.Click += (s, a) => SentrySdk.CauseCrash(CrashType.Java);
#pragma warning restore CS0618
var throwJavaExceptionBackgroundThread = (Button)base.FindViewById(Resource.Id.throwJavaExceptionBackgroundThread)!;
#pragma warning disable CS0618
throwJavaExceptionBackgroundThread.Click += (s, a) => SentrySdk.CauseCrash(CrashType.JavaBackgroundThread);
#pragma warning restore CS0618
var crashInC = (Button)base.FindViewById(Resource.Id.crashInC)!;
#pragma warning disable CS0618
crashInC.Click += (s, a) => SentrySdk.CauseCrash(CrashType.Native);
#pragma warning restore CS0618
}
}