Skip to content

feat: iOS native bridge for scope sync #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6d55e76
initial poc: tags, user, breadcrumbs
bitsandfoxes Aug 26, 2021
cff04ee
modified test breadcrumb for null test
bitsandfoxes Aug 27, 2021
814764f
bridge now deals with nullptr
bitsandfoxes Aug 27, 2021
5758e10
bridge now handles nullptr and accepts everything the observer has
bitsandfoxes Aug 27, 2021
cb2850e
added more debug to init
bitsandfoxes Aug 27, 2021
c114476
removing extra key
bitsandfoxes Aug 27, 2021
80ce513
Merge branch 'main' into feat/ios-native-bridge
bitsandfoxes Sep 14, 2021
b26acec
replaced NSLog with SentryLog
bitsandfoxes Sep 15, 2021
4095e24
expression bodies are love
bitsandfoxes Sep 15, 2021
5c964d2
removed trailing dots
bitsandfoxes Sep 15, 2021
51a2711
moved bridge to package/plugins/ios
bitsandfoxes Sep 15, 2021
dc25349
moved bridge to package/plugins/ios
bitsandfoxes Sep 15, 2021
e0e43b3
tweaked bridge debug output
bitsandfoxes Sep 15, 2021
46313ed
fixed precompile constant to exclude running in editor
bitsandfoxes Sep 15, 2021
dbcd7fa
moved native scope observer into own proj
bitsandfoxes Sep 15, 2021
c696307
added tests, bridge cleanup, observer tweaks
bitsandfoxes Sep 16, 2021
c93001c
typo in CI
bitsandfoxes Sep 16, 2021
785b43f
removed init debug code
bitsandfoxes Sep 16, 2021
a5613aa
renamed ios native support options flag
bitsandfoxes Sep 16, 2021
dbbe3de
updated CHANGELOG.md
bitsandfoxes Sep 16, 2021
9b72c2b
updated ios native flag name in test
bitsandfoxes Sep 16, 2021
22f16af
Merge branch 'main' into feat/ios-native-bridge
bruno-garcia Sep 17, 2021
32657e8
Merge branch 'main' into feat/ios-native-bridge
bruno-garcia Sep 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
with:
submodules: recursive

# Unity is about 4gb in size and takes 20 minutes to download and install.
# Unity is about 4GB in size and takes 20 minutes to download and install.
# Caching still takes some time, but brings it down to about 5 minutes.
- name: Restore cached Unity installation
id: cache-unity
Expand Down
24 changes: 14 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@ samples/unity-of-bugs/Assets/InitTestScene*
package-dev/**/*.dll
package-dev/**/*.meta
package-dev/**/*.framework
# Android SDK files
package-dev/Plugins/Android/Sentry/*
# required to be makred as iOS only
!package-dev/**/*.framework.meta
package-dev/**/*.pdb
package-dev/**/*.xml
package-dev/**/TestSentryOptions.json
package-dev/Tests/Editor/TestFiles/

!package-dev/Runtime/Sentry.Unity.dll.meta
!package-dev/Runtime/Sentry.Unity.iOS.dll.meta
!package-dev/Tests/*.meta

# required to be marked as iOS only
!package-dev/**/*.framework.meta

# Android SDK files
package-dev/Plugins/Android/Sentry/*

# required to be marked as Editor only
!package-dev/Tests/Runtime/Sentry.Unity.Tests.dll.meta
!package-dev/Tests/**/*.asmdef
!package-dev/Tests/**/*.asmdef.meta
package-dev/Tests/Editor/TestFiles/
package-dev/**/*.pdb
package-dev/**/*.xml
package-dev/**/TestSentryOptions.json
!package-dev/Tests/Runtime/Sentry.Unity.iOS.Tests.dll.meta

# Build output of Sentry.Unity
sentry-unity/Assets/Plugins/Sentry/
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## Unreleased

### Feature
### Features

