Skip to content

Commit

Permalink
feat: Renamed Sentry.Runtime to SentryRuntime (#3016)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes authored Jan 11, 2024
1 parent 089fb75 commit bb71eaf
Show file tree
Hide file tree
Showing 22 changed files with 211 additions and 213 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#### Changed APIs

- Class renamed `Sentry.User` to `Sentry.SentryUser` ([#3015](https://github.com/getsentry/sentry-dotnet/pull/3015))
- Class renamed `Sentry.Runtime` to `Sentry.SentryRuntime` ([#3016](https://github.com/getsentry/sentry-dotnet/pull/3016))
- Class renamed `Sentry.Span` to `Sentry.SentrySpan` ([#3021](https://github.com/getsentry/sentry-dotnet/pull/3021))

### 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
14 changes: 7 additions & 7 deletions src/Sentry/Span.cs → src/Sentry/SentrySpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Sentry;
/// <summary>
/// Transaction span.
/// </summary>
public class Span : ISpanData, IJsonSerializable
public class SentrySpan : ISpanData, IJsonSerializable
{
/// <inheritdoc />
public SpanId SpanId { get; private set; }
Expand Down Expand Up @@ -75,9 +75,9 @@ public void SetExtra(string key, object? value) =>
(_extra ??= new Dictionary<string, object?>())[key] = value;

/// <summary>
/// Initializes an instance of <see cref="Span"/>.
/// Initializes an instance of <see cref="SentrySpan"/>.
/// </summary>
public Span(SpanId? parentSpanId, string operation)
public SentrySpan(SpanId? parentSpanId, string operation)
{
SpanId = SpanId.Create();
ParentSpanId = parentSpanId;
Expand All @@ -86,9 +86,9 @@ public Span(SpanId? parentSpanId, string operation)
}

/// <summary>
/// Initializes an instance of <see cref="Span"/>.
/// Initializes an instance of <see cref="SentrySpan"/>.
/// </summary>
public Span(ISpan tracer)
public SentrySpan(ISpan tracer)
: this(tracer.ParentSpanId, tracer.Operation)
{
SpanId = tracer.SpanId;
Expand Down Expand Up @@ -141,7 +141,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
/// <summary>
/// Parses a span from JSON.
/// </summary>
public static Span FromJson(JsonElement json)
public static SentrySpan FromJson(JsonElement json)
{
var spanId = json.GetPropertyOrNull("span_id")?.Pipe(SpanId.FromJson) ?? SpanId.Empty;
var parentSpanId = json.GetPropertyOrNull("parent_span_id")?.Pipe(SpanId.FromJson);
Expand All @@ -156,7 +156,7 @@ public static Span FromJson(JsonElement json)
var measurements = json.GetPropertyOrNull("measurements")?.GetDictionaryOrNull(Measurement.FromJson);
var data = json.GetPropertyOrNull("data")?.GetDictionaryOrNull()?.ToDict();

return new Span(parentSpanId, operation)
return new SentrySpan(parentSpanId, operation)
{
SpanId = spanId,
TraceId = traceId,
Expand Down
8 changes: 4 additions & 4 deletions src/Sentry/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ public IReadOnlyList<string> Fingerprint
public IReadOnlyDictionary<string, string> Tags => _tags;

// Not readonly because of deserialization
private Span[] _spans = Array.Empty<Span>();
private SentrySpan[] _spans = Array.Empty<SentrySpan>();

/// <summary>
/// Flat list of spans within this transaction.
/// </summary>
public IReadOnlyCollection<Span> Spans => _spans;
public IReadOnlyCollection<SentrySpan> Spans => _spans;

/// <inheritdoc />
public bool IsFinished => EndTimestamp is not null;
Expand Down Expand Up @@ -265,7 +265,7 @@ public Transaction(ITransactionTracer tracer)
_tags = tracer.Tags.ToDict();
_spans = tracer.Spans
.Where(s => s is not SpanTracer { IsSentryRequest: true }) // Filter sentry requests created by Sentry.OpenTelemetry.SentrySpanProcessor
.Select(s => new Span(s)).ToArray();
.Select(s => new SentrySpan(s)).ToArray();
_measurements = tracer.Measurements.ToDict();

// Some items are not on the interface, but we only ever pass in a TransactionTracer anyway.
Expand Down Expand Up @@ -383,7 +383,7 @@ public static Transaction FromJson(JsonElement json)
var measurements = json.GetPropertyOrNull("measurements")?
.GetDictionaryOrNull(Measurement.FromJson) ?? new();
var spans = json.GetPropertyOrNull("spans")?
.EnumerateArray().Select(Span.FromJson).ToArray() ?? Array.Empty<Span>();
.EnumerateArray().Select(SentrySpan.FromJson).ToArray() ?? Array.Empty<SentrySpan>();

return new Transaction(name, nameSource)
{
Expand Down
4 changes: 2 additions & 2 deletions test/Sentry.Testing/VerifyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public static SettingsTask IgnoreStandardSentryMembers(this SettingsTask setting
.IgnoreStackTrace();
}

private class SpansConverter : WriteOnlyJsonConverter<IReadOnlyCollection<Span>>
private class SpansConverter : WriteOnlyJsonConverter<IReadOnlyCollection<SentrySpan>>
{
public override void Write(VerifyJsonWriter writer, IReadOnlyCollection<Span> spans)
public override void Write(VerifyJsonWriter writer, IReadOnlyCollection<SentrySpan> spans)
{
var ordered = spans
.OrderBy(x => x.StartTimestamp)
Expand Down
Loading

0 comments on commit bb71eaf

Please sign in to comment.