Skip to content

Commit

Permalink
chore: remove obsolete built-in telemetry extensions (#553)
Browse files Browse the repository at this point in the history
* chore: remove obsolete built-in telemetry extensions

* pr-fix: telemetry type filter integration tests
  • Loading branch information
stijnmoreels committed Nov 20, 2023
1 parent feb3e5f commit f663587
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 1,019 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,6 @@ namespace Microsoft.Extensions.Logging
// ReSharper disable once InconsistentNaming
public static partial class ILoggerExtensions
{
/// <summary>
/// Logs a dependency.
/// </summary>
/// <param name="logger">The logger to track the telemetry.</param>
/// <param name="dependencyType">Custom type of dependency</param>
/// <param name="dependencyData">Custom data of dependency</param>
/// <param name="isSuccessful">Indication whether or not the operation was successful</param>
/// <param name="measurement">Measuring the latency to call the dependency</param>
/// <param name="context">Context that provides more insights on the dependency that was measured</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="logger"/>, <paramref name="dependencyData"/>, <paramref name="measurement"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="dependencyData"/> is blank.</exception>
[Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")]
public static void LogDependency(
this ILogger logger,
string dependencyType,
object dependencyData,
bool isSuccessful,
DependencyMeasurement measurement,
Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency");
Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency");
Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency");

LogDependency(logger, dependencyType, dependencyData, isSuccessful, measurement.StartTime, measurement.Elapsed, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
Expand Down Expand Up @@ -103,38 +73,6 @@ public static partial class ILoggerExtensions
LogDependency(logger, dependencyType, dependencyData, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
/// <param name="logger">The logger to track the telemetry.</param>
/// <param name="dependencyType">Custom type of dependency</param>
/// <param name="dependencyData">Custom data of dependency</param>
/// <param name="isSuccessful">Indication whether or not the operation was successful</param>
/// <param name="dependencyName">The name of the dependency</param>
/// <param name="measurement">Measuring the latency to call the dependency</param>
/// <param name="context">Context that provides more insights on the dependency that was measured</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="logger"/>, <paramref name="dependencyData"/>, <paramref name="measurement"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="dependencyData"/> is blank.</exception>
[Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")]
public static void LogDependency(
this ILogger logger,
string dependencyType,
object dependencyData,
bool isSuccessful,
string dependencyName,
DependencyMeasurement measurement,
Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency");
Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency");
Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency");

LogDependency(logger, dependencyType, dependencyData, isSuccessful, dependencyName, measurement.StartTime, measurement.Elapsed, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
Expand Down Expand Up @@ -335,38 +273,6 @@ public static partial class ILoggerExtensions
LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful, dependencyName, startTime, duration, dependencyId, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
/// <param name="logger">The logger to track the telemetry.</param>
/// <param name="dependencyType">Custom type of dependency</param>
/// <param name="dependencyData">Custom data of dependency</param>
/// <param name="targetName">Name of the dependency target</param>
/// <param name="isSuccessful">Indication whether or not the operation was successful</param>
/// <param name="measurement">Measuring the latency to call the dependency</param>
/// <param name="context">Context that provides more insights on the dependency that was measured</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="logger"/>, <paramref name="dependencyData"/>, <paramref name="measurement"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="dependencyData"/> is blank.</exception>
[Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")]
public static void LogDependency(
this ILogger logger,
string dependencyType,
object dependencyData,
string targetName,
bool isSuccessful,
DependencyMeasurement measurement,
Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency");
Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency");
Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency");

LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, measurement.StartTime, measurement.Elapsed, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
Expand Down Expand Up @@ -431,40 +337,6 @@ public static partial class ILoggerExtensions
LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
/// <param name="logger">The logger to track the telemetry.</param>
/// <param name="dependencyType">Custom type of dependency</param>
/// <param name="dependencyData">Custom data of dependency</param>
/// <param name="targetName">Name of the dependency target</param>
/// <param name="isSuccessful">Indication whether or not the operation was successful</param>
/// <param name="dependencyName">The name of the dependency</param>
/// <param name="measurement">Measuring the latency to call the dependency</param>
/// <param name="context">Context that provides more insights on the dependency that was measured</param>
/// <exception cref="ArgumentNullException">
/// Thrown when the <paramref name="logger"/>, <paramref name="dependencyData"/>, <paramref name="measurement"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="dependencyData"/> is blank.</exception>
[Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")]
public static void LogDependency(
this ILogger logger,
string dependencyType,
object dependencyData,
string targetName,
bool isSuccessful,
string dependencyName,
DependencyMeasurement measurement,
Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency");
Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency");
Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency");

LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement.StartTime, measurement.Elapsed, context);
}

/// <summary>
/// Logs a dependency.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,5 @@ public static void LogCustomEvent(this ILogger logger, string name, Dictionary<s

logger.LogWarning(MessageFormats.EventFormat, new EventLogEntry(name, context));
}

/// <summary>
/// Logs a custom event
/// </summary>
/// <param name="logger">The logger to track the telemetry.</param>
/// <param name="name">Name of the event</param>
/// <param name="context">Context that provides more insights on the event that occurred</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="logger"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="name"/> is blank.</exception>
[Obsolete("Use " + nameof(LogCustomEvent) + " instead")]
public static void LogEvent(this ILogger logger, string name, Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(name, nameof(name), "Requires a non-blank event name to track an custom event");

context = context ?? new Dictionary<string, object>();

logger.LogWarning(MessageFormats.EventFormat, new EventLogEntry(name, context));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@ namespace Microsoft.Extensions.Logging
// ReSharper disable once InconsistentNaming
public static partial class ILoggerExtensions
{
/// <summary>
/// Logs an HTTP dependency
/// </summary>
/// <param name="logger">The logger to track the telemetry.</param>
/// <param name="request">The request that started the HTTP communication.</param>
/// <param name="statusCode">The status code that was returned by the service for this HTTP communication.</param>
/// <param name="measurement">The measuring the latency of the HTTP dependency.</param>
/// <param name="context">The context that provides more insights on the dependency that was measured.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="logger"/>, <paramref name="request"/>, or <paramref name="measurement"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">
/// Thrown when the <paramref name="request"/> doesn't have a request URI or HTTP method, the <paramref name="statusCode"/> is outside 100-599 range inclusively.
/// </exception>
[Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a HTTP dependency")]
public static void LogHttpDependency(
this ILogger logger,
HttpRequestMessage request,
HttpStatusCode statusCode,
DependencyMeasurement measurement,
Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNull(request, nameof(request), "Requires a HTTP request message to track a HTTP dependency");
Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the HTTP communication when tracking a HTTP dependency");

LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, context);
}

/// <summary>
/// Logs an HTTP dependency.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ public static void LogCustomMetric(this ILogger logger, string name, double valu
LogCustomMetric(logger, name, value, DateTimeOffset.UtcNow, context);
}

/// <summary>
/// Logs a custom metric
/// </summary>
/// <param name="logger">The logger to track the metric.</param>
/// <param name="name">Name of the metric</param>
/// <param name="value">Value of the metric</param>
/// <param name="context">Context that provides more insights on the event that occurred</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="logger"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="name"/> is blank.</exception>
[Obsolete("Use " + nameof(LogCustomMetric) + " instead")]
public static void LogMetric(this ILogger logger, string name, double value, Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(name, nameof(name), "Requires a non-blank name to track a metric");

context = context ?? new Dictionary<string, object>();

LogMetric(logger, name, value, DateTimeOffset.UtcNow, context);
}

/// <summary>
/// Logs a custom metric
/// </summary>
Expand All @@ -69,26 +49,5 @@ public static void LogCustomMetric(this ILogger logger, string name, double valu

logger.LogWarning(MessageFormats.MetricFormat, new MetricLogEntry(name, value, timestamp, context));
}

/// <summary>
/// Logs a custom metric
/// </summary>
/// <param name="logger">The logger to track the metric.</param>
/// <param name="name">Name of the metric</param>
/// <param name="value">Value of the metric</param>
/// <param name="timestamp">Timestamp of the metric</param>
/// <param name="context">Context that provides more insights on the event that occurred</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="logger"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">Thrown when the <paramref name="name"/> is blank.</exception>
[Obsolete("Use " + nameof(LogCustomMetric) + " instead")]
public static void LogMetric(this ILogger logger, string name, double value, DateTimeOffset timestamp, Dictionary<string, object> context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
Guard.NotNullOrWhitespace(name, nameof(name), "Requires a non-blank name to track a metric");

context = context ?? new Dictionary<string, object>();

logger.LogWarning(MessageFormats.MetricFormat, new MetricLogEntry(name, value, timestamp, context));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Arcus.Observability.Correlation;
using Arcus.Observability.Telemetry.Core;
using Arcus.Observability.Telemetry.Core.Logging;
using Arcus.Observability.Telemetry.Serilog.Enrichers;
using Arcus.Observability.Tests.Core;
using Microsoft.Azure.ApplicationInsights.Query;
using Microsoft.Azure.ApplicationInsights.Query.Models;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using Xunit;
using Xunit.Abstractions;
using ILogger = Microsoft.Extensions.Logging.ILogger;

namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights
{
Expand All @@ -24,24 +19,6 @@ public EventTests(ITestOutputHelper outputWriter) : base(outputWriter)
{
}

[Fact]
public async Task LogEvent_SinksToApplicationInsights_ResultsInEventTelemetry()
{
// Arrange
string eventName = BogusGenerator.Finance.AccountName();
Dictionary<string, object> telemetryContext = CreateTestTelemetryContext();

// Act
Logger.LogEvent(eventName, telemetryContext);

// Assert
await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client =>
{
EventsCustomEventResult[] results = await client.GetEventsAsync();
Assert.Contains(results, result => result.CustomEvent.Name == eventName);
});
}

[Fact]
public async Task LogCustomEvent_SinksToApplicationInsights_ResultsInEventTelemetry()
{
Expand Down Expand Up @@ -79,29 +56,6 @@ public async Task LogEventWithComponentName_SinksToApplicationInsights_ResultsIn
});
}

[Fact]
public async Task LogEventWithVersion_SinksToApplicationInsights_ResultsInTelemetryWithVersion()
{
// Arrange
var eventName = "Update version";
LoggerConfiguration.Enrich.WithVersion();

// Act
Logger.LogEvent(eventName);

// Assert
await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client=>
{
EventsCustomEventResult[] events = await client.GetEventsAsync();
Assert.Contains(events, ev =>
{
return ev.CustomEvent.Name == eventName
&& ev.CustomDimensions.TryGetValue(VersionEnricher.DefaultPropertyName, out string actualVersion)
&& !String.IsNullOrWhiteSpace(actualVersion);
});
});
}

[Fact]
public async Task LogCustomEventWithVersion_SinksToApplicationInsights_ResultsInTelemetryWithVersion()
{
Expand Down
Loading

0 comments on commit f663587

Please sign in to comment.