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

Apply formatting fixes using dotnet format #2483

Merged
merged 1 commit into from
Nov 12, 2024
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
6 changes: 4 additions & 2 deletions benchmarks/Elastic.Apm.Benchmarks/Helpers/GitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public GitInfo()
WorkingDirectory = Environment.CurrentDirectory
};

_gitProcess = new Process();
_gitProcess.StartInfo = processInfo;
_gitProcess = new Process
{
StartInfo = processInfo
};
}

public string BranchName => RunCommand("rev-parse --abbrev-ref HEAD");
Expand Down
4 changes: 4 additions & 0 deletions sample/ApiSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ private static void FilterSample()
});
}

#pragma warning disable IDE0022
// ReSharper disable ArrangeMethodOrOperatorBody
public static void SampleSpanWithCustomContext()
{
Expand All @@ -291,7 +292,9 @@ public static void SampleSpanWithCustomContextFillAll()
transaction.CaptureSpan("SampleSpan1", "SampleSpanType", span =>
{
// ReSharper disable once UseObjectOrCollectionInitializer
#pragma warning disable IDE0017
span.Context.Http = new Http { Url = "http://mysite.com", Method = "GET" };
#pragma warning restore IDE0017
// send request, get response with status code
span.Context.Http.StatusCode = 200;
});
Expand All @@ -309,6 +312,7 @@ public static void SampleSpanWithCustomContextFillAll()
});
}
// ReSharper restore ArrangeMethodOrOperatorBody
#pragma warning restore IDE0022

#if NET6_0_OR_GREATER
/// <summary>
Expand Down
11 changes: 10 additions & 1 deletion sample/WebApiExample/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries =
[
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
"Freezing",
"Bracing",
"Chilly",
"Cool",
"Mild",
"Warm",
"Balmy",
"Hot",
"Sweltering",
"Scorching"
];

[HttpGet(Name = "GetWeatherForecast")]
Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Apm/AgentComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void ServerInfoCallback(bool success, IApmServerInfo serverInfo)
}
#endif
}

#pragma warning disable IDE0022
private static IApmLogger DefaultLogger(IApmLogger logger, IConfigurationReader configurationReader)
{
#if NETFRAMEWORK
Expand All @@ -198,6 +198,7 @@ private static IConfigurationReader CreateConfiguration(IApmLogger logger, IConf
return configurationReader ?? new EnvironmentConfiguration(configurationLogger);
#endif
}
#pragma warning restore IDE0022

/// <summary>
/// This ensures agents will respect externally provided loggers.
Expand Down
6 changes: 3 additions & 3 deletions src/Elastic.Apm/Api/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Request
[MaxLength]
public string HttpVersion { get; set; }

[MaxLength] [Required] public string Method { get; set; }
[MaxLength][Required] public string Method { get; set; }

public Socket Socket { get; set; }

Expand Down Expand Up @@ -75,9 +75,9 @@ public string Full
set => _full = Sanitization.TrySanitizeUrl(value, out var newValue, out _) ? newValue : value;
}

[MaxLength] [JsonProperty("hostname")] public string HostName { get; set; }
[MaxLength][JsonProperty("hostname")] public string HostName { get; set; }

[MaxLength] [JsonProperty("pathname")] public string PathName { get; set; }
[MaxLength][JsonProperty("pathname")] public string PathName { get; set; }

