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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- The ITraceContext now includes an [Origin](https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/), which is set automatically and is primarily used internally by the Sentry server ([#3564](https://github.com/getsentry/sentry-dotnet/pull/3564))
- `Device.BatteryLevel` and `Device.ProcessorFrequency` are now stored as floats rather than ints, to align with the Cocoa and Java SDKs ([#3567](https://github.com/getsentry/sentry-dotnet/pull/3567))
- `SentryOptions.EnableTracing` has been removed. Instead, tracing should be enabled or disabled by setting the `SentryOptions.TracesSampleRate` or by using `SentryOptions.TracesSampler` to configure a sampling function ([#3569](https://github.com/getsentry/sentry-dotnet/pull/3569))
- The `FailedRequestTargets`, `TagFilters` and `TracePropagationTargets` options have all been changed from `SubstringOrRegexPattern` to `IList<StringOrRegex>` ([#3566](https://github.com/getsentry/sentry-dotnet/pull/3566))

## 4.10.2

Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void ApplyTo(SentryOptions options)
{
options.IsGlobalModeEnabled = IsGlobalModeEnabled ?? options.IsGlobalModeEnabled;
options.EnableScopeSync = EnableScopeSync ?? options.EnableScopeSync;
options.TagFilters = TagFilters?.Select(s => new SubstringOrRegexPattern(s)).ToList() ?? options.TagFilters;
options.TagFilters = TagFilters?.Select(s => new StringOrRegex(s)).ToList() ?? options.TagFilters;
options.SendDefaultPii = SendDefaultPii ?? options.SendDefaultPii;
options.IsEnvironmentUser = IsEnvironmentUser ?? options.IsEnvironmentUser;
options.ServerName = ServerName ?? options.ServerName;
Expand All @@ -80,12 +80,12 @@ public void ApplyTo(SentryOptions options)
options.DeduplicateMode = DeduplicateMode ?? options.DeduplicateMode;
options.CacheDirectoryPath = CacheDirectoryPath ?? options.CacheDirectoryPath;
options.CaptureFailedRequests = CaptureFailedRequests ?? options.CaptureFailedRequests;
options.FailedRequestTargets = FailedRequestTargets?.Select(s => new SubstringOrRegexPattern(s)).ToList() ?? options.FailedRequestTargets;
options.FailedRequestTargets = FailedRequestTargets?.Select(s => new StringOrRegex(s)).ToList() ?? options.FailedRequestTargets;
options.InitCacheFlushTimeout = InitCacheFlushTimeout ?? options.InitCacheFlushTimeout;
options.DefaultTags = DefaultTags ?? options.DefaultTags;
options.TracesSampleRate = TracesSampleRate ?? options.TracesSampleRate;
options.ProfilesSampleRate = ProfilesSampleRate ?? options.ProfilesSampleRate;
options.TracePropagationTargets = TracePropagationTargets?.Select(s => new SubstringOrRegexPattern(s)).ToList() ?? options.TracePropagationTargets;
options.TracePropagationTargets = TracePropagationTargets?.Select(s => new StringOrRegex(s)).ToList() ?? options.TracePropagationTargets;
options.StackTraceMode = StackTraceMode ?? options.StackTraceMode;
options.MaxAttachmentSize = MaxAttachmentSize ?? options.MaxAttachmentSize;
options.DetectStartupTime = DetectStartupTime ?? options.DetectStartupTime;
Expand Down
82 changes: 42 additions & 40 deletions src/Sentry/BuiltInSystemDiagnosticsMeters.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Sentry.Internal;

namespace Sentry;

/// <summary>
/// Well known values for built in metrics that can be configured for
/// Well known values for built-in metrics that can be configured for
/// <see cref="ExperimentalMetricsOptions.CaptureSystemDiagnosticsMeters"/>
/// </summary>
public static partial class BuiltInSystemDiagnosticsMeters
Expand All @@ -20,150 +22,150 @@ public static partial class BuiltInSystemDiagnosticsMeters
private const string SystemNetHttpPattern = @"^System\.Net\.Http$";

/// <summary>
/// Matches the built in Microsoft.AspNetCore.Hosting metrics
/// Matches the built-in Microsoft.AspNetCore.Hosting metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreHosting = MicrosoftAspNetCoreHostingRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreHosting = MicrosoftAspNetCoreHostingRegex();

[GeneratedRegex(MicrosoftAspNetCoreHostingPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreHostingRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreHosting = new Regex(MicrosoftAspNetCoreHostingPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreHosting = new Regex(MicrosoftAspNetCoreHostingPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.AspNetCore.Routing metrics
/// Matches the built-in Microsoft.AspNetCore.Routing metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreRouting = MicrosoftAspNetCoreRoutingRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreRouting = MicrosoftAspNetCoreRoutingRegex();

[GeneratedRegex(MicrosoftAspNetCoreRoutingPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreRoutingRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreRouting = new Regex(MicrosoftAspNetCoreRoutingPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreRouting = new Regex(MicrosoftAspNetCoreRoutingPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.AspNetCore.Diagnostics metrics
/// Matches the built-in Microsoft.AspNetCore.Diagnostics metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreDiagnostics = MicrosoftAspNetCoreDiagnosticsRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreDiagnostics = MicrosoftAspNetCoreDiagnosticsRegex();

[GeneratedRegex(MicrosoftAspNetCoreDiagnosticsPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreDiagnosticsRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreDiagnostics = new Regex(MicrosoftAspNetCoreDiagnosticsPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreDiagnostics = new Regex(MicrosoftAspNetCoreDiagnosticsPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.AspNetCore.RateLimiting metrics
/// Matches the built-in Microsoft.AspNetCore.RateLimiting metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreRateLimiting = MicrosoftAspNetCoreRateLimitingRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreRateLimiting = MicrosoftAspNetCoreRateLimitingRegex();

[GeneratedRegex(MicrosoftAspNetCoreRateLimitingPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreRateLimitingRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreRateLimiting = new Regex(MicrosoftAspNetCoreRateLimitingPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreRateLimiting = new Regex(MicrosoftAspNetCoreRateLimitingPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.AspNetCore.HeaderParsing metrics
/// Matches the built-in Microsoft.AspNetCore.HeaderParsing metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreHeaderParsing = MicrosoftAspNetCoreHeaderParsingRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreHeaderParsing = MicrosoftAspNetCoreHeaderParsingRegex();

[GeneratedRegex(MicrosoftAspNetCoreHeaderParsingPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreHeaderParsingRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreHeaderParsing = new Regex(MicrosoftAspNetCoreHeaderParsingPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreHeaderParsing = new Regex(MicrosoftAspNetCoreHeaderParsingPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.AspNetCore.Server.Kestrel metrics
/// Matches the built-in Microsoft.AspNetCore.Server.Kestrel metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreServerKestrel = MicrosoftAspNetCoreServerKestrelRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreServerKestrel = MicrosoftAspNetCoreServerKestrelRegex();

[GeneratedRegex(MicrosoftAspNetCoreServerKestrelPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreServerKestrelRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreServerKestrel = new Regex(MicrosoftAspNetCoreServerKestrelPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreServerKestrel = new Regex(MicrosoftAspNetCoreServerKestrelPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.AspNetCore.Http.Connections metrics
/// Matches the built-in Microsoft.AspNetCore.Http.Connections metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreHttpConnections = MicrosoftAspNetCoreHttpConnectionsRegex();
public static readonly StringOrRegex MicrosoftAspNetCoreHttpConnections = MicrosoftAspNetCoreHttpConnectionsRegex();

[GeneratedRegex(MicrosoftAspNetCoreHttpConnectionsPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftAspNetCoreHttpConnectionsRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftAspNetCoreHttpConnections = new Regex(MicrosoftAspNetCoreHttpConnectionsPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftAspNetCoreHttpConnections = new Regex(MicrosoftAspNetCoreHttpConnectionsPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.Extensions.Diagnostics.HealthChecks metrics
/// Matches the built-in Microsoft.Extensions.Diagnostics.HealthChecks metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftExtensionsDiagnosticsHealthChecks = MicrosoftExtensionsDiagnosticsHealthChecksRegex();
public static readonly StringOrRegex MicrosoftExtensionsDiagnosticsHealthChecks = MicrosoftExtensionsDiagnosticsHealthChecksRegex();

[GeneratedRegex(MicrosoftExtensionsDiagnosticsHealthChecksPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftExtensionsDiagnosticsHealthChecksRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftExtensionsDiagnosticsHealthChecks = new Regex(MicrosoftExtensionsDiagnosticsHealthChecksPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftExtensionsDiagnosticsHealthChecks = new Regex(MicrosoftExtensionsDiagnosticsHealthChecksPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in Microsoft.Extensions.Diagnostics.ResourceMonitoring metrics
/// Matches the built-in Microsoft.Extensions.Diagnostics.ResourceMonitoring metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern MicrosoftExtensionsDiagnosticsResourceMonitoring = MicrosoftExtensionsDiagnosticsResourceMonitoringRegex();
public static readonly StringOrRegex MicrosoftExtensionsDiagnosticsResourceMonitoring = MicrosoftExtensionsDiagnosticsResourceMonitoringRegex();

[GeneratedRegex(MicrosoftExtensionsDiagnosticsResourceMonitoringPattern, RegexOptions.Compiled)]
private static partial Regex MicrosoftExtensionsDiagnosticsResourceMonitoringRegex();
#else
public static readonly SubstringOrRegexPattern MicrosoftExtensionsDiagnosticsResourceMonitoring = new Regex(MicrosoftExtensionsDiagnosticsResourceMonitoringPattern, RegexOptions.Compiled);
public static readonly StringOrRegex MicrosoftExtensionsDiagnosticsResourceMonitoring = new Regex(MicrosoftExtensionsDiagnosticsResourceMonitoringPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in System.Net.NameResolution metrics
/// Matches the built-in System.Net.NameResolution metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern OpenTelemetryInstrumentationRuntime = OpenTelemetryInstrumentationRuntimeRegex();
public static readonly StringOrRegex OpenTelemetryInstrumentationRuntime = OpenTelemetryInstrumentationRuntimeRegex();

[GeneratedRegex(OpenTelemetryInstrumentationRuntimePattern, RegexOptions.Compiled)]
private static partial Regex OpenTelemetryInstrumentationRuntimeRegex();
#else
public static readonly SubstringOrRegexPattern OpenTelemetryInstrumentationRuntime = new Regex(OpenTelemetryInstrumentationRuntimePattern, RegexOptions.Compiled);
public static readonly StringOrRegex OpenTelemetryInstrumentationRuntime = new Regex(OpenTelemetryInstrumentationRuntimePattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in System.Net.NameResolution metrics
/// Matches the built-in System.Net.NameResolution metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern SystemNetNameResolution = SystemNetNameResolutionRegex();
public static readonly StringOrRegex SystemNetNameResolution = SystemNetNameResolutionRegex();

[GeneratedRegex(SystemNetNameResolutionPattern, RegexOptions.Compiled)]
private static partial Regex SystemNetNameResolutionRegex();
#else
public static readonly SubstringOrRegexPattern SystemNetNameResolution = new Regex(SystemNetNameResolutionPattern, RegexOptions.Compiled);
public static readonly StringOrRegex SystemNetNameResolution = new Regex(SystemNetNameResolutionPattern, RegexOptions.Compiled);
#endif

/// <summary>
/// Matches the built in <see cref="System.Net.Http"/> metrics
/// Matches the built-in <see cref="System.Net.Http"/> metrics
/// </summary>
#if NET8_0_OR_GREATER
public static readonly SubstringOrRegexPattern SystemNetHttp = SystemNetHttpRegex();
public static readonly StringOrRegex SystemNetHttp = SystemNetHttpRegex();

[GeneratedRegex(SystemNetHttpPattern, RegexOptions.Compiled)]
private static partial Regex SystemNetHttpRegex();
#else
public static readonly SubstringOrRegexPattern SystemNetHttp = new Regex(SystemNetHttpPattern, RegexOptions.Compiled);
public static readonly StringOrRegex SystemNetHttp = new Regex(SystemNetHttpPattern, RegexOptions.Compiled);
#endif

private static readonly Lazy<IList<SubstringOrRegexPattern>> LazyAll = new(() => new List<SubstringOrRegexPattern>
private static readonly Lazy<IList<StringOrRegex>> LazyAll = new(() => new List<StringOrRegex>
{
MicrosoftAspNetCoreHosting,
MicrosoftAspNetCoreRouting,
Expand All @@ -180,8 +182,8 @@ public static partial class BuiltInSystemDiagnosticsMeters
});

/// <summary>
/// Matches all built in metrics
/// Matches all built-in metrics
/// </summary>
/// <returns></returns>
public static IList<SubstringOrRegexPattern> All => LazyAll.Value;
public static IList<StringOrRegex> All => LazyAll.Value;
}
14 changes: 8 additions & 6 deletions src/Sentry/ExperimentalMetricsOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Sentry.Internal;

namespace Sentry;

/// <summary>
Expand All @@ -11,21 +13,21 @@ public class ExperimentalMetricsOptions
/// </summary>
public bool EnableCodeLocations { get; set; } = true;

private IList<SubstringOrRegexPattern> _captureSystemDiagnosticsInstruments = new List<SubstringOrRegexPattern>();
private IList<StringOrRegex> _captureSystemDiagnosticsInstruments = new List<StringOrRegex>();

/// <summary>
/// <para>
/// A list of Substrings or Regular Expressions. Any `System.Diagnostics.Metrics.Instrument` whose name
/// matches one of the items in this list will be collected and reported to Sentry.
/// </para>
/// <para>
/// These can be either custom Instruments that you have created or any of the built in metrics that are available.
/// These can be either custom Instruments that you have created or any of the built-in metrics that are available.
/// </para>
/// <para>
/// See https://learn.microsoft.com/en-us/dotnet/core/diagnostics/built-in-metrics for more information.
/// </para>
/// </summary>
public IList<SubstringOrRegexPattern> CaptureSystemDiagnosticsInstruments
public IList<StringOrRegex> CaptureSystemDiagnosticsInstruments
{
// NOTE: During configuration binding, .NET 6 and lower used to just call Add on the existing item.
// .NET 7 changed this to call the setter with an array that already starts with the old value.
Expand All @@ -34,21 +36,21 @@ public IList<SubstringOrRegexPattern> CaptureSystemDiagnosticsInstruments
set => _captureSystemDiagnosticsInstruments = value.WithConfigBinding();
}

private IList<SubstringOrRegexPattern> _captureSystemDiagnosticsMeters = BuiltInSystemDiagnosticsMeters.All;
private IList<StringOrRegex> _captureSystemDiagnosticsMeters = BuiltInSystemDiagnosticsMeters.All;

/// <summary>
/// <para>
/// A list of Substrings or Regular Expressions. Instruments for any `System.Diagnostics.Metrics.Meter`
/// whose name matches one of the items in this list will be collected and reported to Sentry.
/// </para>
/// <para>
/// These can be either custom Instruments that you have created or any of the built in metrics that are available.
/// These can be either custom Instruments that you have created or any of the built-in metrics that are available.
/// </para>
/// <para>
/// See https://learn.microsoft.com/en-us/dotnet/core/diagnostics/built-in-metrics for more information.
/// </para>
/// </summary>
public IList<SubstringOrRegexPattern> CaptureSystemDiagnosticsMeters
public IList<StringOrRegex> CaptureSystemDiagnosticsMeters
{
// NOTE: During configuration binding, .NET 6 and lower used to just call Add on the existing item.
// .NET 7 changed this to call the setter with an array that already starts with the old value.
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/Internal/DelimitedPrefixOrPatternMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ internal class DelimitedPrefixOrPatternMatcher(char delimiter = '.', StringCompa
{
public bool IsMatch(StringOrRegex stringOrRegex, string value)
{
if (stringOrRegex._prefix is not null)
if (stringOrRegex._string is not null)
{
// Check for a prefix followed by the separator
return stringOrRegex._prefix != null && value.StartsWith(stringOrRegex._prefix, comparison) &&
value.Length > stringOrRegex._prefix.Length && value[stringOrRegex._prefix.Length] == delimiter;
return stringOrRegex._string != null && value.StartsWith(stringOrRegex._string, comparison) &&
value.Length > stringOrRegex._string.Length && value[stringOrRegex._string.Length] == delimiter;
}

// Check for any regex match followed by the separator
Expand Down
3 changes: 3 additions & 0 deletions src/Sentry/Internal/IStringOrRegexMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ namespace Sentry.Internal;

internal interface IStringOrRegexMatcher
{
/// <summary>
/// Evaluates if the given value matches the string or regex.
/// </summary>
bool IsMatch(StringOrRegex stringOrRegex, string value);
}
2 changes: 1 addition & 1 deletion src/Sentry/Internal/PrefixOrPatternMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class PrefixOrPatternMatcher(StringComparison comparison = StringCompar
{
public bool IsMatch(StringOrRegex stringOrRegex, string value)
{
return (stringOrRegex._prefix != null && value.StartsWith(stringOrRegex._prefix, comparison)) ||
return (stringOrRegex._string != null && value.StartsWith(stringOrRegex._string, comparison)) ||
stringOrRegex?._regex?.IsMatch(value) == true;
}
}
Loading