Skip to content

Commit

Permalink
[repo] Update dotnet format ci job (#4881)
Browse files Browse the repository at this point in the history
Co-authored-by: Reiley Yang <[email protected]>
Co-authored-by: Utkarsh Umesan Pillai <[email protected]>
Co-authored-by: Mikel Blanchard <[email protected]>
  • Loading branch information
4 people authored Nov 1, 2023
1 parent ff9912f commit 2de73b2
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 262 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v3

- name: Install format tool
run: dotnet tool install -g dotnet-format

- name: dotnet format
run: dotnet-format --folder --check
run: dotnet format OpenTelemetry.sln --verify-no-changes
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace OpenTelemetry.Logs;
/// Contains extension methods for the <see cref="LoggerProviderBuilder"/> class.
/// </summary>
#if EXPOSE_EXPERIMENTAL_FEATURES
public
public
#else
internal
#endif
static class OpenTelemetryDependencyInjectionLoggerProviderBuilderExtensions
static class OpenTelemetryDependencyInjectionLoggerProviderBuilderExtensions
{
#if EXPOSE_EXPERIMENTAL_FEATURES
/// <summary>
Expand Down Expand Up @@ -59,9 +59,9 @@ static class OpenTelemetryDependencyInjectionLoggerProviderBuilderExtensions
#endif
public static LoggerProviderBuilder AddInstrumentation<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this LoggerProviderBuilder loggerProviderBuilder)
T>(this LoggerProviderBuilder loggerProviderBuilder)
where T : class
{
loggerProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ namespace OpenTelemetry.Logs;
/// Extension methods for setting up OpenTelemetry logging services in an <see cref="IServiceCollection" />.
/// </summary>
#if EXPOSE_EXPERIMENTAL_FEATURES
public
public
#else
internal
#endif
static class OpenTelemetryDependencyInjectionLoggingServiceCollectionExtensions
static class OpenTelemetryDependencyInjectionLoggingServiceCollectionExtensions
{
#if EXPOSE_EXPERIMENTAL_FEATURES
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static class OpenTelemetryDependencyInjectionMeterProviderBuilderExtensio
/// <returns>The supplied <see cref="MeterProviderBuilder"/> for chaining.</returns>
public static MeterProviderBuilder AddInstrumentation<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this MeterProviderBuilder meterProviderBuilder)
T>(this MeterProviderBuilder meterProviderBuilder)
where T : class
{
meterProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static class OpenTelemetryDependencyInjectionTracerProviderBuilderExtensi
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder AddInstrumentation<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this TracerProviderBuilder tracerProviderBuilder)
T>(this TracerProviderBuilder tracerProviderBuilder)
where T : class
{
tracerProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ internal static class OtlpRetry

public static bool TryGetHttpRetryResult(HttpStatusCode statusCode, DateTime? deadline, HttpResponseHeaders responseHeaders, int retryDelayMilliseconds, out RetryResult retryResult)
{
return OtlpRetry.TryGetRetryResult(statusCode, IsHttpStatusCodeRetryable, deadline, responseHeaders, TryGetHttpRetryDelay, retryDelayMilliseconds, out retryResult);
return TryGetRetryResult(statusCode, IsHttpStatusCodeRetryable, deadline, responseHeaders, TryGetHttpRetryDelay, retryDelayMilliseconds, out retryResult);
}

public static bool TryGetGrpcRetryResult(StatusCode statusCode, DateTime? deadline, Metadata trailers, int retryDelayMilliseconds, out RetryResult retryResult)
{
return OtlpRetry.TryGetRetryResult(statusCode, IsGrpcStatusCodeRetryable, deadline, trailers, TryGetGrpcRetryDelay, retryDelayMilliseconds, out retryResult);
return TryGetRetryResult(statusCode, IsGrpcStatusCodeRetryable, deadline, trailers, TryGetGrpcRetryDelay, retryDelayMilliseconds, out retryResult);
}

private static bool TryGetRetryResult<TStatusCode, TCarrier>(TStatusCode statusCode, Func<TStatusCode, bool, bool> isRetryable, DateTime? deadline, TCarrier carrier, Func<TStatusCode, TCarrier, TimeSpan?> throttleGetter, int nextRetryDelayMilliseconds, out RetryResult retryResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public static LoggerProviderBuilder AddProcessor(this LoggerProviderBuilder logg
#endif
public static LoggerProviderBuilder AddProcessor<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this LoggerProviderBuilder loggerProviderBuilder)
T>(this LoggerProviderBuilder loggerProviderBuilder)
where T : BaseProcessor<LogRecord>
{
loggerProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public static MeterProviderBuilder AddReader(this MeterProviderBuilder meterProv
/// <returns>The supplied <see cref="MeterProviderBuilder"/> for chaining.</returns>
public static MeterProviderBuilder AddReader<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this MeterProviderBuilder meterProviderBuilder)
T>(this MeterProviderBuilder meterProviderBuilder)
where T : MetricReader
{
meterProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public static TracerProviderBuilder SetSampler(this TracerProviderBuilder tracer
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder SetSampler<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this TracerProviderBuilder tracerProviderBuilder)
T>(this TracerProviderBuilder tracerProviderBuilder)
where T : Sampler
{
tracerProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down Expand Up @@ -203,9 +203,9 @@ public static TracerProviderBuilder AddProcessor(this TracerProviderBuilder trac
/// <returns>The supplied <see cref="TracerProviderBuilder"/> for chaining.</returns>
public static TracerProviderBuilder AddProcessor<
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
T>(this TracerProviderBuilder tracerProviderBuilder)
T>(this TracerProviderBuilder tracerProviderBuilder)
where T : BaseProcessor<Activity>
{
tracerProviderBuilder.ConfigureServices(services => services.TryAddSingleton<T>());
Expand Down
133 changes: 66 additions & 67 deletions src/Shared/PeerServiceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,90 +19,89 @@
using System.Runtime.CompilerServices;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Exporter
namespace OpenTelemetry.Exporter;

internal static class PeerServiceResolver
{
internal static class PeerServiceResolver
private static readonly Dictionary<string, int> PeerServiceKeyResolutionDictionary = new(StringComparer.OrdinalIgnoreCase)
{
private static readonly Dictionary<string, int> PeerServiceKeyResolutionDictionary = new(StringComparer.OrdinalIgnoreCase)
{
[SemanticConventions.AttributePeerService] = 0, // priority 0 (highest).
["peer.hostname"] = 1,
["peer.address"] = 1,
[SemanticConventions.AttributeHttpHost] = 2, // peer.service for Http.
[SemanticConventions.AttributeDbInstance] = 2, // peer.service for Redis.
};
[SemanticConventions.AttributePeerService] = 0, // priority 0 (highest).
["peer.hostname"] = 1,
["peer.address"] = 1,
[SemanticConventions.AttributeHttpHost] = 2, // peer.service for Http.
[SemanticConventions.AttributeDbInstance] = 2, // peer.service for Redis.
};

public interface IPeerServiceState
{
string? PeerService { get; set; }
public interface IPeerServiceState
{
string? PeerService { get; set; }

int? PeerServicePriority { get; set; }
int? PeerServicePriority { get; set; }

string? HostName { get; set; }
string? HostName { get; set; }

string? IpAddress { get; set; }
string? IpAddress { get; set; }

long Port { get; set; }
}
long Port { get; set; }
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InspectTag<T>(ref T state, string key, string? value)
where T : struct, IPeerServiceState
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InspectTag<T>(ref T state, string key, string? value)
where T : struct, IPeerServiceState
{
if (PeerServiceKeyResolutionDictionary.TryGetValue(key, out int priority)
&& (state.PeerService == null || priority < state.PeerServicePriority))
{
if (PeerServiceKeyResolutionDictionary.TryGetValue(key, out int priority)
&& (state.PeerService == null || priority < state.PeerServicePriority))
{
state.PeerService = value;
state.PeerServicePriority = priority;
}
else if (key == SemanticConventions.AttributeNetPeerName)
{
state.HostName = value;
}
else if (key == SemanticConventions.AttributeNetPeerIp)
{
state.IpAddress = value;
}
else if (key == SemanticConventions.AttributeNetPeerPort && long.TryParse(value, out var port))
{
state.Port = port;
}
state.PeerService = value;
state.PeerServicePriority = priority;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InspectTag<T>(ref T state, string key, long value)
where T : struct, IPeerServiceState
else if (key == SemanticConventions.AttributeNetPeerName)
{
if (key == SemanticConventions.AttributeNetPeerPort)
{
state.Port = value;
}
state.HostName = value;
}
else if (key == SemanticConventions.AttributeNetPeerIp)
{
state.IpAddress = value;
}
else if (key == SemanticConventions.AttributeNetPeerPort && long.TryParse(value, out var port))
{
state.Port = port;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Resolve<T>(ref T state, out string? peerServiceName, out bool addAsTag)
where T : struct, IPeerServiceState
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InspectTag<T>(ref T state, string key, long value)
where T : struct, IPeerServiceState
{
if (key == SemanticConventions.AttributeNetPeerPort)
{
peerServiceName = state.PeerService;
state.Port = value;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Resolve<T>(ref T state, out string? peerServiceName, out bool addAsTag)
where T : struct, IPeerServiceState
{
peerServiceName = state.PeerService;

// If priority = 0 that means peer.service was included in tags
addAsTag = state.PeerServicePriority != 0;
// If priority = 0 that means peer.service was included in tags
addAsTag = state.PeerServicePriority != 0;

if (addAsTag)
{
var hostNameOrIpAddress = state.HostName ?? state.IpAddress;
if (addAsTag)
{
var hostNameOrIpAddress = state.HostName ?? state.IpAddress;

// peer.service has not already been included, but net.peer.name/ip and optionally net.peer.port are present
if (hostNameOrIpAddress != null)
{
peerServiceName = state.Port == default
? hostNameOrIpAddress
: $"{hostNameOrIpAddress}:{state.Port}";
}
else if (state.PeerService != null)
{
peerServiceName = state.PeerService;
}
// peer.service has not already been included, but net.peer.name/ip and optionally net.peer.port are present
if (hostNameOrIpAddress != null)
{
peerServiceName = state.Port == default
? hostNameOrIpAddress
: $"{hostNameOrIpAddress}:{state.Port}";
}
else if (state.PeerService != null)
{
peerServiceName = state.PeerService;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void TestAddOtlpExporter_SetsCorrectMetricReaderDefaults()

void CheckMetricReaderDefaults()
{
var bindingFlags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;

var metricReader = typeof(MetricReader)
.Assembly
Expand Down
Loading

0 comments on commit 2de73b2

Please sign in to comment.