-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathNativeOptions.cs
More file actions
98 lines (83 loc) · 3.49 KB
/
NativeOptions.cs
File metadata and controls
98 lines (83 loc) · 3.49 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
using System.Collections.Generic;
using System.IO;
namespace Sentry.Unity.Editor.iOS;
internal static class NativeOptions
{
public static void CreateFile(string path, SentryUnityOptions options) => File.WriteAllText(path, Generate(options));
internal static string Generate(SentryUnityOptions options)
{
var failedRequestStatusCodesArray = GetFailedRequestStatusCodesArray(options.FailedRequestStatusCodes);
var nativeOptions = $@"#import <Foundation/Foundation.h>
#import <Sentry/SentryOptions+HybridSDKs.h>
#import <Sentry/PrivateSentrySDKOnly.h>
// IMPORTANT: Changes to this file will be lost!
// This file is generated during the Xcode project creation.
// To learn more please take a look at our docs at: https://docs.sentry.io/platforms/unity/native-support/
static SentryOptions* getSentryOptions()
{{
[PrivateSentrySDKOnly setSdkName:@""sentry.cocoa.unity""];
NSDictionary* optionsDictionary = @{{
@""dsn"" : @""{options.Dsn}"",
@""debug"" : @{ToObjCString(options.Debug)},
@""diagnosticLevel"" : @""{ToNativeDiagnosticLevel(options.DiagnosticLevel)}"",
@""maxBreadcrumbs"": @{options.MaxBreadcrumbs},
@""maxCacheItems"": @{options.MaxCacheItems},
@""enableAutoSessionTracking"": @NO,
@""enableAppHangTracking"": @NO,
@""enableCaptureFailedRequests"": @{ToObjCString(options.CaptureFailedRequests)},
@""failedRequestStatusCodes"" : @[{failedRequestStatusCodesArray}],
@""sendDefaultPii"" : @{ToObjCString(options.SendDefaultPii)},
@""attachScreenshot"" : @{ToObjCString(options.AttachScreenshot)},
@""release"" : @""{options.Release}"",
@""environment"" : @""{options.Environment}"",
@""enableNetworkBreadcrumbs"" : @NO,
// TODO temp code, implement this properly
@""experimental"" : @{{
@""sessionReplay"" : @{{
@""sessionSampleRate"" : @1.0,
@""errorSampleRate"" : @1.0
}}
}}
}};
NSError *error = nil;
SentryOptions* options = [[SentryOptions alloc] initWithDict:optionsDictionary didFailWithError:&error];
if (error != nil)
{{
NSLog(@""%@"",[error localizedDescription]);
return nil;
}}
{(options.FilterBadGatewayExceptions ? @"options.beforeSend = ^SentryEvent * _Nullable(SentryEvent * _Nonnull event) {
if ([event.request.url containsString:@""operate-sdk-telemetry.unity3d.com""]) return nil;
return event;
};" : "")}
return options;
}}";
return nativeOptions;
}
private static string ToObjCString(bool b) => b ? "YES" : "NO";
private static string ToNativeDiagnosticLevel(SentryLevel sentryLevel)
{
return sentryLevel switch
{
SentryLevel.Debug => "debug",
SentryLevel.Info => "info",
SentryLevel.Warning => "warning",
SentryLevel.Error => "error",
SentryLevel.Fatal => "fatal",
_ => "none"
};
}
private static string GetFailedRequestStatusCodesArray(IList<HttpStatusCodeRange> httpStatusCodeRanges)
{
var codeRanges = string.Empty;
for (var i = 0; i < httpStatusCodeRanges.Count; i++)
{
codeRanges += $"[[SentryHttpStatusCodeRange alloc] initWithMin:{httpStatusCodeRanges[i].Start} max:{httpStatusCodeRanges[i].End}]";
if (i < httpStatusCodeRanges.Count - 1)
{
codeRanges += ", ";
}
}
return codeRanges;
}
}