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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void Setup()
SentryLoggingOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
EnableLogs = true,
};
options.SetBeforeSendLog((SentryLog log) =>
{
Expand Down
4 changes: 0 additions & 4 deletions samples/Sentry.Samples.AspNetCore.Basic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
// Configure the minimum Log Level of Breadcrumbs and Events
options.MinimumBreadcrumbLevel = LogLevel.Information;
options.MinimumEventLevel = LogLevel.Error;

// This option enables Logs sent to Sentry
// Configure the minimum Log Level of Structured-Logs via e.g. "appsettings.json" and "appsettings.{HostEnvironment}.json"
options.EnableLogs = true;
});

var app = builder.Build();
Expand Down
4 changes: 1 addition & 3 deletions samples/Sentry.Samples.AspNetCore.Grpc/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"DiagnosticLevel": "Error",
"DefaultTags": {
"default-key-in-config": "default-value"
},
// Record log messages as Structured Logs (configure via "Logging" section)
"EnableLogs": true
}
},
"Logging": {
"IncludeScopes": false,
Expand Down
4 changes: 1 addition & 3 deletions samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"DiagnosticLevel": "Error",
"DefaultTags": {
"default-key-in-config": "default-value"
},
// Record log messages as Structured Logs (configure via "Logging" section)
"EnableLogs": true
}
},
"Logging": {
"LogLevel": {
Expand Down
3 changes: 1 addition & 2 deletions samples/Sentry.Samples.GenericHost/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//"Dsn": "TODO: Configure your DSN here and uncomment this line",
"MinimumBreadcrumbLevel": "Debug",
"MinimumEventLevel": "Warning",
"SendDefaultPii": true, // Send user name and machine name
"EnableLogs": true // Send structured logs
"SendDefaultPii": true // Send user name and machine name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//"Dsn": "TODO: Configure your DSN here and uncomment this line",
"MaxRequestBodySize": "Always",
"SendDefaultPii": true,
"EnableTracing": true,
"EnableLogs" : true
"EnableTracing": true
}
}
1 change: 0 additions & 1 deletion samples/Sentry.Samples.ME.AI.AspNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
options.DiagnosticLevel = SentryLevel.Debug;
options.SampleRate = 1;
options.TracesSampleRate = 1.0;
options.EnableLogs = true;
});

// This sample uses Microsoft.Extensions.AI.OpenAI
Expand Down
2 changes: 0 additions & 2 deletions samples/Sentry.Samples.ME.Logging/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
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

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

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

// The Sentry MVVM Community Toolkit integration automatically creates traces for async relay commands,
Expand Down Expand Up @@ -79,7 +78,7 @@ public static MauiApp CreateMauiApp()
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

// Configure Logging, including Structured Logs sent to Sentry (see 'EnableLogs = true')
// Configure Logging, including Structured Logs sent to Sentry
builder.Logging.AddFilter(null, LogLevel.Warning);
builder.Logging.AddFilter("Sentry.Samples.Maui", LogLevel.Information);

Expand Down
3 changes: 1 addition & 2 deletions samples/Sentry.Samples.NLog/NLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
ignoreEventsWithNoException="False"
includeEventDataOnBreadcrumbs="False"
includeEventPropertiesAsTags="True"
minimumEventLevel="Error"
enableLogs="True">
minimumEventLevel="Error">

<!-- Advanced options can be configured here-->
<options
Expand Down
1 change: 0 additions & 1 deletion samples/Sentry.Samples.NLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private static void UsingCodeConfiguration()
options.MinimumEventLevel = LogLevel.Error; // Error and higher is sent as event (default is Error)

options.AttachStacktrace = true;
options.EnableLogs = true; // send structured logs to Sentry
options.SendDefaultPii = true; // Send Personal Identifiable information like the username of the user logged in to the device

options.IncludeEventDataOnBreadcrumbs = true; // Optionally include event properties with breadcrumbs
Expand Down
2 changes: 0 additions & 2 deletions samples/Sentry.Samples.Serilog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ private static void Main()
// Error and higher is sent as event (default is Error)
options.MinimumEventLevel = LogEventLevel.Error;
options.AttachStacktrace = true;
// send structured logs to Sentry
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
1 change: 0 additions & 1 deletion src/Sentry.Extensions.Logging/SentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ internal SentryStructuredLogger(string categoryName, SentryLoggingOptions option
public bool IsEnabled(LogLevel logLevel)
{
return _hub.IsEnabled
&& _options.EnableLogs
&& logLevel != LogLevel.None;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Sentry.Log4Net/SentryAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected override void Append(LoggingEvent loggingEvent)
}
}

CaptureStructuredLogIfEnabled(loggingEvent);
CaptureStructuredLog(loggingEvent);

var exception = loggingEvent.ExceptionObject ?? loggingEvent.MessageObject as Exception;

