Skip to content
Open
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
47 changes: 37 additions & 10 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,16 +1834,7 @@ internal void SetupLogging()
if (DiagnosticLogger == null)
{
DiagnosticLogger = new ConsoleDiagnosticLogger(DiagnosticLevel);
DiagnosticLogger.LogDebug("Logging enabled with ConsoleDiagnosticLogger and min level: {0}",
DiagnosticLevel);
}

if (SettingLocator.GetEnvironment().Equals("production", StringComparison.OrdinalIgnoreCase))
{
DiagnosticLogger.LogWarning("Sentry option 'Debug' is set to true while Environment is production. " +
"Be aware this can cause performance degradation and is not advised. " +
"See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger " +
"for more information");
DiagnosticLogger.LogDebug("Logging enabled with ConsoleDiagnosticLogger and min level: {0}", DiagnosticLevel);
}
}
else
Expand All @@ -1852,6 +1843,42 @@ internal void SetupLogging()
}
}

internal void LogDiagnosticWarning()
{
if (Debug && DiagnosticLogger is not null && SettingLocator.GetEnvironment().Equals("production", StringComparison.OrdinalIgnoreCase))
{
DiagnosticLogger.LogWarning("Sentry option 'Debug' is set to true while Environment is production. " +
"Be aware this can cause performance degradation and is not advised. " +
"See https://docs.sentry.io/platforms/dotnet/configuration/diagnostic-logger " +
"for more information");
}
}

internal string? TryGetDsnSpecificCacheDirectoryPath()
{
if (string.IsNullOrWhiteSpace(CacheDirectoryPath))
{
return null;
}

// DSN must be set to use caching
if (string.IsNullOrWhiteSpace(Dsn))
{
return null;
}
#if IOS || ANDROID // on iOS or Android the app is already sandboxed so there's no risk of sending data from 1 app to another Sentry's DSN
return Path.Combine(CacheDirectoryPath, "Sentry");
#else
return Path.Combine(CacheDirectoryPath, "Sentry", Dsn.GetHashString());
#endif
}

internal string? TryGetProcessSpecificCacheDirectoryPath()
{
// In the future, this will most likely contain process ID
return TryGetDsnSpecificCacheDirectoryPath();
}

internal static List<StringOrRegex> GetDefaultInAppExclude() =>
[
"System",
Expand Down
1 change: 1 addition & 0 deletions src/Sentry/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal static IHub InitHub(SentryOptions options)
options.InitCounter.Increment();

options.SetupLogging();
options.LogDiagnosticWarning();

ProcessInfo.Instance ??= new ProcessInfo(options);

Expand Down
44 changes: 44 additions & 0 deletions test/Sentry.Tests/SentryClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,50 @@ public SentryClientTests(ITestOutputHelper output)
_output = output;
}

[Fact]
public void Ctor_DebugTrue_CreatesConsoleDiagnosticLogger()
{
// Arrange
_fixture.SentryOptions.Debug = true;
_fixture.SentryOptions.DiagnosticLogger = null;

// Act
_ = _fixture.GetSut();

// Assert
Assert.NotNull(_fixture.SentryOptions.DiagnosticLogger);
Assert.IsType<ConsoleDiagnosticLogger>(_fixture.SentryOptions.DiagnosticLogger);
}

[Fact]
public void Ctor_DebugFalseButLoggerSet_SetsLoggerToNull()
{
// Arrange
_fixture.SentryOptions.Debug = false;
_fixture.SentryOptions.DiagnosticLogger = Substitute.For<IDiagnosticLogger>();

// Act
_ = _fixture.GetSut();

// Assert
Assert.Null(_fixture.SentryOptions.DiagnosticLogger);
}

[Fact]
public void Ctor_DebugTrueAndLoggerSet_KeepsExistingLogger()
{
// Arrange
var existingLogger = Substitute.For<IDiagnosticLogger>();
_fixture.SentryOptions.Debug = true;
_fixture.SentryOptions.DiagnosticLogger = existingLogger;

// Act
_ = _fixture.GetSut();

// Assert
Assert.Same(existingLogger, _fixture.SentryOptions.DiagnosticLogger);
}

[Theory]
[MemberData(nameof(GetExceptionFilterTestCases))]
public void CaptureEvent_ExceptionFilteredForType(bool shouldFilter, Exception exception, params IExceptionFilter[] filters)
Expand Down
Loading