Skip to content

Commit 275bcef

Browse files
ref!: remove Experimental from Metrics API (#5023)
* ref!: remove Experimental from Metrics API * Changelog --------- Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
1 parent 720312b commit 275bcef

21 files changed

Lines changed: 112 additions & 208 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- GA release for Sentry Metrics ([#5023](https://github.com/getsentry/sentry-dotnet/pull/5023))
8+
39
## 6.2.0
410

511
### Features

Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
<!-- Ignore our own diagnostic ids - these are meant to be external warnings only -->
1515
<NoWarn>$(NoWarn);SENTRY0001</NoWarn>
16-
<NoWarn>$(NoWarn);SENTRYTRACECONNECTEDMETRICS</NoWarn> <!--https://github.com/getsentry/sentry-dotnet/discussions/4838-->
1716

1817
<!-- Allow references to unsigned assemblies (like MAUI) from signed projects -->
1918
<NoWarn>$(NoWarn);CS8002</NoWarn>

samples/Sentry.Samples.Console.Basic/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
return log.Level is SentryLogLevel.Info ? null : log;
5555
});
5656

57-
// Sentry (trace-connected) Metrics via SentrySdk.Experimental.Metrics are enabled by default.
58-
options.Experimental.SetBeforeSendMetric(static metric =>
57+
// Sentry (trace-connected) Metrics via SentrySdk.Metrics are enabled by default.
58+
options.SetBeforeSendMetric(static metric =>
5959
{
6060
if (metric.TryGetValue(out int integer) && integer < 0)
6161
{
@@ -104,13 +104,13 @@ async Task FirstFunction()
104104
SentrySdk.Logger.LogInfo("HTTP Request completed.");
105105

106106
// Counter-Metric prevented from being sent to Sentry via "BeforeSendMetric" callback
107-
SentrySdk.Experimental.Metrics.EmitCounter("sentry.samples.console.basic.ignore", -1);
107+
SentrySdk.Metrics.EmitCounter("sentry.samples.console.basic.ignore", -1);
108108

109109
// Counter-Metric modified before sending it to Sentry via "BeforeSendMetric" callback
110-
SentrySdk.Experimental.Metrics.EmitCounter("sentry.samples.console.basic.http_requests_completed", 1);
110+
SentrySdk.Metrics.EmitCounter("sentry.samples.console.basic.http_requests_completed", 1);
111111

112112
// Distribution-Metric sent as is (see "BeforeSendMetric" callback)
113-
SentrySdk.Experimental.Metrics.EmitDistribution("sentry.samples.console.basic.http_request_duration", stopwatch.Elapsed.TotalSeconds, MeasurementUnit.Duration.Second,
113+
SentrySdk.Metrics.EmitDistribution("sentry.samples.console.basic.http_request_duration", stopwatch.Elapsed.TotalSeconds, MeasurementUnit.Duration.Second,
114114
[new KeyValuePair<string, object>("http.request.method", HttpMethod.Get.Method), new KeyValuePair<string, object>("http.response.status_code", (int)HttpStatusCode.OK)]);
115115
}
116116

src/Sentry/BindableSentryOptions.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal partial class BindableSentryOptions
2222
public string? Environment { get; set; }
2323
public string? Dsn { get; set; }
2424
public bool? EnableLogs { get; set; }
25+
public bool? EnableMetrics { get; set; }
2526
public int? MaxQueueItems { get; set; }
2627
public int? MaxCacheItems { get; set; }
2728
public TimeSpan? ShutdownTimeout { get; set; }
@@ -56,8 +57,6 @@ internal partial class BindableSentryOptions
5657
public bool? EnableSpotlight { get; set; }
5758
public string? SpotlightUrl { get; set; }
5859

59-
public ExperimentalSentryOptions? Experimental { get; set; }
60-
6160
public void ApplyTo(SentryOptions options)
6261
{
6362
options.IsGlobalModeEnabled = IsGlobalModeEnabled ?? options.IsGlobalModeEnabled;
@@ -75,6 +74,7 @@ public void ApplyTo(SentryOptions options)
7574
options.Environment = Environment ?? options.Environment;
7675
options.Dsn = Dsn ?? options.Dsn;
7776
options.EnableLogs = EnableLogs ?? options.EnableLogs;
77+
options.EnableMetrics = EnableMetrics ?? options.EnableMetrics;
7878
options.MaxQueueItems = MaxQueueItems ?? options.MaxQueueItems;
7979
options.MaxCacheItems = MaxCacheItems ?? options.MaxCacheItems;
8080
options.ShutdownTimeout = ShutdownTimeout ?? options.ShutdownTimeout;
@@ -108,24 +108,11 @@ public void ApplyTo(SentryOptions options)
108108
options.EnableSpotlight = EnableSpotlight ?? options.EnableSpotlight;
109109
options.SpotlightUrl = SpotlightUrl ?? options.SpotlightUrl;
110110

111-
if (Experimental is { } experimental)
112-
{
113-
options.Experimental.EnableMetrics = experimental.EnableMetrics ?? options.Experimental.EnableMetrics;
114-
}
115-
116111
#if ANDROID
117112
Android.ApplyTo(options.Android);
118113
Native.ApplyTo(options.Native);
119114
#elif __IOS__
120115
Native.ApplyTo(options.Native);
121116
#endif
122117
}
123-
124-
/// <summary>
125-
/// Bindable Options for <see cref="SentryOptions.ExperimentalSentryOptions"/>.
126-
/// </summary>
127-
internal class ExperimentalSentryOptions
128-
{
129-
public bool? EnableMetrics { get; set; }
130-
}
131118
}

src/Sentry/Extensibility/DisabledHub.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,5 @@ public void Dispose()
270270
/// <summary>
271271
/// Disabled Metrics.
272272
/// </summary>
273-
[Experimental("SENTRYTRACECONNECTEDMETRICS", UrlFormat = "https://github.com/getsentry/sentry-dotnet/discussions/4838")]
274273
public SentryMetricEmitter Metrics => DisabledSentryMetricEmitter.Instance;
275274
}

src/Sentry/Extensibility/HubAdapter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ private HubAdapter() { }
3939
/// <summary>
4040
/// Forwards the call to <see cref="SentrySdk"/>.
4141
/// </summary>
42-
[Experimental("SENTRYTRACECONNECTEDMETRICS", UrlFormat = "https://github.com/getsentry/sentry-dotnet/discussions/4838")]
43-
public SentryMetricEmitter Metrics { [DebuggerStepThrough] get => SentrySdk.Experimental.Metrics; }
42+
public SentryMetricEmitter Metrics { [DebuggerStepThrough] get => SentrySdk.Metrics; }
4443

4544
/// <summary>
4645
/// Forwards the call to <see cref="SentrySdk"/>.

src/Sentry/IHub.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public interface IHub : ISentryClient, ISentryScopeManager
3535
/// <remarks>
3636
/// Available options:
3737
/// <list type="bullet">
38-
/// <item><see cref="Sentry.SentryOptions.ExperimentalSentryOptions.EnableMetrics"/></item>
39-
/// <item><see cref="Sentry.SentryOptions.ExperimentalSentryOptions.SetBeforeSendMetric(System.Func{SentryMetric, SentryMetric})"/></item>
38+
/// <item><see cref="Sentry.SentryOptions.EnableMetrics"/></item>
39+
/// <item><see cref="Sentry.SentryOptions.SetBeforeSendMetric(System.Func{SentryMetric, SentryMetric})"/></item>
4040
/// </list>
4141
/// </remarks>
42-
[Experimental("SENTRYTRACECONNECTEDMETRICS", UrlFormat = "https://github.com/getsentry/sentry-dotnet/discussions/4838")]
4342
public SentryMetricEmitter Metrics { get; }
4443

4544
/// <summary>

src/Sentry/Internal/DefaultSentryMetricEmitter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal sealed class DefaultSentryMetricEmitter : SentryMetricEmitter, IDisposa
1414
internal DefaultSentryMetricEmitter(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
1515
{
1616
Debug.Assert(hub.IsEnabled);
17-
Debug.Assert(options.Experimental is { EnableMetrics: true });
17+
Debug.Assert(options is { EnableMetrics: true });
1818

1919
_hub = hub;
2020
_options = options;
@@ -69,7 +69,7 @@ private protected override void CaptureMetric<T>(SentryMetric<T> metric) where T
6969

7070
SentryMetric? configuredMetric = metric;
7171

72-
if (_options.Experimental.BeforeSendMetricInternal is { } beforeSendMetric)
72+
if (_options.BeforeSendMetricInternal is { } beforeSendMetric)
7373
{
7474
try
7575
{

src/Sentry/SentryMetricEmitter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static SentryMetricEmitter Create(IHub hub, SentryOptions options, ISys
1313

1414
internal static SentryMetricEmitter Create(IHub hub, SentryOptions options, ISystemClock clock, int batchCount, TimeSpan batchInterval)
1515
{
16-
return options.Experimental.EnableMetrics
16+
return options.EnableMetrics
1717
? new DefaultSentryMetricEmitter(hub, options, clock, batchCount, batchInterval)
1818
: DisabledSentryMetricEmitter.Instance;
1919
}

src/Sentry/SentryOptions.cs

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,32 @@ public void SetBeforeSendLog(Func<SentryLog, SentryLog?> beforeSendLog)
569569
_beforeSendLog = beforeSendLog;
570570
}
571571

572+
/// <summary>
573+
/// When set to <see langword="false"/>, the SDK does not generate and send metrics to Sentry via <see cref="SentrySdk.Metrics"/>.
574+
/// Defaults to <see langword="true"/>.
575+
/// </summary>
576+
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/metrics/"/>
577+
public bool EnableMetrics { get; set; } = true;
578+
579+
private Func<SentryMetric, SentryMetric?>? _beforeSendMetric;
580+
581+
internal Func<SentryMetric, SentryMetric?>? BeforeSendMetricInternal => _beforeSendMetric;
582+
583+
/// <summary>
584+
/// Sets a callback function to be invoked before sending the metric to Sentry.
585+
/// When the delegate throws an <see cref="Exception"/> during invocation, the metric will not be captured.
586+
/// </summary>
587+
/// <remarks>
588+
/// It can be used to modify the metric object before being sent to Sentry.
589+
/// To prevent the metric from being sent to Sentry, return <see langword="null"/>.
590+
/// Supported numeric value types are <see langword="byte"/>, <see langword="short"/>, <see langword="int"/>, <see langword="long"/>, <see langword="float"/>, and <see langword="double"/>.
591+
/// </remarks>
592+
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/metrics/"/>
593+
public void SetBeforeSendMetric(Func<SentryMetric, SentryMetric?> beforeSendMetric)
594+
{
595+
_beforeSendMetric = beforeSendMetric;
596+
}
597+
572598
private int _maxQueueItems = 30;
573599

574600
/// <summary>
@@ -1907,51 +1933,4 @@ internal static List<StringOrRegex> GetDefaultInAppExclude() =>
19071933
InAppExcludeRegexes.LibMonoSgen,
19081934
InAppExcludeRegexes.LibXamarin
19091935
];
1910-
1911-
/// <summary>
1912-
/// Sentry features that are currently in an experimental state.
1913-
/// </summary>
1914-
/// <remarks>
1915-
/// Experimental features are subject to binary, source and behavioral breaking changes in future updates.
1916-
/// </remarks>
1917-
public ExperimentalSentryOptions Experimental { get; } = new ExperimentalSentryOptions();
1918-
1919-
/// <summary>
1920-
/// Sentry features that are currently in an experimental state.
1921-
/// </summary>
1922-
/// <remarks>
1923-
/// Experimental features are subject to binary, source and behavioral breaking changes in future updates.
1924-
/// </remarks>
1925-
public class ExperimentalSentryOptions
1926-
{
1927-
private Func<SentryMetric, SentryMetric?>? _beforeSendMetric;
1928-
1929-
internal ExperimentalSentryOptions()
1930-
{
1931-
}
1932-
1933-
internal Func<SentryMetric, SentryMetric?>? BeforeSendMetricInternal => _beforeSendMetric;
1934-
1935-
/// <summary>
1936-
/// When set to <see langword="false"/>, the SDK does not generate and send metrics to Sentry via <see cref="SentrySdk"/>.
1937-
/// Defaults to <see langword="true"/>.
1938-
/// </summary>
1939-
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/metrics/"/>
1940-
public bool EnableMetrics { get; set; } = true;
1941-
1942-
/// <summary>
1943-
/// Sets a callback function to be invoked before sending the metric to Sentry.
1944-
/// When the delegate throws an <see cref="Exception"/> during invocation, the metric will not be captured.
1945-
/// </summary>
1946-
/// <remarks>
1947-
/// It can be used to modify the metric object before being sent to Sentry.
1948-
/// To prevent the metric from being sent to Sentry, return <see langword="null"/>.
1949-
/// Supported numeric value types are <see langword="byte"/>, <see langword="short"/>, <see langword="int"/>, <see langword="long"/>, <see langword="float"/>, and <see langword="double"/>.
1950-
/// </remarks>
1951-
/// <seealso href="https://develop.sentry.dev/sdk/telemetry/metrics/"/>
1952-
public void SetBeforeSendMetric(Func<SentryMetric, SentryMetric?> beforeSendMetric)
1953-
{
1954-
_beforeSendMetric = beforeSendMetric;
1955-
}
1956-
}
19571936
}

0 commit comments

Comments
 (0)