Skip to content

Commit

Permalink
Get coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer committed Jul 18, 2023
1 parent 65ddc68 commit e5f9437
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Telemetry.Enrichment;
Expand Down Expand Up @@ -50,7 +51,7 @@ public static IServiceCollection AddLogEnricher(this IServiceCollection services
/// <typeparam name="T">Enricher type.</typeparam>
/// <returns>The value of <paramref name="services"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="services"/> is <see langword="null"/>.</exception>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public static IServiceCollection AddStaticLogEnricher<T>(this IServiceCollection services)
where T : class, IStaticLogEnricher
{
Expand All @@ -66,7 +67,7 @@ public static IServiceCollection AddStaticLogEnricher<T>(this IServiceCollection
/// <param name="enricher">The enricher instance to add.</param>
/// <returns>The value of <paramref name="services"/>.</returns>
/// <exception cref="ArgumentNullException"><paramref name="services"/> or <paramref name="enricher"/> are <see langword="null"/>.</exception>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public static IServiceCollection AddStaticLogEnricher(this IServiceCollection services, IStaticLogEnricher enricher)
{
_ = Throw.IfNull(services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Telemetry.Enrichment;

/// <summary>
/// A component that augments log records with additional properties which are unchanging over the life of the object.
/// </summary>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public interface IStaticLogEnricher
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Shared.DiagnosticIds;

namespace Microsoft.Extensions.Telemetry.Logging;

Expand Down Expand Up @@ -36,6 +37,6 @@ public interface ILogPropertyCollector
/// <exception cref="ArgumentException"><paramref name="propertyName" /> is empty or contains exclusively whitespace,
/// or when a property of the same name has already been added.
/// </exception>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
void Add(string propertyName, object? propertyValue, DataClassification classification);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Telemetry.Enrichment;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;
using Microsoft.Shared.Pools;

Expand Down Expand Up @@ -37,7 +38,7 @@ public void Add(string propertyName, object? propertyValue)
}

/// <inheritdoc/>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public void Add(string propertyName, object? propertyValue, DataClassification classification) => Add(propertyName, propertyValue);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Pools;

namespace Microsoft.Extensions.Telemetry.Logging;
Expand All @@ -15,7 +16,7 @@ namespace Microsoft.Extensions.Telemetry.Logging;
/// Utility type to support generated logging methods.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public static class LoggerMessageHelper
{
[ThreadStatic]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Pools;

namespace Microsoft.Extensions.Telemetry.Logging;

/// <summary>
/// Additional state to use with <see cref="ILogger.Log"/>.
/// </summary>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed partial class LoggerMessageState
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<Stage>normal</Stage>
<MinCodeCoverage>99</MinCodeCoverage>
<MinCodeCoverage>100</MinCodeCoverage>
<MinMutationScore>100</MinMutationScore>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options.Validation;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Telemetry.Logging;

/// <summary>
/// Extensions for configuring logging enrichment features.
/// </summary>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public static class LoggingEnrichmentExtensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Shared.DiagnosticIds;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Extensions.Telemetry.Logging;

/// <summary>
/// Extensions for configuring logging redaction features.
/// </summary>
[Experimental(diagnosticId: "TBD", UrlFormat = "TBD")]
[Experimental(diagnosticId: Experiments.Telemetry, UrlFormat = Experiments.UrlFormat)]
public static class LoggingRedactionExtensions
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.Compliance.Redaction;
using Microsoft.Extensions.Compliance.Testing;
using Microsoft.Extensions.Telemetry.Enrichment.Test;
using Moq;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Telemetry.Enrichment;

namespace Microsoft.Extensions.Telemetry.Enrichment.Test;
namespace Microsoft.AspNetCore.Telemetry.RequestHeaders.Test;

public class TestLogEnrichmentPropertyBag : IEnrichmentPropertyBag
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

using System;
using System.Collections.Generic;
using Microsoft.Extensions.Telemetry.Enrichment;

namespace Microsoft.Extensions.Telemetry.Enrichment.Test;
namespace Microsoft.AspNetCore.Telemetry.Test.Enrichment.RequestHeaders.Tests;

public class TestMetricEnrichmentPropertyBag : IEnrichmentPropertyBag
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<ProjectReference Include="..\..\..\src\Libraries\Microsoft.Extensions.Telemetry.Testing\Microsoft.Extensions.Telemetry.Testing.csproj" />
<ProjectReference Include="..\..\..\src\Libraries\Microsoft.Extensions.Compliance.Testing\Microsoft.Extensions.Compliance.Testing.csproj" />
<ProjectReference Include="..\..\..\src\Libraries\Microsoft.Extensions.Compliance.Redaction\Microsoft.Extensions.Compliance.Redaction.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Telemetry.Abstractions.Tests\Microsoft.Extensions.Telemetry.Abstractions.Tests.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void ServiceCollection_GivenNullArguments_Throws()
}

[Fact]
public void ServiceCollection_AddMultipleEnrichersSuccessfully()
public void ServiceCollection_AddMultipleMetricEnrichersSuccessfully()
{
var services = new ServiceCollection();
services.AddMetricEnricher<EmptyEnricher>();
Expand All @@ -63,15 +63,53 @@ public void ServiceCollection_AddMultipleEnrichersSuccessfully()
Assert.Equal(2, enricherCount);
}

internal class EmptyEnricher : IMetricEnricher, ILogEnricher
[Fact]
public void AddLogEnricher()
{
var services = new ServiceCollection();
services.AddLogEnricher<EmptyEnricher>();
services.AddLogEnricher(new TestEnricher());

using var provider = services.BuildServiceProvider();
var enrichersCollection = provider.GetServices<ILogEnricher>();

var enricherCount = 0;
foreach (var enricher in enrichersCollection)
{
enricherCount++;
}

Assert.Equal(2, enricherCount);
}

[Fact]
public void AddStaticLogEnricher()
{
var services = new ServiceCollection();
services.AddStaticLogEnricher<EmptyEnricher>();
services.AddStaticLogEnricher(new TestEnricher());

using var provider = services.BuildServiceProvider();
var enrichersCollection = provider.GetServices<IStaticLogEnricher>();

var enricherCount = 0;
foreach (var enricher in enrichersCollection)
{
enricherCount++;
}

Assert.Equal(2, enricherCount);
}

internal class EmptyEnricher : IMetricEnricher, ILogEnricher, IStaticLogEnricher
{
public void Enrich(IEnrichmentPropertyBag enrichmentBag)
{
// intentionally left empty
}
}

internal class TestEnricher : IMetricEnricher, ILogEnricher
internal class TestEnricher : IMetricEnricher, ILogEnricher, IStaticLogEnricher
{
public void Enrich(IEnrichmentPropertyBag enrichmentBag)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public void LatencyRegistryExtension_NullArguments()
() => LatencyRegistryExtensions.RegisterTagNames(new ServiceCollection(), null!));
}

[Fact]
public void LatencyRegistryExtension_EmptyNames()
{
Assert.Throws<ArgumentException>(() => LatencyRegistryExtensions.RegisterCheckpointNames(new ServiceCollection(), ""));
Assert.Throws<ArgumentException>(() => LatencyRegistryExtensions.RegisterMeasureNames(new ServiceCollection(), ""));
Assert.Throws<ArgumentException>(() => LatencyRegistryExtensions.RegisterTagNames(new ServiceCollection(), ""));
}

[Fact]
public void LatencyRegistryExtension_BasicFunctionality()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.Telemetry.Enrichment;
using Microsoft.Extensions.Telemetry.Logging;
using Xunit;
Expand Down Expand Up @@ -34,7 +35,7 @@ public static void CollectorContract()
Assert.Empty(list);
Assert.Equal(string.Empty, list.ParameterName);

list.Add(PropName, Value);
list.Add(PropName, Value, DataClassification.None);
Assert.Single(list);
Assert.Equal(PropName, list[0].Key);
Assert.Equal(Value, list[0].Value);
Expand Down

0 comments on commit e5f9437

Please sign in to comment.