diff --git a/src/Sentry/BindableSentryOptions.cs b/src/Sentry/BindableSentryOptions.cs
index 5f2ede7844..88cf93716c 100644
--- a/src/Sentry/BindableSentryOptions.cs
+++ b/src/Sentry/BindableSentryOptions.cs
@@ -79,7 +79,9 @@ public void ApplyTo(SentryOptions options)
options.Environment = Environment ?? options.Environment;
options.Dsn = Dsn ?? options.Dsn;
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;
options.MaxCacheItems = MaxCacheItems ?? options.MaxCacheItems;
options.ShutdownTimeout = ShutdownTimeout ?? options.ShutdownTimeout;
diff --git a/src/Sentry/IHub.cs b/src/Sentry/IHub.cs
index 7831616152..d2d4ad2d69 100644
--- a/src/Sentry/IHub.cs
+++ b/src/Sentry/IHub.cs
@@ -35,7 +35,6 @@ public interface IHub : ISentryClient, ISentryScopeManager
///
/// Available options:
///
- ///
///
///
///
diff --git a/src/Sentry/Internal/DefaultSentryMetricEmitter.cs b/src/Sentry/Internal/DefaultSentryMetricEmitter.cs
index 1b798b49b1..11d2879295 100644
--- a/src/Sentry/Internal/DefaultSentryMetricEmitter.cs
+++ b/src/Sentry/Internal/DefaultSentryMetricEmitter.cs
@@ -14,7 +14,6 @@ internal sealed class DefaultSentryMetricEmitter : SentryMetricEmitter, IDisposa
internal DefaultSentryMetricEmitter(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
Debug.Assert(hub.IsEnabled);
- Debug.Assert(options is { EnableMetrics: true });
_hub = hub;
_options = options;
diff --git a/src/Sentry/SentryMetricEmitter.cs b/src/Sentry/SentryMetricEmitter.cs
index d3f8aa194c..e44e81289a 100644
--- a/src/Sentry/SentryMetricEmitter.cs
+++ b/src/Sentry/SentryMetricEmitter.cs
@@ -13,9 +13,7 @@ internal static SentryMetricEmitter Create(IHub hub, SentryOptions options, ISys
internal static SentryMetricEmitter Create(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
{
- return options.EnableMetrics
- ? new DefaultSentryMetricEmitter(hub, options, clock, batchCount, batchInterval)
- : DisabledSentryMetricEmitter.Instance;
+ return new DefaultSentryMetricEmitter(hub, options, clock, batchCount, batchInterval);
}
private protected SentryMetricEmitter()
diff --git a/src/Sentry/SentryOptions.cs b/src/Sentry/SentryOptions.cs
index 0dbfd7c99b..0de27069e1 100644
--- a/src/Sentry/SentryOptions.cs
+++ b/src/Sentry/SentryOptions.cs
@@ -632,12 +632,24 @@ public void SetBeforeSendLog(Func beforeSendLog)
_beforeSendLog = beforeSendLog;
}
+ internal const string ObsoleteEnableMetrics =
+ "Metrics are always enabled. This option is ignored and will be removed in version 7.0.0. " +
+ "To drop metrics, use SetBeforeSendMetric and return null.";
+
///
- /// When set to , the SDK does not generate and send metrics to Sentry via .
- /// Defaults to .
+ /// Metrics are always sent to Sentry via .
///
+ ///
+ /// This option no longer has any effect. The getter always returns and the setter is ignored.
+ /// To filter or drop metrics, use and return .
+ ///
///
- public bool EnableMetrics { get; set; } = true;
+ [Obsolete(ObsoleteEnableMetrics)]
+ public bool EnableMetrics
+ {
+ get => true;
+ set { }
+ }
private Func? _beforeSendMetric;
diff --git a/test/Sentry.Compiler.Extensions.Tests/Analyzers/TraceConnectedMetricsAnalyzerTests.cs b/test/Sentry.Compiler.Extensions.Tests/Analyzers/TraceConnectedMetricsAnalyzerTests.cs
index bd70ea2d4a..710a151ce2 100644
--- a/test/Sentry.Compiler.Extensions.Tests/Analyzers/TraceConnectedMetricsAnalyzerTests.cs
+++ b/test/Sentry.Compiler.Extensions.Tests/Analyzers/TraceConnectedMetricsAnalyzerTests.cs
@@ -34,11 +34,6 @@ public async Task NoInvocations_NoDiagnostics()
public class AnalyzerTest
{
- public void Init(SentryOptions options)
- {
- options.EnableMetrics = false;
- }
-
public void Emit(IHub hub)
{
var metrics = SentrySdk.Metrics;
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
index c132faa2b7..5f150f965e 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet10_0.verified.txt
@@ -838,6 +838,8 @@ namespace Sentry
public string? Dsn { get; set; }
public bool EnableBackpressureHandling { get; set; }
public bool EnableLogs { get; set; }
+ [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" +
+ " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")]
public bool EnableMetrics { get; set; }
public bool EnableScopeSync { get; set; }
public bool EnableSpotlight { get; set; }
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
index c132faa2b7..5f150f965e 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
@@ -838,6 +838,8 @@ namespace Sentry
public string? Dsn { get; set; }
public bool EnableBackpressureHandling { get; set; }
public bool EnableLogs { get; set; }
+ [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" +
+ " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")]
public bool EnableMetrics { get; set; }
public bool EnableScopeSync { get; set; }
public bool EnableSpotlight { get; set; }
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
index c132faa2b7..5f150f965e 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.DotNet9_0.verified.txt
@@ -838,6 +838,8 @@ namespace Sentry
public string? Dsn { get; set; }
public bool EnableBackpressureHandling { get; set; }
public bool EnableLogs { get; set; }
+ [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" +
+ " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")]
public bool EnableMetrics { get; set; }
public bool EnableScopeSync { get; set; }
public bool EnableSpotlight { get; set; }
diff --git a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
index efd3961e5d..61369e66c2 100644
--- a/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
+++ b/test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt
@@ -825,6 +825,8 @@ namespace Sentry
public string? Dsn { get; set; }
public bool EnableBackpressureHandling { get; set; }
public bool EnableLogs { get; set; }
+ [System.Obsolete("Metrics are always enabled. This option is ignored and will be removed in version" +
+ " 7.0.0. To drop metrics, use SetBeforeSendMetric and return null.")]
public bool EnableMetrics { get; set; }
public bool EnableScopeSync { get; set; }
public bool EnableSpotlight { get; set; }
diff --git a/test/Sentry.Tests/HubTests.cs b/test/Sentry.Tests/HubTests.cs
index fcc1bf8f54..ae986edb0c 100644
--- a/test/Sentry.Tests/HubTests.cs
+++ b/test/Sentry.Tests/HubTests.cs
@@ -2112,30 +2112,9 @@ public void Logger_Dispose_DoesCaptureLog()
}
[Fact]
- public void Metrics_IsDisabled_DoesNotCaptureMetric()
+ public void Metrics_DoesCaptureMetric()
{
// Arrange
- _fixture.Options.EnableMetrics = false;
- var hub = _fixture.GetSut();
-
- // Act
- hub.Metrics.EmitCounter("sentry_tests.hub_tests.counter", 1);
- hub.Metrics.Flush();
-
- // Assert
- _fixture.Client.Received(0).CaptureEnvelope(
- Arg.Is(envelope =>
- envelope.Items.Single(item => item.Header["type"].Equals("trace_metric")).Payload.GetType().IsAssignableFrom(typeof(JsonSerializable))
- )
- );
- hub.Metrics.Should().BeOfType();
- }
-
- [Fact]
- public void Metrics_IsEnabled_DoesCaptureMetric()
- {
- // Arrange
- Assert.True(_fixture.Options.EnableMetrics);
var hub = _fixture.GetSut();
// Act
@@ -2151,39 +2130,10 @@ public void Metrics_IsEnabled_DoesCaptureMetric()
hub.Metrics.Should().BeOfType();
}
- [Fact]
- public void Metrics_EnableAfterCreate_HasNoEffect()
- {
- // Arrange
- _fixture.Options.EnableMetrics = false;
- var hub = _fixture.GetSut();
-
- // Act
- _fixture.Options.EnableMetrics = true;
-
- // Assert
- hub.Metrics.Should().BeOfType();
- }
-
- [Fact]
- public void Metrics_DisableAfterCreate_HasNoEffect()
- {
- // Arrange
- Assert.True(_fixture.Options.EnableMetrics);
- var hub = _fixture.GetSut();
-
- // Act
- _fixture.Options.EnableMetrics = false;
-
- // Assert
- hub.Metrics.Should().BeOfType();
- }
-
[Fact]
public async Task Metrics_FlushAsync_DoesCaptureMetric()
{
// Arrange
- Assert.True(_fixture.Options.EnableMetrics);
var hub = _fixture.GetSut();
// Act
@@ -2208,7 +2158,6 @@ await _fixture.Client.Received(1).FlushAsync(
public void Metrics_Dispose_DoesCaptureMetric()
{
// Arrange
- Assert.True(_fixture.Options.EnableMetrics);
var hub = _fixture.GetSut();
// Act
diff --git a/test/Sentry.Tests/SentryMetricEmitterTests.Options.cs b/test/Sentry.Tests/SentryMetricEmitterTests.Options.cs
index 10bc6db12d..20e2987434 100644
--- a/test/Sentry.Tests/SentryMetricEmitterTests.Options.cs
+++ b/test/Sentry.Tests/SentryMetricEmitterTests.Options.cs
@@ -5,11 +5,17 @@ namespace Sentry.Tests;
public partial class SentryMetricEmitterTests
{
[Fact]
- public void EnableMetrics_Default_True()
+ public void EnableMetrics_IsObsoleteAndAlwaysEnabled()
{
var options = new SentryOptions();
+#pragma warning disable CS0618 // Type or member is obsolete
options.EnableMetrics.Should().BeTrue();
+
+ options.EnableMetrics = false;
+
+ options.EnableMetrics.Should().BeTrue();
+#pragma warning restore CS0618
}
[Fact]
diff --git a/test/Sentry.Tests/SentryMetricEmitterTests.Types.cs b/test/Sentry.Tests/SentryMetricEmitterTests.Types.cs
index cb6a959a1b..2024db884c 100644
--- a/test/Sentry.Tests/SentryMetricEmitterTests.Types.cs
+++ b/test/Sentry.Tests/SentryMetricEmitterTests.Types.cs
@@ -8,9 +8,8 @@ public partial class SentryMetricEmitterTests
[InlineData(SentryMetricType.Counter)]
[InlineData(SentryMetricType.Gauge)]
[InlineData(SentryMetricType.Distribution)]
- public void Emit_Enabled_CapturesEnvelope(SentryMetricType type)
+ public void Emit_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -27,24 +26,8 @@ public void Emit_Enabled_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Counter)]
[InlineData(SentryMetricType.Gauge)]
[InlineData(SentryMetricType.Distribution)]
- public void Emit_Disabled_DoesNotCaptureEnvelope(SentryMetricType type)
+ public void Emit_Attributes_CapturesEnvelope(SentryMetricType type)
{
- _fixture.Options.EnableMetrics = false;
- var metrics = _fixture.GetSut();
-
- metrics.Emit(type, 1, []);
- metrics.Flush();
-
- _fixture.Hub.Received(0).CaptureEnvelope(Arg.Any());
- }
-
- [Theory]
- [InlineData(SentryMetricType.Counter)]
- [InlineData(SentryMetricType.Gauge)]
- [InlineData(SentryMetricType.Distribution)]
- public void Emit_Attributes_Enabled_CapturesEnvelope(SentryMetricType type)
- {
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -57,28 +40,12 @@ public void Emit_Attributes_Enabled_CapturesEnvelope(SentryMetricType type)
_fixture.AssertEnvelope(envelope, type);
}
- [Theory]
- [InlineData(SentryMetricType.Counter)]
- [InlineData(SentryMetricType.Gauge)]
- [InlineData(SentryMetricType.Distribution)]
- public void Emit_Attributes_Disabled_DoesNotCaptureEnvelope(SentryMetricType type)
- {
- _fixture.Options.EnableMetrics = false;
- var metrics = _fixture.GetSut();
-
- metrics.Emit(type, 1, [new KeyValuePair("attribute-key", "attribute-value")]);
- metrics.Flush();
-
- _fixture.Hub.Received(0).CaptureEnvelope(Arg.Any());
- }
-
[Theory]
[InlineData(SentryMetricType.Counter)]
[InlineData(SentryMetricType.Gauge)]
[InlineData(SentryMetricType.Distribution)]
public void Emit_Byte_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -97,7 +64,6 @@ public void Emit_Byte_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Int16_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -116,7 +82,6 @@ public void Emit_Int16_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Int32_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -135,7 +100,6 @@ public void Emit_Int32_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Int64_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -154,7 +118,6 @@ public void Emit_Int64_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Single_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -173,7 +136,6 @@ public void Emit_Single_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Double_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -192,7 +154,6 @@ public void Emit_Double_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Decimal_DoesNotCaptureEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
metrics.Emit(type, 1m, []);
@@ -213,7 +174,6 @@ public void Emit_Decimal_DoesNotCaptureEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Half_DoesNotCaptureEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
metrics.Emit(type, Half.One, []);
@@ -234,7 +194,6 @@ public void Emit_Half_DoesNotCaptureEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Enum_DoesNotCaptureEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
metrics.Emit(type, (StringComparison)1, []);
@@ -254,7 +213,6 @@ public void Emit_Enum_DoesNotCaptureEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution, nameof(SentryMetricType.Distribution), typeof(int))]
public void Emit_Name_Null_DoesNotCaptureEnvelope(SentryMetricType type, string arg0, Type arg1)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
metrics.Emit(type, null!, 1);
@@ -274,7 +232,6 @@ public void Emit_Name_Null_DoesNotCaptureEnvelope(SentryMetricType type, string
[InlineData(SentryMetricType.Distribution, nameof(SentryMetricType.Distribution), typeof(int))]
public void Emit_Name_Empty_DoesNotCaptureEnvelope(SentryMetricType type, string arg0, Type arg1)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
metrics.Emit(type, "", 1);
@@ -320,7 +277,6 @@ public void Type_EmitMethods_StringUnitParameterOverloadsAreObsoleteForForwardCo
[InlineData(SentryMetricType.Distribution)]
public void Emit_Unit_String_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -338,7 +294,6 @@ public void Emit_Unit_String_CapturesEnvelope(SentryMetricType type)
[InlineData(SentryMetricType.Distribution)]
public void Emit_Unit_MeasurementUnit_CapturesEnvelope(SentryMetricType type)
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
diff --git a/test/Sentry.Tests/SentryMetricEmitterTests.cs b/test/Sentry.Tests/SentryMetricEmitterTests.cs
index 84c850ed05..293bad2cdb 100644
--- a/test/Sentry.Tests/SentryMetricEmitterTests.cs
+++ b/test/Sentry.Tests/SentryMetricEmitterTests.cs
@@ -74,10 +74,8 @@ public void Dispose()
}
[Fact]
- public void Create_Enabled_NewDefaultInstance()
+ public void Create_NewDefaultInstance()
{
- Assert.True(_fixture.Options.EnableMetrics);
-
var instance = _fixture.GetSut();
var other = _fixture.GetSut();
@@ -85,23 +83,10 @@ public void Create_Enabled_NewDefaultInstance()
instance.Should().NotBeSameAs(other);
}
- [Fact]
- public void Create_Disabled_CachedDisabledInstance()
- {
- _fixture.Options.EnableMetrics = false;
-
- var instance = _fixture.GetSut();
- var other = _fixture.GetSut();
-
- instance.Should().BeOfType();
- instance.Should().BeSameAs(other);
- }
-
[Fact]
public void Emit_WithoutActiveSpan_CapturesEnvelope()
{
_fixture.WithoutActiveSpan();
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -120,7 +105,6 @@ public void Emit_WithBeforeSendMetric_InvokesCallback()
var invocations = 0;
SentryMetric configuredMetric = null!;
- Assert.True(_fixture.Options.EnableMetrics);
_fixture.Options.SetBeforeSendMetric((SentryMetric metric) =>
{
invocations++;
@@ -142,7 +126,6 @@ public void Emit_WhenBeforeSendMetricReturnsNull_DoesNotCaptureEnvelope()
{
var invocations = 0;
- Assert.True(_fixture.Options.EnableMetrics);
_fixture.Options.SetBeforeSendMetric((SentryMetric metric) =>
{
invocations++;
@@ -159,7 +142,6 @@ public void Emit_WhenBeforeSendMetricReturnsNull_DoesNotCaptureEnvelope()
[Fact]
public void Emit_InvalidBeforeSendMetric_DoesNotCaptureEnvelope()
{
- Assert.True(_fixture.Options.EnableMetrics);
_fixture.Options.SetBeforeSendMetric(static (SentryMetric metric) => throw new InvalidOperationException());
var metrics = _fixture.GetSut();
@@ -176,7 +158,6 @@ public void Emit_InvalidBeforeSendMetric_DoesNotCaptureEnvelope()
[Fact]
public void Flush_AfterEmit_CapturesEnvelope()
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
Envelope envelope = null!;
@@ -198,7 +179,6 @@ public void Flush_AfterEmit_CapturesEnvelope()
[Fact]
public void Dispose_BeforeEmit_DoesNotCaptureEnvelope()
{
- Assert.True(_fixture.Options.EnableMetrics);
var metrics = _fixture.GetSut();
var defaultMetrics = metrics.Should().BeOfType().Which;