Skip to content

Commit

Permalink
Code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch committed Mar 5, 2024
1 parent f5e6069 commit 2026e86
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/OpenTelemetry/Metrics/MeterProviderSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class MeterProviderSdk : MeterProvider
{
internal const string EmitOverFlowAttributeConfigKey = "OTEL_DOTNET_EXPERIMENTAL_METRICS_EMIT_OVERFLOW_ATTRIBUTE";
internal const string ReclaimUnusedMetricPointsConfigKey = "OTEL_DOTNET_EXPERIMENTAL_METRICS_RECLAIM_UNUSED_METRIC_POINTS";
internal const string ExemplarFilterConfigKey = "OTEL_DOTNET_EXPERIMENTAL_METRICS_EXEMPLAR_FILTER";
internal const string ExemplarFilterConfigKey = "OTEL_METRICS_EXEMPLAR_FILTER";

internal readonly IServiceProvider ServiceProvider;
internal readonly IDisposable? OwnedServiceProvider;
Expand Down Expand Up @@ -490,6 +490,7 @@ private void ApplySpecificationConfigurationKeys(IConfiguration configuration)
OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent("Reclaim unused metric point feature enabled via configuration.");
}

#if EXPOSE_EXPERIMENTAL_FEATURES
if (configuration.TryGetStringValue(ExemplarFilterConfigKey, out var configValue))
{
if (this.ExemplarFilter.HasValue)
Expand Down Expand Up @@ -522,5 +523,6 @@ private void ApplySpecificationConfigurationKeys(IConfiguration configuration)

OpenTelemetrySdkEventSource.Log.MeterProviderSdkEvent($"Exemplar filter set to '{exemplarFilter}' from configuration.");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\EventSourceTestHelper.cs" Link="Includes\EventSourceTestHelper.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\SkipUnlessTrueTheoryAttribute.cs" Link="Includes\SkipUnlessTrueTheoryAttribute.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\TestEventListener.cs" Link="Includes\TestEventListener.cs" />
<Compile Include="$(RepoRoot)\test\OpenTelemetry.Tests\Shared\Utils.cs" Link="Includes\Utils.cs" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion test/OpenTelemetry.Tests/Metrics/MetricExemplarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace OpenTelemetry.Metrics.Tests;
public class MetricExemplarTests : MetricTestsBase
{
private const int MaxTimeToAllowForFlush = 10000;
private static readonly Func<bool> IsExemplarApiExposed = () => typeof(ExemplarFilterType).IsVisible;

[Theory]
[SkipUnlessTrueTheory(typeof(MetricExemplarTests), nameof(IsExemplarApiExposed), "ExemplarFilter config tests skipped for stable builds")]
[InlineData(null, null, null)]
[InlineData(null, "always_off", (int)ExemplarFilterType.AlwaysOff)]
[InlineData(null, "ALWays_ON", (int)ExemplarFilterType.AlwaysOn)]
Expand Down
33 changes: 33 additions & 0 deletions test/OpenTelemetry.Tests/Shared/SkipUnlessTrueTheoryAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Reflection;
using OpenTelemetry.Internal;
using Xunit;

namespace OpenTelemetry.Tests;

internal sealed class SkipUnlessTrueTheoryAttribute : TheoryAttribute
{
public SkipUnlessTrueTheoryAttribute(Type typeContainingTest, string testFieldName, string skipMessage)
{
Guard.ThrowIfNull(typeContainingTest);
Guard.ThrowIfNullOrEmpty(testFieldName);
Guard.ThrowIfNullOrEmpty(skipMessage);

var field = typeContainingTest.GetField(testFieldName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
?? throw new InvalidOperationException($"Static field '{testFieldName}' could not be found on '{typeContainingTest}' type.");

if (field.FieldType != typeof(Func<bool>))
{
throw new InvalidOperationException($"Field '{testFieldName}' on '{typeContainingTest}' type should be defined as '{typeof(Func<bool>)}'.");
}

var testFunc = (Func<bool>)field.GetValue(null);

if (!testFunc())
{
this.Skip = skipMessage;
}
}
}

0 comments on commit 2026e86

Please sign in to comment.