-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathSentryCocoaBridgeProxy.cs
More file actions
153 lines (111 loc) · 6.81 KB
/
Copy pathSentryCocoaBridgeProxy.cs
File metadata and controls
153 lines (111 loc) · 6.81 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Runtime.InteropServices;
using Sentry.Extensibility;
namespace Sentry.Unity.iOS;
/// <summary>
/// P/Invoke to SentryNativeBridge.m which communicates with the `sentry-cocoa` SDK.
/// </summary>
/// <remarks>
/// Functions are declared in `SentryNativeBridge.m`
/// </remarks>
/// <see href="https://github.com/getsentry/sentry-cocoa"/>
internal static class SentryCocoaBridgeProxy
{
private static IDiagnosticLogger? Logger;
public static bool IsEnabled() => SentryNativeBridgeIsEnabled() == 1;
public static bool Init(SentryUnityOptions options)
{
if (LoadLibrary() != 1)
{
return false;
}
Logger = options.DiagnosticLogger;
var cOptions = OptionsNew();
// Note: DSN is not null because options.IsValid() must have returned true for this to be called.
OptionsSetString(cOptions, "dsn", options.Dsn!);
if (options.Release is not null)
{
Logger?.LogDebug("Setting Release: {0}", options.Release);
OptionsSetString(cOptions, "release", options.Release);
}
if (options.Environment is not null)
{
Logger?.LogDebug("Setting Environment: {0}", options.Environment);
OptionsSetString(cOptions, "environment", options.Environment);
}
Logger?.LogDebug("Setting Debug: {0}", options.Debug);
OptionsSetInt(cOptions, "debug", options.Debug ? 1 : 0);
var diagnosticLevel = options.DiagnosticLevel.ToString().ToLowerInvariant();
Logger?.LogDebug("Setting DiagnosticLevel: {0}", diagnosticLevel);
OptionsSetString(cOptions, "diagnosticLevel", diagnosticLevel);
Logger?.LogDebug("Setting SendDefaultPii: {0}", options.SendDefaultPii);
OptionsSetInt(cOptions, "sendDefaultPii", options.SendDefaultPii ? 1 : 0);
// macOS screenshots currently don't work, because there's no UIKit. Cocoa logs: "Sentry - info:: NO UIKit"
// Logger?.LogDebug("Setting AttachScreenshot: {0}", options.AttachScreenshot);
// OptionsSetInt(cOptions, "attachScreenshot", options.AttachScreenshot ? 1 : 0);
OptionsSetInt(cOptions, "attachScreenshot", 0);
Logger?.LogDebug("Setting MaxBreadcrumbs: {0}", options.MaxBreadcrumbs);
OptionsSetInt(cOptions, "maxBreadcrumbs", options.MaxBreadcrumbs);
Logger?.LogDebug("Setting MaxCacheItems: {0}", options.MaxCacheItems);
OptionsSetInt(cOptions, "maxCacheItems", options.MaxCacheItems);
// See https://github.com/getsentry/sentry-unity/issues/1658
OptionsSetInt(cOptions, "enableNetworkBreadcrumbs", 0);
Logger?.LogDebug("Setting EnableAppHangTracking: {0}", options.EnableAppHangTracking);
OptionsSetInt(cOptions, "enableAppHangTracking", options.EnableAppHangTracking ? 1 : 0);
Logger?.LogDebug("Setting AppHangTimeoutInterval: {0}s", options.AppHangTimeout.TotalSeconds);
OptionsSetDouble(cOptions, "appHangTimeoutInterval", options.AppHangTimeout.TotalSeconds);
Logger?.LogDebug("Setting EnableWatchdogTerminationTracking: {0}", options.IosWatchdogTerminationIntegrationEnabled);
OptionsSetInt(cOptions, "enableWatchdogTerminationTracking", options.IosWatchdogTerminationIntegrationEnabled ? 1 : 0);
Logger?.LogDebug("Setting CaptureFailedRequests: {0}", options.CaptureFailedRequests);
OptionsSetInt(cOptions, "enableCaptureFailedRequests", options.CaptureFailedRequests ? 1 : 0);
Logger?.LogDebug("Setting EnableLogs: {0}", options.EnableLogs);
OptionsSetInt(cOptions, "enableLogs", options.EnableLogs ? 1 : 0);
Logger?.LogDebug("Setting EnableMetrics: {0}", options.EnableMetrics);
OptionsSetInt(cOptions, "enableMetrics", options.EnableMetrics ? 1 : 0);
foreach (var range in options.FailedRequestStatusCodes)
{
Logger?.LogDebug("Adding FailedRequestStatusCodeRange: {0}-{1}", range.Start, range.End);
OptionsAddFailedRequestStatusCodeRange(cOptions, range.Start, range.End);
}
var result = StartWithOptions(cOptions);
return result is 1;
}
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeLoadLibrary")]
private static extern int LoadLibrary();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeIsEnabled")]
private static extern int SentryNativeBridgeIsEnabled();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsNew")]
private static extern IntPtr OptionsNew();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsSetString")]
private static extern void OptionsSetString(IntPtr options, string name, string value);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsSetInt")]
private static extern void OptionsSetInt(IntPtr options, string name, int value);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsSetDouble")]
private static extern void OptionsSetDouble(IntPtr options, string name, double value);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeOptionsAddFailedRequestStatusCodeRange")]
private static extern void OptionsAddFailedRequestStatusCodeRange(IntPtr options, int min, int max);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeStartWithOptions")]
private static extern int StartWithOptions(IntPtr options);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetSdkName")]
public static extern int SetSdkName();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeCrashedLastRun")]
public static extern int CrashedLastRun();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeClose")]
public static extern void Close();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeAddBreadcrumb")]
public static extern void AddBreadcrumb(string timestamp, string? message, string? type, string? category, int level);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetExtra")]
public static extern void SetExtra(string key, string? value);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetTag")]
public static extern void SetTag(string key, string value);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeUnsetTag")]
public static extern void UnsetTag(string key);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetUser")]
public static extern void SetUser(string? email, string? userId, string? ipAddress, string? username);
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeUnsetUser")]
public static extern void UnsetUser();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeGetInstallationId")]
public static extern string GetInstallationId();
[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetTrace")]
public static extern void SetTrace(string traceId, string spanId);
}