Expand All @@ -103,10 +103,10 @@ protected override void Append(LoggingEvent loggingEvent)
CreateSentryEvent(loggingEvent, exception);
}

private void CaptureStructuredLogIfEnabled(LoggingEvent loggingEvent)
private void CaptureStructuredLog(LoggingEvent loggingEvent)
{
var options = _hub.GetSentryOptions();
if (options is not { EnableLogs: true })
if (options is null)
{
return;
}
Expand Down
21 changes: 14 additions & 7 deletions src/Sentry.NLog/SentryTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,20 @@ public string MinimumBreadcrumbLevel
}

/// <summary>
/// Controls whether logs are generated and sent.
/// Logs are always generated and sent.
/// </summary>
/// <remarks>
/// This option no longer has any effect. The getter always returns <see langword="true"/> and the setter is ignored.
/// To filter or drop logs, use <see cref="SentryOptions.SetBeforeSendLog(Func{SentryLog, SentryLog})"/> and return <see langword="null"/>.
/// </remarks>
[Obsolete(SentryOptions.ObsoleteEnableLogs)]
public bool EnableLogs
{
get => Options.EnableLogs;
set => Options.EnableLogs = value;
get => true;
set
{
// Logs are always enabled. This option is deliberately ignored.
}
}

/// <summary>
Expand Down Expand Up @@ -363,11 +371,10 @@ private void InnerWrite(LogEventInfo logEvent)
CreateBreadcrumb(logEvent, exception, shouldIncludeProperties, hub);
}