[MaxLength] public string Protocol { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,9 @@ private HttpRequestMessage BuildHttpRequest(EntityTagHeaderValue eTag)
_logger.Trace()?.Log("Making HTTP request to APM Server... Request: {HttpRequest}.", httpRequest.RequestUri.Sanitize());

var httpResponse = await HttpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseContentRead, CancellationTokenSource.Token)
.ConfigureAwait(false);
// ReSharper disable once InvertIf
if (httpResponse == null)
{
throw new FailedToFetchConfigException("HTTP client API call for request to APM Server returned null."
.ConfigureAwait(false) ?? throw new FailedToFetchConfigException("HTTP client API call for request to APM Server returned null."
+ $" Request:{Environment.NewLine}{httpRequest.Sanitize(_configurationStore.CurrentSnapshot.SanitizeFieldNames).ToString().Indent()}",
new WaitInfoS(WaitTimeIfAnyError, "HttpResponseMessage from APM Server is null"));
}

_logger.Trace()?.Log("Reading HTTP response body... Response: {HttpResponse}.", httpResponse);
var httpResponseBody = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Elastic.Apm.Instrumentations.SqlClient
{
internal class SqlClientDiagnosticListener : DiagnosticListenerBase
{
private ApmAgent _agent;
private readonly ApmAgent _agent;
private readonly PropertyFetcherSet _microsoftPropertyFetcherSet = new();

private readonly ConcurrentDictionary<Guid, ISpan> _spans = new();
Expand Down
126 changes: 63 additions & 63 deletions src/Elastic.Apm/Logging/GlobalLogConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,79 +27,79 @@ internal class EnvironmentLoggingConfiguration(IDictionary environmentVariables
{
public IDictionary EnvironmentVariables { get; } = environmentVariables ?? Environment.GetEnvironmentVariables();

public string GetSafeEnvironmentVariable(string key)
{
var value = EnvironmentVariables.Contains(key) ? EnvironmentVariables[key]?.ToString() : null;
return value ?? string.Empty;
}
public string GetSafeEnvironmentVariable(string key)
{
var value = EnvironmentVariables.Contains(key) ? EnvironmentVariables[key]?.ToString() : null;
return value ?? string.Empty;
}

public LogLevel? GetLogLevel(params string[] keys)
{
var level = keys
.Select(k => GetSafeEnvironmentVariable(k))
.Select<string, LogLevel?>(v => v.ToLowerInvariant() switch
{
"trace" => LogLevel.Trace,
"debug" => LogLevel.Debug,
"info" => LogLevel.Information,
"warn" => LogLevel.Warning,
"error" => LogLevel.Error,
"none" => LogLevel.None,
_ => null
})
.FirstOrDefault(l => l != null);
return level;
}
public LogLevel? GetLogLevel(params string[] keys)
{
var level = keys
.Select(k => GetSafeEnvironmentVariable(k))
.Select<string, LogLevel?>(v => v.ToLowerInvariant() switch
{
"trace" => LogLevel.Trace,
"debug" => LogLevel.Debug,
"info" => LogLevel.Information,
"warn" => LogLevel.Warning,
"error" => LogLevel.Error,
"none" => LogLevel.None,
_ => null
})
.FirstOrDefault(l => l != null);
return level;
}

public string GetLogDirectory(params string[] keys)
{
var path = keys
.Select(k => GetSafeEnvironmentVariable(k))
.FirstOrDefault(p => !string.IsNullOrEmpty(p));
public string GetLogDirectory(params string[] keys)
{
var path = keys
.Select(k => GetSafeEnvironmentVariable(k))
.FirstOrDefault(p => !string.IsNullOrEmpty(p));

return path;
}
return path;
}

public bool AnyConfigured(params string[] keys) =>
keys
.Select(k => GetSafeEnvironmentVariable(k))
.Any(p => !string.IsNullOrEmpty(p));
public bool AnyConfigured(params string[] keys) =>
keys
.Select(k => GetSafeEnvironmentVariable(k))
.Any(p => !string.IsNullOrEmpty(p));

public GlobalLogTarget? ParseLogTargets(params string[] keys)
{
var targets = keys
.Select(k => GetSafeEnvironmentVariable(k))
.FirstOrDefault(p => !string.IsNullOrEmpty(p));
if (string.IsNullOrWhiteSpace(targets))
return null;
public GlobalLogTarget? ParseLogTargets(params string[] keys)
{
var targets = keys
.Select(k => GetSafeEnvironmentVariable(k))
.FirstOrDefault(p => !string.IsNullOrEmpty(p));
if (string.IsNullOrWhiteSpace(targets))
return null;

var logTargets = GlobalLogTarget.None;
var found = false;
var logTargets = GlobalLogTarget.None;
var found = false;

foreach (var target in targets.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
if (IsSet(target, "stdout"))
logTargets |= GlobalLogTarget.StdOut;
else if (IsSet(target, "file"))
logTargets |= GlobalLogTarget.File;
else if (IsSet(target, "none"))
logTargets |= GlobalLogTarget.None;
}
return !found ? null : logTargets;
foreach (var target in targets.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
if (IsSet(target, "stdout"))
logTargets |= GlobalLogTarget.StdOut;
else if (IsSet(target, "file"))
logTargets |= GlobalLogTarget.File;
else if (IsSet(target, "none"))
logTargets |= GlobalLogTarget.None;
}
return !found ? null : logTargets;

bool IsSet(string k, string v)
{
var b = k.Trim().Equals(v, StringComparison.InvariantCultureIgnoreCase);
if (b)
found = true;
return b;
bool IsSet(string k, string v)
{
var b = k.Trim().Equals(v, StringComparison.InvariantCultureIgnoreCase);
if (b)
found = true;
return b;
}
}
}

internal static string GetDefaultLogDirectory() =>
Environment.OSVersion.Platform == PlatformID.Win32NT
? Path.Combine(Environment.GetEnvironmentVariable("PROGRAMDATA")!, "elastic", "apm-agent-dotnet", "logs")
: "/var/log/elastic/apm-agent-dotnet";
internal static string GetDefaultLogDirectory() =>
Environment.OSVersion.Platform == PlatformID.Win32NT
? Path.Combine(Environment.GetEnvironmentVariable("PROGRAMDATA")!, "elastic", "apm-agent-dotnet", "logs")
: "/var/log/elastic/apm-agent-dotnet";
}

[Flags]
Expand Down
3 changes: 1 addition & 2 deletions src/Elastic.Apm/Logging/LogValuesFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ private object FormatArgument(object value)
return value;

// if the value implements IEnumerable, build a comma separated string.
var enumerable = value as IEnumerable;
if (enumerable != null)
if (value is IEnumerable enumerable)
return string.Join(", ", enumerable.Cast<object>().Select(o => o ?? NullValue));

return value;
Expand Down
3 changes: 1 addition & 2 deletions src/Elastic.Apm/Model/SignatureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void QuerySignature(string query, StringBuilder signature, StringBuilder
if (cachedSignature != null)
{
signature.Append(cachedSignature[0]);
if (dbLink != null)
dbLink.Append(cachedSignature[1]);
dbLink?.Append(cachedSignature[1]);
return;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Elastic.Apm/Reflection/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static Func<TObject, TProperty> BuildPropertyGetter<TObject, TProperty>(s
}

/// <summary>
/// Builds a delegate to get a property from an object. <paramref name="type"/> is cast to <see cref="Object"/>,
/// with the returned property cast to <see cref="Object"/>.
/// Builds a delegate to get a property from an object. <paramref name="type"/> is cast to <see cref="object"/>,
/// with the returned property cast to <see cref="object"/>.
/// </summary>
public static Func<object, object> BuildPropertyGetter(Type type, PropertyInfo propertyInfo)
{
Expand All @@ -36,8 +36,8 @@ public static Func<object, object> BuildPropertyGetter(Type type, PropertyInfo p
}

/// <summary>
/// Builds a delegate to get a property from an object. <paramref name="type"/> is cast to <see cref="Object"/>,
/// with the returned property cast to <see cref="Object"/>.
/// Builds a delegate to get a property from an object. <paramref name="type"/> is cast to <see cref="object"/>,
/// with the returned property cast to <see cref="object"/>.
/// </summary>
public static Func<object, object> BuildFieldGetter(Type type, FieldInfo fieldInfo)
{
Expand All @@ -49,8 +49,8 @@ public static Func<object, object> BuildFieldGetter(Type type, FieldInfo fieldIn
}

/// <summary>
/// Builds a delegate to get a property from an object. <paramref name="type"/> is cast to <see cref="Object"/>,
/// with the returned property cast to <see cref="Object"/>.
/// Builds a delegate to get a property from an object. <paramref name="type"/> is cast to <see cref="object"/>,
/// with the returned property cast to <see cref="object"/>.
/// </summary>
public static Func<object, object> BuildPropertyGetter(Type type, string propertyName)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Elastic.Apm/Reflection/PropertyFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public virtual object Fetch(object obj)
if (_innerFetcher == null)
{
var type = obj.GetType().GetTypeInfo();
var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, PropertyName, StringComparison.OrdinalIgnoreCase));
if (property == null)
property = type.GetProperty(PropertyName);
var property = type.DeclaredProperties.FirstOrDefault(p => string.Equals(p.Name, PropertyName, StringComparison.OrdinalIgnoreCase)) ?? type.GetProperty(PropertyName);

_innerFetcher = PropertyFetch.FetcherForProperty(property);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Elastic.Apm/ServerInfo/ElasticVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ private static int CompareComponent(string a, string b, bool lower = false)
{
var ac = aComps[i];
var bc = bComps[i];
int anum, bnum;
var isanum = int.TryParse(ac, out anum);
var isbnum = int.TryParse(bc, out bnum);
var isanum = int.TryParse(ac, out var anum);
var isbnum = int.TryParse(bc, out var bnum);
int r;
if (isanum && isbnum)
{
Expand Down
2 changes: 1 addition & 1 deletion src/azure/Elastic.Apm.Azure.Storage/BlobUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static bool TryCreate(string url, out BlobUrl blobUrl)

internal abstract class StorageUrl
{
private static char[] SplitDomain = { '.' };
private static readonly char[] SplitDomain = { '.' };

protected StorageUrl(Uri url)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Elastic.Apm.EntityFrameworkCore
internal class EfCoreDiagnosticListener : DiagnosticListenerBase
{
private readonly ConcurrentDictionary<Guid, ISpan> _spans = new ConcurrentDictionary<Guid, ISpan>();
private ApmAgent _agent;
private readonly ApmAgent _agent;

public EfCoreDiagnosticListener(IApmAgent agent) : base(agent) => _agent = agent as ApmAgent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static IServiceCollection AddElasticApmForAspNetCore(this IServiceCollect
{
var subs = subscribers.ToList();
subs.Add(new AspNetCoreDiagnosticSubscriber());
services.AddElasticApm([..subs]);
services.AddElasticApm([.. subs]);
}

return services;
Expand Down
Loading
Loading