Skip to content

Commit 2ee89b5

Browse files
authored
chore: Moved StructureLogging out of experimental (#2401)
1 parent bbe59fc commit 2ee89b5

File tree

6 files changed

+51
-87
lines changed

6 files changed

+51
-87
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
- Structured logs now have the `origin` and `sdk` attributes correctly set ([#2390](https://github.com/getsentry/sentry-unity/pull/2390))
99
- Resolved possible startup crashes on Android VR platforms like the Oculus Quest. The SDK no longer natively subscribes to interaction hooks for automatic tracing and breadcrumb creation. ([#2393](https://github.com/getsentry/sentry-unity/pull/2393))
1010

11+
### Features
12+
13+
- Strucutured Logs are not longer `experimental` ([#2401](https://github.com/getsentry/sentry-unity/pull/2401))
14+
1115
### Dependencies
1216

1317
- Bump Native SDK from v0.11.2 to v0.12.1 ([#2357](https://github.com/getsentry/sentry-unity/pull/2357), [#2378](https://github.com/getsentry/sentry-unity/pull/2378), [#2388](https://github.com/getsentry/sentry-unity/pull/2388))

src/Sentry.Unity/Integrations/UnityApplicationLoggingIntegration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private void ProcessBreadcrumbs(string message, LogType logType)
124124
}
125125

126126
// Breadcrumb collection on top of structure log capture must be opted in
127-
if (_options.Experimental is { EnableLogs: true, AttachBreadcrumbsToEvents: false })
127+
if (_options is { EnableLogs: true, AttachBreadcrumbsToEvents: false })
128128
{
129129
return;
130130
}
@@ -138,7 +138,7 @@ private void ProcessBreadcrumbs(string message, LogType logType)
138138

139139
private void ProcessStructuredLog(string message, LogType logType)
140140
{
141-
if (!_options.Experimental.EnableLogs || !_options.Experimental.CaptureStructuredLogsForLogType.TryGetValue(logType, out var captureLog) || !captureLog)
141+
if (!_options.EnableLogs || !_options.CaptureStructuredLogsForLogType.TryGetValue(logType, out var captureLog) || !captureLog)
142142
{
143143
return;
144144
}

src/Sentry.Unity/ScriptableSentryUnityOptions.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,16 @@ internal SentryUnityOptions ToSentryUnityOptions(
193193
XboxNativeSupportEnabled = XboxNativeSupportEnabled,
194194
Il2CppLineNumberSupportEnabled = Il2CppLineNumberSupportEnabled,
195195
PerformanceAutoInstrumentationEnabled = AutoAwakeTraces,
196-
Experimental = new SentryUnityExperimentalOptions
196+
EnableLogs = EnableStructuredLogging,
197+
CaptureStructuredLogsForLogType =
197198
{
198-
EnableLogs = EnableStructuredLogging,
199-
CaptureStructuredLogsForLogType =
200-
{
201-
[LogType.Log] = StructuredLogOnDebugLog,
202-
[LogType.Warning] = StructuredLogOnDebugLogWarning,
203-
[LogType.Assert] = StructuredLogOnDebugLogAssertion,
204-
[LogType.Error] = StructuredLogOnDebugLogError,
205-
[LogType.Exception] = StructuredLogOnDebugLogException
206-
},
207-
AttachBreadcrumbsToEvents = AttachBreadcrumbsToEvents
208-
}
199+
[LogType.Log] = StructuredLogOnDebugLog,
200+
[LogType.Warning] = StructuredLogOnDebugLogWarning,
201+
[LogType.Assert] = StructuredLogOnDebugLogAssertion,
202+
[LogType.Error] = StructuredLogOnDebugLogError,
203+
[LogType.Exception] = StructuredLogOnDebugLogException
204+
},
205+
AttachBreadcrumbsToEvents = AttachBreadcrumbsToEvents
209206
};
210207

211208
// By default, the cacheDirectoryPath gets set on known platforms. We're overwriting this behaviour here.

src/Sentry.Unity/SentryUnityOptions.cs

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ public sealed class SentryUnityOptions : SentryOptions
130130
/// </summary>
131131
public int ScreenshotCompression { get; set; } = 75;
132132

133+
/// <summary>
134+
/// Controls whether structured logs should be captured for each Unity log type.
135+
/// </summary>
136+
public Dictionary<LogType, bool> CaptureStructuredLogsForLogType { get; set; }
137+
138+
/// <summary>
139+
/// When set to true, breadcrumbs will be added on top of structured logging.
140+
/// Defaults to false.
141+
/// </summary>
142+
public bool AttachBreadcrumbsToEvents { get; set; } = false;
143+
133144
/// <summary>
134145
/// Whether the SDK automatically captures events for 'Debug.LogError'.
135146
/// </summary>
@@ -305,13 +316,6 @@ internal string? DefaultUserId
305316
internal ISentryUnityInfo UnityInfo { get; private set; }
306317
internal Action<SentryUnityOptions>? PlatformConfiguration { get; private set; }
307318

308-
// Delegate to base property to ensure both Unity and base SDK reference the same instance
309-
public new SentryUnityExperimentalOptions Experimental
310-
{
311-
get => (SentryUnityExperimentalOptions)base.Experimental;
312-
set => base.Experimental = value;
313-
}
314-
315319
public SentryUnityOptions() : this(isBuilding: false) { }
316320

317321
// For testing
@@ -326,9 +330,6 @@ internal SentryUnityOptions(IApplication? application = null,
326330
UnityInfo = unityInfo ?? SentryPlatformServices.UnityInfo;
327331
PlatformConfiguration = SentryPlatformServices.PlatformConfiguration;
328332

329-
// Initialize base.Experimental with Unity-specific experimental options
330-
base.Experimental = new SentryUnityExperimentalOptions();
331-
332333
application ??= ApplicationAdapter.Instance;
333334
behaviour ??= SentryMonoBehaviour.Instance;
334335

@@ -391,6 +392,15 @@ internal SentryUnityOptions(IApplication? application = null,
391392
? "editor"
392393
: "production";
393394

395+
CaptureStructuredLogsForLogType = new Dictionary<LogType, bool>
396+
{
397+
{ LogType.Log, false },
398+
{ LogType.Warning, true },
399+
{ LogType.Assert, true },
400+
{ LogType.Error, true },
401+
{ LogType.Exception, true }
402+
};
403+
394404
AddBreadcrumbsForLogType = new Dictionary<LogType, bool>
395405
{
396406
{ LogType.Log, true},
@@ -499,50 +509,3 @@ public enum NativeInitializationType
499509
/// </summary>
500510
BuildTime,
501511
}
502-
503-
/// <summary>
504-
/// Unity-specific experimental options.
505-
/// </summary>
506-
/// <remarks>
507-
/// This extends the base <see cref="SentryOptions.SentryExperimentalOptions"/> with Unity-specific experimental features.
508-
/// These options are subject to change in future versions.
509-
/// </remarks>
510-
public sealed class SentryUnityExperimentalOptions : SentryOptions.SentryExperimentalOptions
511-
{
512-
/// <summary>
513-
/// Controls whether structured logs should be captured for each Unity log type.
514-
/// </summary>
515-
public Dictionary<LogType, bool> CaptureStructuredLogsForLogType { get; set; }
516-
517-
/// <summary>
518-
/// When set to true, breadcrumbs will be added on top of structured logging.
519-
/// Defaults to false.
520-
/// </summary>
521-
public bool AttachBreadcrumbsToEvents { get; set; } = false;
522-
523-
/// <summary>
524-
/// Sets a callback function to be invoked before sending the log to Sentry.
525-
/// When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.
526-
/// </summary>
527-
/// <remarks>
528-
/// It can be used to modify the log object before being sent to Sentry.
529-
/// To prevent the log from being sent to Sentry, return <see langword="null"/>.
530-
/// </remarks>
531-
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/logs/"/>
532-
public new void SetBeforeSendLog(Func<SentryLog, SentryLog?> beforeSendLog)
533-
{
534-
base.SetBeforeSendLog(beforeSendLog);
535-
}
536-
537-
internal SentryUnityExperimentalOptions()
538-
{
539-
CaptureStructuredLogsForLogType = new Dictionary<LogType, bool>
540-
{
541-
{ LogType.Log, false },
542-
{ LogType.Warning, true },
543-
{ LogType.Assert, true },
544-
{ LogType.Error, true },
545-
{ LogType.Exception, true }
546-
};
547-
}
548-
}

src/sentry-dotnet

Submodule sentry-dotnet updated 75 files

test/Sentry.Unity.Tests/UnityApplicationLoggingIntegrationTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ public void OnLogMessageReceived_LogTypeException_CaptureExceptionsEnabled_Event
182182
[TestCase(LogType.Error)]
183183
public void OnLogMessageReceived_ExperimentalLogsEnabledWithAttachBreadcrumbsFalse_BreadcrumbsNotAdded(LogType unityLogType)
184184
{
185-
_fixture.SentryOptions.Experimental.EnableLogs = true;
186-
_fixture.SentryOptions.Experimental.AttachBreadcrumbsToEvents = false;
185+
_fixture.SentryOptions.EnableLogs = true;
186+
_fixture.SentryOptions.AttachBreadcrumbsToEvents = false;
187187
_fixture.SentryOptions.AddBreadcrumbsForLogType[unityLogType] = true;
188188
var sut = _fixture.GetSut();
189189
var message = TestContext.CurrentContext.Test.Name;
@@ -205,8 +205,8 @@ public void OnLogMessageReceived_ExperimentalLogsEnabledWithAttachBreadcrumbsFal
205205
[TestCase(LogType.Error)]
206206
public void OnLogMessageReceived_ExperimentalLogsEnabledWithAttachBreadcrumbsTrue_BreadcrumbsAdded(LogType unityLogType)
207207
{
208-
_fixture.SentryOptions.Experimental.EnableLogs = true;
209-
_fixture.SentryOptions.Experimental.AttachBreadcrumbsToEvents = true;
208+
_fixture.SentryOptions.EnableLogs = true;
209+
_fixture.SentryOptions.AttachBreadcrumbsToEvents = true;
210210
_fixture.SentryOptions.AddBreadcrumbsForLogType[unityLogType] = true;
211211
var sut = _fixture.GetSut();
212212
var message = TestContext.CurrentContext.Test.Name;
@@ -230,7 +230,7 @@ public void OnLogMessageReceived_ExperimentalLogsEnabledWithAttachBreadcrumbsTru
230230
[TestCase(LogType.Error)]
231231
public void OnLogMessageReceived_ExperimentalLogsDisabled_BreadcrumbsAddedAsNormal(LogType unityLogType)
232232
{
233-
_fixture.SentryOptions.Experimental.EnableLogs = false;
233+
_fixture.SentryOptions.EnableLogs = false;
234234
_fixture.SentryOptions.AddBreadcrumbsForLogType[unityLogType] = true;
235235
var sut = _fixture.GetSut();
236236
var message = TestContext.CurrentContext.Test.Name;
@@ -303,8 +303,8 @@ public void OnLogMessageReceived_LogErrorAttachStackTraceFalse_CaptureMessageWit
303303
[Test]
304304
public void OnLogMessageReceived_ExperimentalCaptureEnabled_CapturesStructuredLog()
305305
{
306-
_fixture.SentryOptions.Experimental.EnableLogs = true;
307-
_fixture.SentryOptions.Experimental.CaptureStructuredLogsForLogType[LogType.Exception] = true;
306+
_fixture.SentryOptions.EnableLogs = true;
307+
_fixture.SentryOptions.CaptureStructuredLogsForLogType[LogType.Exception] = true;
308308
_fixture.CaptureExceptions = true;
309309
var sut = _fixture.GetSut();
310310
var message = TestContext.CurrentContext.Test.Name;
@@ -321,8 +321,8 @@ public void OnLogMessageReceived_ExperimentalCaptureEnabled_CapturesStructuredLo
321321
[Test]
322322
public void OnLogMessageReceived_ExperimentalCaptureDisabled_DoesNotCaptureStructuredLog()
323323
{
324-
_fixture.SentryOptions.Experimental.EnableLogs = true;
325-
_fixture.SentryOptions.Experimental.CaptureStructuredLogsForLogType[LogType.Exception] = false;
324+
_fixture.SentryOptions.EnableLogs = true;
325+
_fixture.SentryOptions.CaptureStructuredLogsForLogType[LogType.Exception] = false;
326326
_fixture.CaptureExceptions = true;
327327
var sut = _fixture.GetSut();
328328
var message = TestContext.CurrentContext.Test.Name;
@@ -336,8 +336,8 @@ public void OnLogMessageReceived_ExperimentalCaptureDisabled_DoesNotCaptureStruc
336336
[Test]
337337
public void OnLogMessageReceived_WithSentryLogTag_DoesNotCaptureStructuredLog()
338338
{
339-
_fixture.SentryOptions.Experimental.EnableLogs = true;
340-
_fixture.SentryOptions.Experimental.CaptureStructuredLogsForLogType[LogType.Error] = true;
339+
_fixture.SentryOptions.EnableLogs = true;
340+
_fixture.SentryOptions.CaptureStructuredLogsForLogType[LogType.Error] = true;
341341
var sut = _fixture.GetSut();
342342
var message = $"{UnityLogger.LogTag}: Test message";
343343

@@ -350,8 +350,8 @@ public void OnLogMessageReceived_WithSentryLogTag_DoesNotCaptureStructuredLog()
350350
[Test]
351351
public void OnLogMessageReceived_WithEnableLogsFalse_DoesNotCaptureStructuredLog()
352352
{
353-
_fixture.SentryOptions.Experimental.EnableLogs = false;
354-
_fixture.SentryOptions.Experimental.CaptureStructuredLogsForLogType[LogType.Error] = true;
353+
_fixture.SentryOptions.EnableLogs = false;
354+
_fixture.SentryOptions.CaptureStructuredLogsForLogType[LogType.Error] = true;
355355
var sut = _fixture.GetSut();
356356
var message = TestContext.CurrentContext.Test.Name;
357357

@@ -372,8 +372,8 @@ public void OnLogMessageReceived_WithEnableLogsFalse_DoesNotCaptureStructuredLog
372372
[TestCase(LogType.Assert, SentryLogLevel.Error, false)]
373373
public void OnLogMessageReceived_WithExperimentalFlag_CapturesStructuredLogWhenEnabled(LogType logType, SentryLogLevel expectedLevel, bool captureEnabled)
374374
{
375-
_fixture.SentryOptions.Experimental.EnableLogs = true;
376-
_fixture.SentryOptions.Experimental.CaptureStructuredLogsForLogType[logType] = captureEnabled;
375+
_fixture.SentryOptions.EnableLogs = true;
376+
_fixture.SentryOptions.CaptureStructuredLogsForLogType[logType] = captureEnabled;
377377
var sut = _fixture.GetSut();
378378
var message = TestContext.CurrentContext.Test.Name;
379379

0 commit comments

Comments
 (0)