Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ public void Setup()
SentryLoggingOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
Experimental =
{
EnableLogs = true,
},
ExperimentalLogging =
{
MinimumLogLevel = LogLevel.Information,
}
EnableLogs = true,
};
options.Experimental.SetBeforeSendLog((SentryLog log) =>
options.SetBeforeSendLog((SentryLog log) =>
{
_lastLog = log;
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ public void Setup()
SentryOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
Experimental =
{
EnableLogs = true,
},
EnableLogs = true,
};

var batchInterval = Timeout.InfiniteTimeSpan;
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.AspNetCore.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#endif

// This option enables Logs sent to Sentry.
options.Experimental.EnableLogs = true;
options.EnableLogs = true;
});

var app = builder.Build();
Expand Down
4 changes: 2 additions & 2 deletions samples/Sentry.Samples.Console.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
options.TracesSampleRate = 1.0;

// This option enables Sentry Logs created via SentrySdk.Logger.
options.Experimental.EnableLogs = true;
options.Experimental.SetBeforeSendLog(static log =>
options.EnableLogs = true;
options.SetBeforeSendLog(static log =>
{
// A demonstration of how you can drop logs based on some attribute they have
if (log.TryGetAttribute("suppress", out var attribute) && attribute is true)
Expand Down
5 changes: 2 additions & 3 deletions samples/Sentry.Samples.ME.Logging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
// Optionally configure options: The default values are:
options.MinimumBreadcrumbLevel = LogLevel.Information; // It requires at least this level to store breadcrumb
options.MinimumEventLevel = LogLevel.Error; // This level or above will result in event sent to Sentry
options.ExperimentalLogging.MinimumLogLevel = LogLevel.Trace; // This level or above will result in log sent to Sentry

// This option enables Logs sent to Sentry.
options.Experimental.EnableLogs = true;
options.Experimental.SetBeforeSendLog(static log =>
options.EnableLogs = true;
options.SetBeforeSendLog(static log =>
{
log.SetAttribute("attribute-key", "attribute-value");
return log;
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static MauiApp CreateMauiApp()
options.AttachScreenshot = true;

options.Debug = true;
options.Experimental.EnableLogs = true;
options.EnableLogs = true;
options.SampleRate = 1.0F;

// The Sentry MVVM Community Toolkit integration automatically creates traces for async relay commands,
Expand Down
2 changes: 1 addition & 1 deletion samples/Sentry.Samples.Serilog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private static void Main()
options.MinimumEventLevel = LogEventLevel.Error;
options.AttachStacktrace = true;
// send structured logs to Sentry
options.Experimental.EnableLogs = true;
options.EnableLogs = true;
// send PII like the username of the user logged in to the device
options.SendDefaultPii = true;
// Optional Serilog text formatter used to format LogEvent to string. If TextFormatter is set, FormatProvider is ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ public void ApplyTo(SentryLoggingOptions options)
options.MinimumBreadcrumbLevel = MinimumBreadcrumbLevel ?? options.MinimumBreadcrumbLevel;
options.MinimumEventLevel = MinimumEventLevel ?? options.MinimumEventLevel;
options.InitializeSdk = InitializeSdk ?? options.InitializeSdk;

options.ExperimentalLogging.MinimumLogLevel = ExperimentalLogging.MinimumLogLevel ?? options.ExperimentalLogging.MinimumLogLevel;
}
}
35 changes: 0 additions & 35 deletions src/Sentry.Extensions.Logging/SentryLoggingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,39 +50,4 @@ public class SentryLoggingOptions : SentryOptions
/// List of callbacks to be invoked when initializing the SDK
/// </summary>
internal Action<Scope>[] ConfigureScopeCallbacks { get; set; } = Array.Empty<Action<Scope>>();

/// <summary>
/// Experimental Sentry Logging features.
/// </summary>
/// <remarks>
/// This and related experimental APIs may change in the future.
/// </remarks>
[Experimental(Infrastructure.DiagnosticId.ExperimentalFeature)]
public SentryLoggingExperimentalOptions ExperimentalLogging { get; set; } = new();

/// <summary>
/// Experimental Sentry Logging options.
/// </summary>
/// <remarks>
/// This and related experimental APIs may change in the future.
/// </remarks>
[Experimental(Infrastructure.DiagnosticId.ExperimentalFeature)]
public sealed class SentryLoggingExperimentalOptions
{
internal SentryLoggingExperimentalOptions()
{
}

/// <summary>
/// Gets or sets the minimum log level.
/// <para>This API is experimental and it may change in the future.</para>
/// </summary>
/// <remarks>
/// Logs with this level or higher will be stored as <see cref="SentryLog"/>.
/// </remarks>
/// <value>
/// The minimum log level.
/// </value>
public LogLevel MinimumLogLevel { get; set; } = LogLevel.Trace;
}
}
5 changes: 2 additions & 3 deletions src/Sentry.Extensions.Logging/SentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ internal SentryStructuredLogger(string categoryName, SentryLoggingOptions option
public bool IsEnabled(LogLevel logLevel)
{
return _hub.IsEnabled
&& _options.Experimental.EnableLogs
&& logLevel != LogLevel.None
&& logLevel >= _options.ExperimentalLogging.MinimumLogLevel;
&& _options.EnableLogs
&& logLevel != LogLevel.None;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry.Serilog/SentrySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private bool IsEnabled(LogEvent logEvent)

return logEvent.Level >= _options.MinimumEventLevel
|| logEvent.Level >= _options.MinimumBreadcrumbLevel
|| options?.Experimental.EnableLogs is true;
|| options?.EnableLogs is true;
}

private void InnerEmit(LogEvent logEvent)
Expand Down Expand Up @@ -169,7 +169,7 @@ private void InnerEmit(LogEvent logEvent)
// In cases where Sentry's Serilog-Sink is added without a DSN (i.e., without initializing the SDK) and the SDK is initialized differently (e.g., through ASP.NET Core),
// then the 'EnableLogs' option of this Sink's Serilog-Options is default, but the Hub's Sentry-Options have the actual user-defined value configured.
var options = hub.GetSentryOptions();
if (options?.Experimental.EnableLogs is true)
if (options?.EnableLogs is true)
{
CaptureStructuredLog(hub, options, logEvent, formatted, template);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Sentry.Serilog/SentrySinkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class SentrySinkExtensions
/// <param name="reportAssembliesMode">What mode to use for reporting referenced assemblies in each event sent to sentry. Defaults to <see cref="Sentry.ReportAssembliesMode.Version"/></param>
/// <param name="deduplicateMode">What modes to use for event automatic de-duplication. <seealso cref="SentryOptions.DeduplicateMode"/></param>
/// <param name="defaultTags">Default tags to add to all events. <seealso cref="SentryOptions.DefaultTags"/></param>
/// <param name="experimentalEnableLogs">Whether to send structured logs. <seealso cref="SentryOptions.SentryExperimentalOptions.EnableLogs"/></param>
/// <param name="enableLogs">Whether to send structured logs. <seealso cref="SentryOptions.EnableLogs"/></param>
/// <returns><see cref="LoggerConfiguration"/></returns>
/// <example>This sample shows how each item may be set from within a configuration file:
/// <code>
Expand Down Expand Up @@ -73,7 +73,7 @@ public static class SentrySinkExtensions
/// "key-1", "value-1",
/// "key-2", "value-2"
/// },
/// "experimentalEnableLogs": true
/// "enableLogs": true
/// }
/// }
/// ]
Expand Down Expand Up @@ -106,7 +106,7 @@ public static LoggerConfiguration Sentry(
ReportAssembliesMode? reportAssembliesMode = null,
DeduplicateMode? deduplicateMode = null,
Dictionary<string, string>? defaultTags = null,
bool? experimentalEnableLogs = null)
bool? enableLogs = null)
{
return loggerConfiguration.Sentry(o => ConfigureSentrySerilogOptions(o,
dsn,
Expand All @@ -132,7 +132,7 @@ public static LoggerConfiguration Sentry(
reportAssembliesMode,
deduplicateMode,
defaultTags,
experimentalEnableLogs));
enableLogs));
}

/// <summary>
Expand Down Expand Up @@ -210,7 +210,7 @@ internal static void ConfigureSentrySerilogOptions(
ReportAssembliesMode? reportAssembliesMode = null,
DeduplicateMode? deduplicateMode = null,
Dictionary<string, string>? defaultTags = null,
bool? experimentalEnableLogs = null)
bool? enableLogs = null)
{
if (dsn is not null)
{
Expand Down Expand Up @@ -322,9 +322,9 @@ internal static void ConfigureSentrySerilogOptions(
sentrySerilogOptions.DeduplicateMode = deduplicateMode.Value;
}

if (experimentalEnableLogs.HasValue)
if (enableLogs.HasValue)
{
sentrySerilogOptions.Experimental.EnableLogs = experimentalEnableLogs.Value;
sentrySerilogOptions.EnableLogs = enableLogs.Value;
}

// Serilog-specific items
Expand Down
11 changes: 2 additions & 9 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal partial class BindableSentryOptions
public string? Distribution { get; set; }
public string? Environment { get; set; }
public string? Dsn { get; set; }
public bool? EnableLogs { get; set; }
public int? MaxQueueItems { get; set; }
public int? MaxCacheItems { get; set; }
public TimeSpan? ShutdownTimeout { get; set; }
Expand Down Expand Up @@ -55,13 +56,6 @@ internal partial class BindableSentryOptions
public bool? EnableSpotlight { get; set; }
public string? SpotlightUrl { get; set; }

public BindableSentryExperimentalOptions Experimental { get; set; } = new();

internal sealed class BindableSentryExperimentalOptions
{
public bool? EnableLogs { get; set; }
}

public void ApplyTo(SentryOptions options)
{
options.IsGlobalModeEnabled = IsGlobalModeEnabled ?? options.IsGlobalModeEnabled;
Expand All @@ -78,6 +72,7 @@ public void ApplyTo(SentryOptions options)
options.Distribution = Distribution ?? options.Distribution;
options.Environment = Environment ?? options.Environment;
options.Dsn = Dsn ?? options.Dsn;
options.EnableLogs = EnableLogs ?? options.EnableLogs;
options.MaxQueueItems = MaxQueueItems ?? options.MaxQueueItems;
options.MaxCacheItems = MaxCacheItems ?? options.MaxCacheItems;
options.ShutdownTimeout = ShutdownTimeout ?? options.ShutdownTimeout;
Expand Down Expand Up @@ -111,8 +106,6 @@ public void ApplyTo(SentryOptions options)
options.EnableSpotlight = EnableSpotlight ?? options.EnableSpotlight;
options.SpotlightUrl = SpotlightUrl ?? options.SpotlightUrl;

options.Experimental.EnableLogs = Experimental.EnableLogs ?? options.Experimental.EnableLogs;

#if ANDROID
Android.ApplyTo(options.Android);
Native.ApplyTo(options.Native);
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/IHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public interface IHub : ISentryClient, ISentryScopeManager
/// <remarks>
/// Available options:
/// <list type="bullet">
/// <item><see cref="Sentry.SentryOptions.SentryExperimentalOptions.EnableLogs"/></item>
/// <item><see cref="Sentry.SentryOptions.SentryExperimentalOptions.SetBeforeSendLog(System.Func{SentryLog, SentryLog})"/></item>
/// <item><see cref="Sentry.SentryOptions.EnableLogs"/></item>
/// <item><see cref="Sentry.SentryOptions.SetBeforeSendLog(System.Func{SentryLog, SentryLog})"/></item>
/// </list>
/// </remarks>
public SentryStructuredLogger Logger { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Internal/DefaultSentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class DefaultSentryStructuredLogger : SentryStructuredLogger, ID
internal DefaultSentryStructuredLogger(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
Debug.Assert(hub.IsEnabled);
Debug.Assert(options is { Experimental.EnableLogs: true });
Debug.Assert(options is { EnableLogs: true });

_hub = hub;
_options = options;
Expand Down Expand Up @@ -79,7 +79,7 @@ protected internal override void CaptureLog(SentryLog log)
{
var configuredLog = log;

if (_options.Experimental.BeforeSendLogInternal is { } beforeSendLog)
if (_options.BeforeSendLogInternal is { } beforeSendLog)
{
try
{
Expand Down
71 changes: 25 additions & 46 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,31 @@ public void SetBeforeBreadcrumb(Func<Breadcrumb, Breadcrumb?> beforeBreadcrumb)
_beforeBreadcrumb = (breadcrumb, _) => beforeBreadcrumb(breadcrumb);
}

/// <summary>
/// When set to <see langword="true"/>, logs are sent to Sentry.
/// Defaults to <see langword="false"/>.
/// </summary>
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/logs/"/>
public bool EnableLogs { get; set; } = false;

private Func<SentryLog, SentryLog?>? _beforeSendLog;

internal Func<SentryLog, SentryLog?>? BeforeSendLogInternal => _beforeSendLog;

/// <summary>
/// Sets a callback function to be invoked before sending the log to Sentry.
/// When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.
/// </summary>
/// <remarks>
/// It can be used to modify the log object before being sent to Sentry.
/// To prevent the log from being sent to Sentry, return <see langword="null"/>.
/// </remarks>
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/logs/"/>
public void SetBeforeSendLog(Func<SentryLog, SentryLog?> beforeSendLog)
{
_beforeSendLog = beforeSendLog;
}

private int _maxQueueItems = 30;

/// <summary>
Expand Down Expand Up @@ -1878,50 +1903,4 @@ internal static List<StringOrRegex> GetDefaultInAppExclude() =>
"ServiceStack",
"Java.Interop",
];

/// <summary>
/// Experimental Sentry features.
/// </summary>
/// <remarks>
/// This and related experimental APIs may change in the future.
/// </remarks>
public SentryExperimentalOptions Experimental { get; set; } = new();

/// <summary>
/// Experimental Sentry SDK options.
/// </summary>
/// <remarks>
/// This and related experimental APIs may change in the future.
/// </remarks>
public class SentryExperimentalOptions
{
internal SentryExperimentalOptions()
{
}

/// <summary>
/// When set to <see langword="true"/>, logs are sent to Sentry.
/// Defaults to <see langword="false"/>.
/// </summary>
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/logs/"/>
public bool EnableLogs { get; set; } = false;

private Func<SentryLog, SentryLog?>? _beforeSendLog;

internal Func<SentryLog, SentryLog?>? BeforeSendLogInternal => _beforeSendLog;

/// <summary>
/// Sets a callback function to be invoked before sending the log to Sentry.
/// When the delegate throws an <see cref="Exception"/> during invocation, the log will not be captured.
/// </summary>
/// <remarks>
/// It can be used to modify the log object before being sent to Sentry.
/// To prevent the log from being sent to Sentry, return <see langword="null"/>.
/// </remarks>
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/logs/"/>
public void SetBeforeSendLog(Func<SentryLog, SentryLog?> beforeSendLog)
{
_beforeSendLog = beforeSendLog;
}
}
}
2 changes: 1 addition & 1 deletion src/Sentry/SentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, I

internal static SentryStructuredLogger Create(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
return options.Experimental.EnableLogs
return options.EnableLogs
? new DefaultSentryStructuredLogger(hub, options, clock, batchCount, batchInterval)
: DisabledSentryStructuredLogger.Instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private class Fixture
public Fixture()
{
var loggingOptions = new SentryAspNetCoreOptions();
loggingOptions.Experimental.EnableLogs = true;
loggingOptions.EnableLogs = true;

Options = Microsoft.Extensions.Options.Options.Create(loggingOptions);
Hub = Substitute.For<IHub>();
Expand Down
Loading
Loading