-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathNativeScopeObserver.cs
More file actions
83 lines (64 loc) · 3.22 KB
/
Copy pathNativeScopeObserver.cs
File metadata and controls
83 lines (64 loc) · 3.22 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
using System;
namespace Sentry.Unity.iOS;
public class NativeScopeObserver : ScopeObserver
{
public NativeScopeObserver(string name, SentryOptions options) : base(name, options) { }
public override void AddBreadcrumbImpl(Breadcrumb breadcrumb)
{
var level = GetBreadcrumbLevel(breadcrumb.Level);
var timestamp = GetTimestamp(breadcrumb.Timestamp);
// Pass breadcrumb.Data as two parallel key/value arrays for the __Internal P/Invoke boundary.
var dataCount = GetBreadcrumbData(breadcrumb, out var dataKeys, out var dataValues);
SentryCocoaBridgeProxy.AddBreadcrumb(timestamp, breadcrumb.Message, breadcrumb.Type, breadcrumb.Category, level,
dataKeys, dataValues, dataCount);
}
internal static int GetBreadcrumbData(Breadcrumb breadcrumb, out string[]? keys, out string[]? values)
{
if (breadcrumb.Data is not { Count: > 0 } data)
{
keys = null;
values = null;
return 0;
}
keys = new string[data.Count];
values = new string[data.Count];
var i = 0;
foreach (var kvp in data)
{
keys[i] = kvp.Key;
values[i] = kvp.Value;
i++;
}
return data.Count;
}
public override void SetExtraImpl(string key, string? value) =>
SentryCocoaBridgeProxy.SetExtra(key, value);
public override void SetTagImpl(string key, string value) => SentryCocoaBridgeProxy.SetTag(key, value);
public override void UnsetTagImpl(string key) => SentryCocoaBridgeProxy.UnsetTag(key);
public override void SetUserImpl(SentryUser user) =>
SentryCocoaBridgeProxy.SetUser(user.Email, user.Id, user.IpAddress, user.Username);
public override void UnsetUserImpl() => SentryCocoaBridgeProxy.UnsetUser();
public override void SetTraceImpl(SentryId traceId, SpanId spanId) =>
SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString());
public override void AddFileAttachmentImpl(string filePath, string fileName, string? contentType) =>
SentryCocoaBridgeProxy.AddFileAttachment(filePath, fileName, contentType);
public override void AddByteAttachmentImpl(byte[] data, string fileName, string? contentType) =>
SentryCocoaBridgeProxy.AddByteAttachment(data, data.Length, fileName, contentType);
public override void ClearAttachmentsImpl() =>
SentryCocoaBridgeProxy.ClearAttachments();
internal static string GetTimestamp(DateTimeOffset timestamp) =>
// "o": Using ISO 8601 to make sure the timestamp makes it to the bridge correctly.
// https://docs.microsoft.com/en-gb/dotnet/standard/base-types/standard-date-and-time-format-strings#Roundtrip
timestamp.ToString("o");
internal static int GetBreadcrumbLevel(BreadcrumbLevel breadcrumbLevel) =>
// https://github.com/getsentry/sentry-cocoa/blob/50f955aeb214601dd62b5dae7abdaddc8a1f24d9/Sources/Sentry/Public/SentryDefines.h#L99-L105
breadcrumbLevel switch
{
BreadcrumbLevel.Debug => 1,
BreadcrumbLevel.Info => 2,
BreadcrumbLevel.Warning => 3,
BreadcrumbLevel.Error => 4,
BreadcrumbLevel.Fatal => 5,
_ => 0
};
}