Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- The SDK now correctly synchronizes the `Environment` set on the `Scope` events coming from the native layer ([#2764](https://github.com/getsentry/sentry-unity/pull/2764))

### Dependencies

- Bump .NET SDK from v6.5.0-33-g0140be0a to v6.7.0 ([#2761](https://github.com/getsentry/sentry-unity/pull/2761), [#2762](https://github.com/getsentry/sentry-unity/pull/2762))
Expand Down
5 changes: 5 additions & 0 deletions package-dev/Plugins/Switch/sentry_native_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ void sentry_set_trace(const char* trace_id, const char* parent_span_id)
(void)parent_span_id;
}

void sentry_set_environment(const char* environment)
{
(void)environment;
}

/*
* =============================================================================
* Crash Detection Functions
Expand Down
9 changes: 9 additions & 0 deletions package-dev/Plugins/iOS/SentryNativeBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ void SentryNativeBridgeSetTag(const char *key, const char *value)
}];
}

void SentryNativeBridgeSetEnvironment(const char *environment)
{
NSString *environmentString = _NSStringOrNil(environment);

[SentrySDK configureScope:^(SentryScope *scope) {
[scope setEnvironment:environmentString];
}];
}

void SentryNativeBridgeUnsetTag(const char *key)
{
if (key == NULL) {
Expand Down
2 changes: 2 additions & 0 deletions package-dev/Plugins/iOS/SentryNativeBridgeNoOp.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void SentryNativeBridgeUnsetUser() { }

void SentryNativeBridgeSetTrace(const char *traceId, const char *spanId) { }

void SentryNativeBridgeSetEnvironment(const char *environment) { }

void SentryNativeBridgeWriteScope( // clang-format off
// // const char *AppStartTime,
// const char *AppBuildType,
Expand Down
9 changes: 9 additions & 0 deletions package-dev/Plugins/macOS/SentryNativeBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ void SentryNativeBridgeSetTag(const char *key, const char *value)
});
}

void SentryNativeBridgeSetEnvironment(const char *environment)
{
NSString *environmentString = _NSStringOrNil(environment);

SentryConfigureScope(^(id scope) {
[scope performSelector:@selector(setEnvironment:) withObject:environmentString];
});
}

void SentryNativeBridgeUnsetTag(const char *key)
{
if (key == NULL) {
Expand Down
3 changes: 3 additions & 0 deletions src/Sentry.Unity.Android/AndroidJavaScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public override void UnsetUserImpl() =>
public override void SetTraceImpl(SentryId traceId, SpanId spanId) =>
_sentryJava.SetTrace(traceId, spanId);

public override void SetEnvironmentImpl(string? environment) =>
_sentryJava.SetEnvironment(environment);

public override void AddFileAttachmentImpl(string filePath, string fileName, string? contentType) =>
_sentryJava.AddAttachment(filePath, fileName, contentType);

Expand Down
14 changes: 14 additions & 0 deletions src/Sentry.Unity.Android/SentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void WriteScope(
public void SetUser(SentryUser user);
public void UnsetUser();
public void SetTrace(SentryId traceId, SpanId spanId);
public void SetEnvironment(string? environment);
void AddAttachment(string path, string fileName, string? contentType);
void AddAttachmentBytes(byte[] data, string fileName, string? contentType);
void ClearAttachments();
Expand Down Expand Up @@ -387,6 +388,19 @@ public void SetTrace(SentryId traceId, SpanId spanId)
});
}

public void SetEnvironment(string? environment)
{
// TODO: sentry-java lacks this API
// RunJniSafe(() =>
// {
// using var sentry = GetSentryJava();
// sentry.CallStatic("configureScope", new ScopeCallback(scope =>
// {
// scope.Call("setEnvironment", environment);
// }));
// });
}

public void AddAttachment(string path, string fileName, string? contentType)
{
RunJniSafe(() =>
Expand Down
3 changes: 3 additions & 0 deletions src/Sentry.Unity.Native/CFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ internal static void SetValueIfNotNull(sentry_value_t obj, string key, long? val
[DllImport(SentryLib)]
internal static extern void sentry_set_trace(string traceId, string parentSpanId);

[DllImport(SentryLib)]
internal static extern void sentry_set_environment(string? environment);

[DllImport(SentryLib)]
internal static extern IntPtr sentry_attach_file(string path);

Expand Down
3 changes: 3 additions & 0 deletions src/Sentry.Unity.Native/NativeScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public override void SetUserImpl(SentryUser user)
public override void SetTraceImpl(SentryId traceId, SpanId spanId) =>
C.sentry_set_trace(traceId.ToString(), spanId.ToString());

public override void SetEnvironmentImpl(string? environment) =>
C.sentry_set_environment(environment);
Comment thread
cursor[bot] marked this conversation as resolved.

public override void AddFileAttachmentImpl(string filePath, string fileName, string? contentType) =>
C.sentry_attach_file(filePath);

Expand Down
3 changes: 3 additions & 0 deletions src/Sentry.Unity.iOS/NativeScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public override void SetUserImpl(SentryUser user) =>
public override void SetTraceImpl(SentryId traceId, SpanId spanId) =>
SentryCocoaBridgeProxy.SetTrace(traceId.ToString(), spanId.ToString());

public override void SetEnvironmentImpl(string? environment) =>
SentryCocoaBridgeProxy.SetEnvironment(environment);

public override void AddFileAttachmentImpl(string filePath, string fileName, string? contentType)
{
// iOS/macOS attachment sync to sentry-cocoa is not yet supported.
Expand Down
3 changes: 3 additions & 0 deletions src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,7 @@ public static extern void AddBreadcrumb(string timestamp, string? message, strin

[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetTrace")]
public static extern void SetTrace(string traceId, string spanId);

[DllImport("__Internal", EntryPoint = "SentryNativeBridgeSetEnvironment")]
public static extern void SetEnvironment(string? environment);
}
8 changes: 8 additions & 0 deletions src/Sentry.Unity/ScopeObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public void SetTrace(SentryId traceId, SpanId spanId)

public abstract void SetTraceImpl(SentryId traceId, SpanId spanId);

public void SetEnvironment(string? environment)
{
_options.LogDebug("{0} Scope Sync - Setting Environment e:\"{1}\"", _name, environment);
SetEnvironmentImpl(environment);
}

public abstract void SetEnvironmentImpl(string? environment);

public void AddAttachment(SentryAttachment attachment)
{
if (attachment.Content is FileAttachmentContent fileContent)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry-dotnet
Submodule sentry-dotnet updated 79 files
+0 −10 .editorconfig
+12 −5 .generated.NoMobile.slnx
+1 −0 .gitattributes
+45 −0 .githooks/pre-commit
+1 −1 .github/CODEOWNERS
+0 −5 .github/actions/environment/action.yml
+0 −36 .github/actions/install-zstd/action.yml
+0 −5 .github/workflows/build.yml
+25 −0 CONTRIBUTING.md
+1 −0 README.md
+12 −5 Sentry.slnx
+19 −0 dev.cs
+1 −1 samples/Sentry.Samples.Log4Net/Program.cs
+1 −1 samples/Sentry.Samples.Log4Net/Sentry.Samples.Log4Net.csproj
+2 −1 samples/Sentry.Samples.NLog/NLog.config
+1 −0 samples/Sentry.Samples.NLog/Program.cs
+17 −7 src/Sentry.AspNetCore/SentryMiddleware.cs
+4 −0 src/Sentry.AspNetCore/SentryWebHostBuilderExtensions.cs
+1 −1 src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj
+16 −0 src/Sentry.Log4Net/LevelMapping.cs
+6 −0 src/Sentry.Log4Net/Sentry.Log4Net.csproj
+57 −0 src/Sentry.Log4Net/SentryAppender.Structured.cs
+45 −8 src/Sentry.Log4Net/SentryAppender.cs
+1 −10 src/Sentry.Maui/Internal/ScreenshotAttachment.cs
+15 −0 src/Sentry.NLog/LogLevelExtensions.cs
+6 −0 src/Sentry.NLog/Sentry.NLog.csproj
+91 −0 src/Sentry.NLog/SentryTarget.Structured.cs
+125 −84 src/Sentry.NLog/SentryTarget.cs
+12 −0 src/Sentry.Serilog/SentrySerilogOptions.cs
+23 −7 src/Sentry.Serilog/SentrySinkExtensions.cs
+1 −2 src/Sentry/Ben.BlockingDetector/TaskBlockingListener.cs
+75 −0 src/Sentry/HubExtensions.cs
+5 −0 src/Sentry/IScopeObserver.cs
+87 −0 src/Sentry/ISpanRecorder.cs
+9 −0 src/Sentry/Internal/ScopeObserver.cs
+114 −0 src/Sentry/Internal/SpanRecorder.cs
+12 −0 src/Sentry/Platforms/Android/AndroidScopeObserver.cs
+12 −0 src/Sentry/Platforms/Cocoa/CocoaScopeObserver.cs
+3 −0 src/Sentry/Platforms/Native/CFunctions.cs
+3 −0 src/Sentry/Platforms/Native/NativeScopeObserver.cs
+19 −2 src/Sentry/Protocol/Envelopes/Envelope.cs
+26 −1 src/Sentry/Scope.cs
+20 −0 src/Sentry/SentryAttachment.cs
+4 −1 src/Sentry/SentryClient.cs
+15 −1 src/Sentry/SentryLog.cs
+20 −0 src/Sentry/SentrySdk.cs
+12 −3 src/Sentry/ViewHierarchyAttachment.cs
+14 −0 test/.editorconfig
+0 −1 test/CommonModuleInit.cs
+2 −1 test/Sentry.AspNetCore.Tests/MiddlewareLoggerIntegration.cs
+36 −1 test/Sentry.AspNetCore.Tests/SentryMiddlewareTests.cs
+6 −0 test/Sentry.Log4Net.Tests/Sentry.Log4Net.Tests.csproj
+291 −0 test/Sentry.Log4Net.Tests/SentryAppenderTests.Structured.cs
+11 −1 test/Sentry.Log4Net.Tests/SentryAppenderTests.cs
+1 −0 test/Sentry.NLog.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
+1 −0 test/Sentry.NLog.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+1 −0 test/Sentry.NLog.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
+1 −0 test/Sentry.NLog.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+6 −0 test/Sentry.NLog.Tests/Sentry.NLog.Tests.csproj
+210 −0 test/Sentry.NLog.Tests/SentryTargetTests.Structured.cs
+26 −1 test/Sentry.NLog.Tests/SentryTargetTests.cs
+6 −2 test/Sentry.Serilog.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
+6 −2 test/Sentry.Serilog.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+6 −2 test/Sentry.Serilog.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
+6 −2 test/Sentry.Serilog.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+1 −0 test/Sentry.Serilog.Tests/Sentry.Serilog.Tests.csproj
+50 −1 test/Sentry.Serilog.Tests/SentrySerilogSinkExtensionsTests.cs
+2 −0 test/Sentry.Testing/Sentry.Testing.csproj
+23 −1 test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
+23 −1 test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+23 −1 test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
+23 −1 test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+3 −2 test/Sentry.Tests/AttachmentHelper.cs
+22 −0 test/Sentry.Tests/AttachmentTests.cs
+152 −0 test/Sentry.Tests/HubExtensionsRecordTests.cs
+0 −1 test/Sentry.Tests/ModuleInit.cs
+28 −0 test/Sentry.Tests/Protocol/Envelopes/EnvelopeTests.cs
+93 −0 test/Sentry.Tests/ScopeTests.cs
+69 −0 test/Sentry.Tests/SentryClientTests.cs
2 changes: 2 additions & 0 deletions test/Sentry.Unity.Android.Tests/TestSentryJava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void UnsetUser() { }

public void SetTrace(SentryId traceId, SpanId spanId) { }

public void SetEnvironment(string? environment) { }

public void AddAttachment(string path, string fileName, string? contentType) { }

public void AddAttachmentBytes(byte[] data, string fileName, string? contentType) { }
Expand Down
52 changes: 52 additions & 0 deletions test/Sentry.Unity.Tests/UnityEventScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,56 @@ public void UserId_ScopeSync_TriggeredEvenWhenUserAlreadySet()
Assert.AreEqual("native-id", observer.LastUser!.Id);
}

[Test]
public void Environment_ScopeSync_ForwardedToObserver()
{
// arrange - enable scope sync with a tracking observer
var options = new SentryUnityOptions(application: _testApplication);
var observer = new TestScopeObserver(options);
options.ScopeObserver = observer;
options.EnableScopeSync = true;

var scope = new Scope(options);

// act
scope.Environment = "the-environment";

// assert
Assert.AreEqual("the-environment", observer.LastEnvironment);
}

[Test]
public void Environment_ScopeSyncDisabled_NotForwardedToObserver()
{
// arrange
var options = new SentryUnityOptions(application: _testApplication);
var observer = new TestScopeObserver(options);
options.ScopeObserver = observer;
options.EnableScopeSync = false;

var scope = new Scope(options);

// act
scope.Environment = "the-environment";

// assert
Assert.IsNull(observer.LastEnvironment);
}

[Test]
public void SetEnvironment_DelegatesToImpl()
{
// arrange
var options = new SentryUnityOptions(application: _testApplication);
var observer = new TestScopeObserver(options);

// act
observer.SetEnvironment("the-environment");

// assert
Assert.AreEqual("the-environment", observer.LastEnvironment);
}

[Test]
public void OperatingSystemProtocol_Assigned()
{
Expand Down Expand Up @@ -668,6 +718,7 @@ internal sealed class TestSentrySystemInfo : ISentrySystemInfo
internal sealed class TestScopeObserver : ScopeObserver
{
public SentryUser? LastUser { get; set; }
public string? LastEnvironment { get; set; }

public TestScopeObserver(SentryOptions options) : base("Test", options) { }

Expand All @@ -678,6 +729,7 @@ public override void UnsetTagImpl(string key) { }
public override void SetUserImpl(SentryUser user) => LastUser = user;
public override void UnsetUserImpl() => LastUser = null;
public override void SetTraceImpl(SentryId traceId, SpanId spanId) { }
public override void SetEnvironmentImpl(string? environment) => LastEnvironment = environment;
public override void AddFileAttachmentImpl(string filePath, string fileName, string? contentType) { }
public override void AddByteAttachmentImpl(byte[] data, string fileName, string? contentType) { }
public override void ClearAttachmentsImpl() { }
Expand Down
Loading