// Read the options from the Hub rather than the Target's NLog-Options because 'EnableLogs' is declared in the
// base 'SentryOptions', rather than the derived 'SentryNLogOptions'. If the NLog-Target is added without a DSN
// (i.e. without initialising the SDK), then base options will only be initialised in the Hub options.
// Read the options from the Hub rather than the Target's NLog-Options. If the NLog-Target is added without a
// DSN (i.e. without initialising the SDK), then base options will only be initialised in the Hub options.
var sentryOptions = hub.GetSentryOptions();
if (sentryOptions?.EnableLogs is true)
if (sentryOptions is not null)
{
try
{
Expand Down
22 changes: 4 additions & 18 deletions src/Sentry.Serilog/SentrySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ internal SentrySink(

public void Emit(LogEvent logEvent)
{
if (!IsEnabled(logEvent))
{
return;
}

if (isReentrant.Value)
{
_options.DiagnosticLogger?.LogError($"Reentrant log event detected. Logging when inside the scope of another log event can cause a StackOverflowException. LogEventInfo.Message: {logEvent.MessageTemplate.Text}");
Expand All @@ -78,15 +73,6 @@ public void Emit(LogEvent logEvent)
}
}

private bool IsEnabled(LogEvent logEvent)
{
var options = _hubAccessor().GetSentryOptions();

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

private void InnerEmit(LogEvent logEvent)
{
if (logEvent.TryGetSourceContext(out var context))
Expand Down Expand Up @@ -165,11 +151,11 @@ private void InnerEmit(LogEvent logEvent)
level: logEvent.Level.ToBreadcrumbLevel());
}

// Read the options from the Hub, rather than the Sink's Serilog-Options, because 'EnableLogs' is declared in the base 'SentryOptions', rather than the derived 'SentrySerilogOptions'.
// 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.
// Read the options from the Hub, rather than the Sink's Serilog-Options. 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), only the Hub's Sentry-Options have the actual user-defined values configured.
var options = hub.GetSentryOptions();
if (options?.EnableLogs is true)
if (options is not null)
{
CaptureStructuredLog(hub, options, logEvent, formatted, template);
}
Expand Down
10 changes: 2 additions & 8 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="enableLogs">Whether to send structured logs. <seealso cref="SentryOptions.EnableLogs"/></param>
/// <param name="enableLogs">Ignored. Structured logs are always sent. To drop logs, use <see cref="SentryOptions.SetBeforeSendLog(Func{SentryLog, SentryLog})"/> and return <see langword="null"/>.</param>
/// <param name="restrictedToMinimumLevel">The minimum level for events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified. <seealso cref="SentrySerilogOptions.RestrictedToMinimumLevel"/></param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime. <seealso cref="SentrySerilogOptions.LevelSwitch"/></param>
/// <returns><see cref="LoggerConfiguration"/></returns>
Expand Down Expand Up @@ -74,8 +74,7 @@ public static class SentrySinkExtensions
/// "defaultTags": {
/// "key-1", "value-1",
/// "key-2", "value-2"
/// },
/// "enableLogs": true
/// }
/// }
/// }
/// ]
Expand Down Expand Up @@ -335,11 +334,6 @@ internal static void ConfigureSentrySerilogOptions(
sentrySerilogOptions.DeduplicateMode = deduplicateMode.Value;
}

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

sentrySerilogOptions.RestrictedToMinimumLevel = restrictedToMinimumLevel;
sentrySerilogOptions.LevelSwitch = levelSwitch;

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void ApplyTo(SentryOptions options)
options.Distribution = Distribution ?? options.Distribution;
options.Environment = Environment ?? options.Environment;
options.Dsn = Dsn ?? options.Dsn;
#pragma warning disable CS0618 // Bound so existing configuration keys still resolve; the values are ignored.
options.EnableLogs = EnableLogs ?? options.EnableLogs;
#pragma warning disable CS0618 // Bound so existing configuration keys still resolve; the value is ignored.
options.EnableMetrics = EnableMetrics ?? options.EnableMetrics;
#pragma warning restore CS0618
options.MaxQueueItems = MaxQueueItems ?? options.MaxQueueItems;
Expand Down
22 changes: 16 additions & 6 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,17 +607,27 @@ public void SetBeforeBreadcrumb(Func<Breadcrumb, Breadcrumb?> beforeBreadcrumb)
_beforeBreadcrumb = (breadcrumb, _) => beforeBreadcrumb(breadcrumb);
}

internal const string ObsoleteEnableLogs =
"Logs are always enabled. This option is ignored and will be removed in a future major version. " +
"To drop logs, use SetBeforeSendLog and return null.";

/// <summary>
/// When set to <see langword="true"/>, logs captured by the logging integrations
/// (<c>Sentry.Extensions.Logging</c>, <c>Sentry.Serilog</c>, <c>Sentry.NLog</c>, <c>Sentry.Log4Net</c>)
/// are sent to Sentry. Defaults to <see langword="false"/>.
/// Logs are always sent to Sentry.
/// </summary>
/// <remarks>
/// This option does not apply to logs created directly via <see cref="SentryStructuredLogger"/>
/// (typically <c>SentrySdk.Logger</c>), which are always sent.
/// This option no longer has any effect. The getter always returns <see langword="true"/> and the setter is ignored.
/// To filter or drop logs, use <see cref="SetBeforeSendLog(Func{SentryLog, SentryLog})"/> and return <see langword="null"/>.
/// </remarks>
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/logs/"/>
public bool EnableLogs { get; set; } = false;
[Obsolete(ObsoleteEnableLogs)]
public bool EnableLogs
{
get => true;
set
{
// Logs are always enabled. This option is deliberately ignored.
}
}

private Func<SentryLog, SentryLog?>? _beforeSendLog;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ private class Fixture
public Fixture()
{
var loggingOptions = new SentryAspNetCoreOptions();
loggingOptions.EnableLogs = true;

Options = Microsoft.Extensions.Options.Options.Create(loggingOptions);
Hub = Substitute.For<IHub>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void UseSentry_Logging_AddLoggerProviders()
#endif
WebHostBuilder.UseSentry((SentryAspNetCoreOptions options) =>
{
options.EnableLogs = true;
options.InitializeSdk = false;
});
using var serviceProvider = Services.BuildServiceProvider();
Expand All @@ -105,7 +104,6 @@ public void UseSentry_Logging_AddLoggerFilterRules()
{
WebHostBuilder.UseSentry((SentryAspNetCoreOptions options) =>
{
options.EnableLogs = true;
options.InitializeSdk = false;
});
using var serviceProvider = Services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
http.response.status_code: 200
}
}
},
{
Source: {
Length: 7
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
http.response.status_code: 200
}
}
},
{
Source: {
Length: 7
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
http.response.status_code: 200
}
}
},
{
Source: {
Length: 7
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ public async Task PreFlightIgnoresTransaction()

// No transaction should be recorded for pre-flight/options requests
// See: https://github.com/getsentry/sentry-dotnet/issues/1835#issuecomment-1239546099
transport.Payloads.Any().Should().BeFalse();
// Other signals (logs, client reports, ...) are captured as usual - only transactions matter here.
transport.Envelopes
.SelectMany(envelope => envelope.Items)
.Where(item => item.TryGetType() == EnvelopeItem.TypeValueTransaction)
.Should().BeEmpty();
}

[ApiController]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public void AddSentry_LoggingBuilder_AddLoggerProviders()
var serviceCollection = new ServiceCollection();
serviceCollection.AddLogging((ILoggingBuilder builder) => builder.AddSentry(options =>
{
options.EnableLogs = true;
options.InitializeSdk = false;
}));
using var serviceProvider = serviceCollection.BuildServiceProvider();
Expand All @@ -35,7 +34,6 @@ public void AddSentry_LoggingBuilder_AddLoggerFilterRules()
var serviceCollection = new ServiceCollection();
serviceCollection.AddLogging((ILoggingBuilder builder) => builder.AddSentry(options =>
{
options.EnableLogs = true;
options.InitializeSdk = false;
}));
using var serviceProvider = serviceCollection.BuildServiceProvider();
Expand Down
Loading
Loading