Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Renamed Sentry.Runtime to SentryRuntime #3016

Merged
merged 13 commits into from
Jan 11, 2024
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#### Changed APIs

- Class renamed `Sentry.User` to `Sentry.SentryUser` ([#3015](https://github.com/getsentry/sentry-dotnet/pull/3015))
- Renamed `Sentry.User` to `SentryUser` ([#3015](https://github.com/getsentry/sentry-dotnet/pull/3015))
- Renamed `Sentry.Runtime` to `SentryRuntime` ([#3016](https://github.com/getsentry/sentry-dotnet/pull/3016))
bitsandfoxes marked this conversation as resolved.
Show resolved Hide resolved

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Integrations/NetFxInstallationsIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public void Register(IHub hub, SentryOptions options)
{
try
{
if (!Runtime.Current.IsMono())
if (!SentryRuntime.Current.IsMono())
{
options.AddEventProcessor(new NetFxInstallationsEventProcessor(options));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Internal/Enricher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class Enricher

private readonly Lazy<Runtime> _runtimeLazy = new(() =>
{
var current = PlatformAbstractions.Runtime.Current;
var current = PlatformAbstractions.SentryRuntime.Current;
return new Runtime
{
Name = current.Name,
Expand All @@ -36,7 +36,7 @@ public void Apply(IEventLike eventLike)
if (!eventLike.Contexts.ContainsKey(OperatingSystem.Type))
{
// RuntimeInformation.OSDescription is throwing on Mono 5.12
if (!PlatformAbstractions.Runtime.Current.IsMono())
if (!PlatformAbstractions.SentryRuntime.Current.IsMono())
{
#if NETFRAMEWORK
// RuntimeInformation.* throws on .NET Framework on macOS/Linux
Expand Down
32 changes: 16 additions & 16 deletions src/Sentry/PlatformAbstractions/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,53 @@ internal static class RuntimeInfo
/// Gets the current runtime.
/// </summary>
/// <returns>A new instance for the current runtime</returns>
internal static Runtime GetRuntime()
internal static SentryRuntime GetRuntime()
{
var runtime = GetFromRuntimeInformation();
runtime ??= GetFromMonoRuntime();
runtime ??= GetFromEnvironmentVariable();
return runtime.WithAdditionalProperties();
}

internal static Runtime WithAdditionalProperties(this Runtime runtime)
internal static SentryRuntime WithAdditionalProperties(this SentryRuntime runtime)
{
#if NETFRAMEWORK
GetNetFxInstallationAndVersion(runtime, out var inst, out var ver);
var version = runtime.Version ?? ver;
var installation = runtime.FrameworkInstallation ?? inst;
return new Runtime(runtime.Name, version, installation, runtime.Raw);
return new SentryRuntime(runtime.Name, version, installation, runtime.Raw);
#elif NET5_0_OR_GREATER
var version = runtime.Version ?? GetNetCoreVersion(runtime);
var identifier = runtime.Identifier ?? GetRuntimeIdentifier(runtime);
return new Runtime(runtime.Name, version, runtime.Raw, identifier);
return new SentryRuntime(runtime.Name, version, runtime.Raw, identifier);
#else
var version = runtime.Version ?? GetNetCoreVersion(runtime);
return new Runtime(runtime.Name, version, runtime.Raw);
return new SentryRuntime(runtime.Name, version, runtime.Raw);
#endif
}

internal static Runtime? Parse(string? rawRuntimeDescription, string? name = null)
internal static SentryRuntime? Parse(string? rawRuntimeDescription, string? name = null)
{
if (rawRuntimeDescription == null)
{
return name == null ? null : new Runtime(name);
return name == null ? null : new SentryRuntime(name);
}

var match = RuntimeParseRegex.Match(rawRuntimeDescription);
if (match.Success)
{
return new Runtime(
return new SentryRuntime(
name ?? (match.Groups["name"].Value == string.Empty ? null : match.Groups["name"].Value.Trim()),
match.Groups["version"].Value == string.Empty ? null : match.Groups["version"].Value.Trim(),
raw: rawRuntimeDescription);
}

return new Runtime(name, raw: rawRuntimeDescription);
return new SentryRuntime(name, raw: rawRuntimeDescription);
}

#if NETFRAMEWORK
internal static void GetNetFxInstallationAndVersion(
Runtime runtime,
SentryRuntime runtime,
out FrameworkInstallation? frameworkInstallation,
out string? version)
{
Expand All @@ -85,7 +85,7 @@ internal static void GetNetFxInstallationAndVersion(
}
}
#else
private static string? GetNetCoreVersion(Runtime runtime)
private static string? GetNetCoreVersion(SentryRuntime runtime)
{
var description = RuntimeInformation.FrameworkDescription;
return RemovePrefixOrNull(description, ".NET Core")
Expand All @@ -101,7 +101,7 @@ internal static void GetNetFxInstallationAndVersion(
#endif

#if NET5_0_OR_GREATER
internal static string? GetRuntimeIdentifier(Runtime runtime)
internal static string? GetRuntimeIdentifier(SentryRuntime runtime)
{
try
{
Expand All @@ -114,7 +114,7 @@ internal static void GetNetFxInstallationAndVersion(
}
#endif

private static Runtime? GetFromRuntimeInformation()
private static SentryRuntime? GetFromRuntimeInformation()
{
try
{
Expand All @@ -132,7 +132,7 @@ internal static void GetNetFxInstallationAndVersion(
}
}

private static Runtime? GetFromMonoRuntime()
private static SentryRuntime? GetFromMonoRuntime()
=> Type.GetType("Mono.Runtime", false)
?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static)
?.Invoke(null, null) is string monoVersion
Expand All @@ -146,7 +146,7 @@ internal static void GetNetFxInstallationAndVersion(
: null;

// This should really only be used on .NET 1.0, 1.1, 2.0, 3.0, 3.5 and 4.0
private static Runtime GetFromEnvironmentVariable()
private static SentryRuntime GetFromEnvironmentVariable()
{
// Environment.Version: NET Framework 4, 4.5, 4.5.1, 4.5.2 = 4.0.30319.xxxxx
// .NET Framework 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1 = 4.0.30319.42000
Expand All @@ -158,6 +158,6 @@ private static Runtime GetFromEnvironmentVariable()
1 => "",
_ => version.ToString()
};
return new Runtime(".NET Framework", friendlyVersion, raw: "Environment.Version=" + version);
return new SentryRuntime(".NET Framework", friendlyVersion, raw: "Environment.Version=" + version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ namespace Sentry.PlatformAbstractions;
/// <summary>
/// Details of the runtime
/// </summary>
public class Runtime : IEquatable<Runtime>
public class SentryRuntime : IEquatable<SentryRuntime>
{
private static Lazy<Runtime> _currentRuntime = new(RuntimeInfo.GetRuntime);
private static Lazy<SentryRuntime> _currentRuntime = new(RuntimeInfo.GetRuntime);

/// <summary>
/// Gets the current runtime
/// </summary>
/// <value>
/// The current runtime.
/// </value>
public static Runtime Current => _currentRuntime.Value;
public static SentryRuntime Current => _currentRuntime.Value;

/// <summary>
/// The name of the runtime
Expand Down Expand Up @@ -62,7 +62,7 @@ public class Runtime : IEquatable<Runtime>
/// Creates a new Runtime instance
/// </summary>
#if NETFRAMEWORK
public Runtime(
public SentryRuntime(
string? name = null,
string? version = null,
FrameworkInstallation? frameworkInstallation = null,
Expand All @@ -75,7 +75,7 @@ public Runtime(
Identifier = null;
}
#else
public Runtime(
public SentryRuntime(
string? name = null,
string? version = null,
string? raw = null,
Expand Down Expand Up @@ -113,7 +113,7 @@ public Runtime(
/// </summary>
/// <param name="other">The instance to compare against.</param>
/// <returns>True if the instances are equal by reference or its state.</returns>
public bool Equals(Runtime? other)
public bool Equals(SentryRuntime? other)
{
if (other is null)
{
Expand Down Expand Up @@ -157,7 +157,7 @@ public override bool Equals(object? obj)
return false;
}

return Equals((Runtime)obj);
return Equals((SentryRuntime)obj);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
namespace Sentry.PlatformAbstractions;

/// <summary>
/// Extension method to the <see cref="Runtime"/> class.
/// Extension method to the <see cref="SentryRuntime"/> class.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class RuntimeExtensions
public static class SentryRuntimeExtensions
{
/// <summary>
/// Is the runtime instance .NET Framework.
/// </summary>
/// <param name="runtime">The runtime instance to check.</param>
/// <returns>True if it's .NET Framework, otherwise false.</returns>
public static bool IsNetFx(this Runtime runtime) => runtime.StartsWith(".NET Framework");
public static bool IsNetFx(this SentryRuntime runtime) => runtime.StartsWith(".NET Framework");

/// <summary>
/// Is the runtime instance .NET Core (or .NET).
/// </summary>
/// <param name="runtime">The runtime instance to check.</param>
/// <returns>True if it's .NET Core (or .NET), otherwise false.</returns>
public static bool IsNetCore(this Runtime runtime) =>
public static bool IsNetCore(this SentryRuntime runtime) =>
runtime.StartsWith(".NET Core") ||
(runtime.StartsWith(".NET") && !runtime.StartsWith(".NET Framework"));

Expand All @@ -27,16 +27,16 @@ public static bool IsNetCore(this Runtime runtime) =>
/// </summary>
/// <param name="runtime">The runtime instance to check.</param>
/// <returns>True if it's Mono, otherwise false.</returns>
public static bool IsMono(this Runtime runtime) => runtime.StartsWith("Mono");
public static bool IsMono(this SentryRuntime runtime) => runtime.StartsWith("Mono");

/// <summary>
/// Is the runtime instance Browser Web Assembly.
/// </summary>
/// <param name="runtime">The runtime instance to check.</param>
/// <returns>True if it's Browser WASM, otherwise false.</returns>
internal static bool IsBrowserWasm(this Runtime runtime) => runtime.Identifier == "browser-wasm";
internal static bool IsBrowserWasm(this SentryRuntime runtime) => runtime.Identifier == "browser-wasm";

private static bool StartsWith(this Runtime? runtime, string runtimeName) =>
private static bool StartsWith(this SentryRuntime? runtime, string runtimeName) =>
runtime?.Name?.StartsWith(runtimeName, StringComparison.OrdinalIgnoreCase) == true ||
runtime?.Raw?.StartsWith(runtimeName, StringComparison.OrdinalIgnoreCase) == true;
}
2 changes: 1 addition & 1 deletion src/Sentry/Protocol/SampleProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
writer.WriteEndObject();

#if NETFRAMEWORK
if (PlatformAbstractions.Runtime.Current.IsMono())
if (PlatformAbstractions.SentryRuntime.Current.IsMono())
{
// STJ doesn't like HashableGrowableArray on Mono, failing with:
// Invalid IL code in (wrapper dynamic-method) object:.ctor (): IL_0005: ret
Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public bool IsGlobalModeEnabled
/// </summary>
public bool IsGlobalModeEnabled
{
get => _isGlobalModeEnabled ??= Runtime.Current.IsBrowserWasm();
get => _isGlobalModeEnabled ??= SentryRuntime.Current.IsBrowserWasm();
set => _isGlobalModeEnabled = value;
}
#endif
Expand Down Expand Up @@ -938,7 +938,7 @@ public StackTraceMode StackTraceMode
{
// from 3.0.0 uses Enhanced (Ben.Demystifier) by default which is a breaking change
// unless you are using .NET Native which isn't compatible with Ben.Demystifier.
_stackTraceMode = Runtime.Current.Name == ".NET Native"
_stackTraceMode = SentryRuntime.Current.Name == ".NET Native"
? StackTraceMode.Original
: StackTraceMode.Enhanced;
}
Expand Down
16 changes: 8 additions & 8 deletions test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1416,24 +1416,24 @@ namespace Sentry.PlatformAbstractions
Client = 0,
Full = 1,
}
public class Runtime : System.IEquatable<Sentry.PlatformAbstractions.Runtime>
public class SentryRuntime : System.IEquatable<Sentry.PlatformAbstractions.SentryRuntime>
{
public Runtime(string? name = null, string? version = null, string? raw = null, string? identifier = null) { }
public SentryRuntime(string? name = null, string? version = null, string? raw = null, string? identifier = null) { }
public string? Identifier { get; }
public string? Name { get; }
public string? Raw { get; }
public string? Version { get; }
public static Sentry.PlatformAbstractions.Runtime Current { get; }
public bool Equals(Sentry.PlatformAbstractions.Runtime? other) { }
public static Sentry.PlatformAbstractions.SentryRuntime Current { get; }
public bool Equals(Sentry.PlatformAbstractions.SentryRuntime? other) { }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string? ToString() { }
}
public static class RuntimeExtensions
public static class SentryRuntimeExtensions
{
public static bool IsMono(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsNetCore(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsNetFx(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsMono(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
public static bool IsNetCore(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
public static bool IsNetFx(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
}
}
namespace Sentry.Protocol
Expand Down
16 changes: 8 additions & 8 deletions test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1416,24 +1416,24 @@ namespace Sentry.PlatformAbstractions
Client = 0,
Full = 1,
}
public class Runtime : System.IEquatable<Sentry.PlatformAbstractions.Runtime>
public class SentryRuntime : System.IEquatable<Sentry.PlatformAbstractions.SentryRuntime>
{
public Runtime(string? name = null, string? version = null, string? raw = null, string? identifier = null) { }
public SentryRuntime(string? name = null, string? version = null, string? raw = null, string? identifier = null) { }
public string? Identifier { get; }
public string? Name { get; }
public string? Raw { get; }
public string? Version { get; }
public static Sentry.PlatformAbstractions.Runtime Current { get; }
public bool Equals(Sentry.PlatformAbstractions.Runtime? other) { }
public static Sentry.PlatformAbstractions.SentryRuntime Current { get; }
public bool Equals(Sentry.PlatformAbstractions.SentryRuntime? other) { }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string? ToString() { }
}
public static class RuntimeExtensions
public static class SentryRuntimeExtensions
{
public static bool IsMono(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsNetCore(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsNetFx(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsMono(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
public static bool IsNetCore(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
public static bool IsNetFx(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
}
}
namespace Sentry.Protocol
Expand Down
16 changes: 8 additions & 8 deletions test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1417,24 +1417,24 @@ namespace Sentry.PlatformAbstractions
Client = 0,
Full = 1,
}
public class Runtime : System.IEquatable<Sentry.PlatformAbstractions.Runtime>
public class SentryRuntime : System.IEquatable<Sentry.PlatformAbstractions.SentryRuntime>
{
public Runtime(string? name = null, string? version = null, string? raw = null, string? identifier = null) { }
public SentryRuntime(string? name = null, string? version = null, string? raw = null, string? identifier = null) { }
public string? Identifier { get; }
public string? Name { get; }
public string? Raw { get; }
public string? Version { get; }
public static Sentry.PlatformAbstractions.Runtime Current { get; }
public bool Equals(Sentry.PlatformAbstractions.Runtime? other) { }
public static Sentry.PlatformAbstractions.SentryRuntime Current { get; }
public bool Equals(Sentry.PlatformAbstractions.SentryRuntime? other) { }
public override bool Equals(object? obj) { }
public override int GetHashCode() { }
public override string? ToString() { }
}
public static class RuntimeExtensions
public static class SentryRuntimeExtensions
{
public static bool IsMono(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsNetCore(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsNetFx(this Sentry.PlatformAbstractions.Runtime runtime) { }
public static bool IsMono(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
public static bool IsNetCore(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
public static bool IsNetFx(this Sentry.PlatformAbstractions.SentryRuntime runtime) { }
}
}
namespace Sentry.Protocol
Expand Down
Loading
Loading