- Android Native Support ([#307](https://github.com/getsentry/sentry-unity/pull/307))
- iOS native bridge for scope sync ([#296](https://github.com/getsentry/sentry-unity/pull/296))

### Fixes

Expand Down
30 changes: 30 additions & 0 deletions Sentry.Unity.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.Editor.iOS", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.Editor.iOS.Tests", "test\Sentry.Unity.Editor.iOS.Tests\Sentry.Unity.Editor.iOS.Tests.csproj", "{A43C866F-FA99-4B01-B480-6A7901569FAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.iOS", "src\Sentry.Unity.iOS\Sentry.Unity.iOS.csproj", "{9E01A414-DD86-49BD-B10F-6DEF42BE9474}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Unity.iOS.Tests", "test\Sentry.Unity.iOS.Tests\Sentry.Unity.iOS.Tests.csproj", "{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -129,6 +133,30 @@ Global
{A43C866F-FA99-4B01-B480-6A7901569FAB}.Release|x64.Build.0 = Release|Any CPU
{A43C866F-FA99-4B01-B480-6A7901569FAB}.Release|x86.ActiveCfg = Release|Any CPU
{A43C866F-FA99-4B01-B480-6A7901569FAB}.Release|x86.Build.0 = Release|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Debug|x64.ActiveCfg = Debug|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Debug|x64.Build.0 = Debug|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Debug|x86.ActiveCfg = Debug|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Debug|x86.Build.0 = Debug|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Release|Any CPU.Build.0 = Release|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Release|x64.ActiveCfg = Release|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Release|x64.Build.0 = Release|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Release|x86.ActiveCfg = Release|Any CPU
{9E01A414-DD86-49BD-B10F-6DEF42BE9474}.Release|x86.Build.0 = Release|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Debug|x64.ActiveCfg = Debug|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Debug|x64.Build.0 = Debug|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Debug|x86.ActiveCfg = Debug|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Debug|x86.Build.0 = Debug|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Release|Any CPU.Build.0 = Release|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Release|x64.ActiveCfg = Release|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Release|x64.Build.0 = Release|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Release|x86.ActiveCfg = Release|Any CPU
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -144,5 +172,7 @@ Global
{583BBF7E-054D-414D-AAA8-47C400AB3914} = {36979A3D-4741-4D8A-82BF-4010474388E1}
{703A3ECC-048C-443A-B624-0D17DFC674AA} = {36979A3D-4741-4D8A-82BF-4010474388E1}
{A43C866F-FA99-4B01-B480-6A7901569FAB} = {6A85CE0A-6FE4-4190-ABEE-7E8BCFF9AF4D}
{9E01A414-DD86-49BD-B10F-6DEF42BE9474} = {36979A3D-4741-4D8A-82BF-4010474388E1}
{BE8D1F39-B2FA-48D3-8884-96CA02C5B13F} = {6A85CE0A-6FE4-4190-ABEE-7E8BCFF9AF4D}
EndGlobalSection
EndGlobal
109 changes: 109 additions & 0 deletions package-dev/Plugins/iOS/SentryNativeBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#import <Sentry/Sentry.h>

NS_ASSUME_NONNULL_BEGIN

void SentryNativeBridgeAddBreadcrumb(const char* timestamp, const char* message, const char* type, const char* category, int level) {
if (timestamp == NULL && message == NULL && type == NULL && category == NULL) {
return;
}

[SentrySDK configureScope:^(SentryScope * scope) {
SentryBreadcrumb *breadcrumb = [[SentryBreadcrumb alloc] init];

if (timestamp != NULL) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:NSCalendarIdentifierISO8601];
breadcrumb.timestamp = [dateFormatter dateFromString:[NSString stringWithCString:timestamp encoding:NSUTF8StringEncoding]];
}

if (message != NULL) {
breadcrumb.message = [NSString stringWithCString:message encoding:NSUTF8StringEncoding];
}

if (type != NULL) {
breadcrumb.type = [NSString stringWithCString:type encoding:NSUTF8StringEncoding];
}

if (category != NULL) {
breadcrumb.category = [NSString stringWithCString:category encoding:NSUTF8StringEncoding];
}

breadcrumb.level = level;

[scope addBreadcrumb:breadcrumb];
}];
}

void SentryNativeBridgeSetExtra(const char* key, const char* value) {
if (key == NULL) {
return;
}

[SentrySDK configureScope:^(SentryScope * scope) {
if (value != NULL) {
[scope setExtraValue:[NSString stringWithUTF8String:value] forKey:[NSString stringWithUTF8String:key]];
} else {
[scope removeExtraForKey:[NSString stringWithUTF8String:key]];
}
}];
}

void SentryNativeBridgeSetTag(const char* key, const char* value) {
if (key == NULL) {
return;
}

[SentrySDK configureScope:^(SentryScope * scope) {
if (value != NULL) {
[scope setTagValue:[NSString stringWithUTF8String:value] forKey:[NSString stringWithUTF8String:key]];
} else {
[scope removeTagForKey:[NSString stringWithUTF8String:key]];
}
}];
}

void SentryNativeBridgeUnsetTag(const char* key) {
if (key == NULL) {
return;
}

[SentrySDK configureScope:^(SentryScope * scope) {
[scope removeTagForKey:[NSString stringWithUTF8String:key]];
}];
}

void SentryNativeBridgeSetUser(const char* email, const char* userId, const char* ipAddress, const char* username) {
if (email == NULL && userId == NULL && ipAddress == NULL && username == NULL) {
return;
}

[SentrySDK configureScope:^(SentryScope * scope) {
SentryUser *user = [[SentryUser alloc] init];

if (email != NULL) {
user.email = [NSString stringWithCString:email encoding:NSUTF8StringEncoding];
}

if (userId != NULL) {
user.userId = [NSString stringWithCString:userId encoding:NSUTF8StringEncoding];
}

if (ipAddress != NULL) {
user.ipAddress = [NSString stringWithCString:ipAddress encoding:NSUTF8StringEncoding];
}

if (username != NULL) {
user.username = [NSString stringWithCString:username encoding:NSUTF8StringEncoding];
}

[scope setUser:user];
}];
}

void SentryNativeBridgeUnsetUser() {
[SentrySDK configureScope:^(SentryScope * scope) {
[scope setUser:nil];
}];
}

NS_ASSUME_NONNULL_END
86 changes: 86 additions & 0 deletions package-dev/Runtime/Sentry.Unity.iOS.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package-dev/Runtime/SentryInitialization.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using UnityEngine;
using UnityEngine.Scripting;

#if UNITY_IOS && !UNITY_EDITOR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea if this works:

Suggested change
#if UNITY_IOS && !UNITY_EDITOR
#define ENABLE_ISO_BRIDGE = UNITY_IOS && !UNITY_EDITOR
#if ENABLE_ISO_BRIDGE

using Sentry.Unity.iOS;
#endif

[assembly: AlwaysLinkAssembly]

namespace Sentry.Unity
Expand All @@ -13,6 +17,12 @@ public static void Init()
var options = ScriptableSentryUnityOptions.LoadSentryUnityOptions();
if (options.ShouldInitializeSdk())
{

#if UNITY_IOS && !UNITY_EDITOR
options.ScopeObserver = new IosNativeScopeObserver(options);
options.EnableScopeSync = true;
#endif

SentryUnity.Init(options);
}
}
Expand Down
Loading