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

feat: LogHttpDependency() should allow status codes within 100-599 range #515

Merged
merged 5 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static void LogHttpDependency(
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");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
stijnmoreels marked this conversation as resolved.
Show resolved Hide resolved
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, context);
}
Expand Down Expand Up @@ -71,8 +71,8 @@ public static void LogHttpDependency(
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");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, dependencyId, context);
}
Expand Down Expand Up @@ -102,8 +102,8 @@ public static void LogHttpDependency(
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.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP dependency operation");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

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

Expand Down Expand Up @@ -137,8 +137,8 @@ public static void LogHttpDependency(
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.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP dependency operation");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static void LogHttpDependency(
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");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, context);
}
Expand All @@ -66,8 +66,8 @@ public static void LogHttpDependency(
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");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, context);
}
Expand Down Expand Up @@ -96,8 +96,8 @@ public static void LogHttpDependency(
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");
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, dependencyId, context);
}
Expand Down Expand Up @@ -129,8 +129,8 @@ public static void LogHttpDependency(
Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP dependency operation");
Guard.For(() => request.RequestUri is null, new ArgumentException("Requires a HTTP request URI to track a HTTP dependency", nameof(request)));
Guard.For(() => request.Method is null, new ArgumentException("Requires a HTTP request method to track a HTTP dependency", nameof(request)));
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

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

Expand Down Expand Up @@ -166,8 +166,8 @@ public static void LogHttpDependency(
Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP dependency operation");
Guard.For(() => request.RequestUri is null, new ArgumentException("Requires a HTTP request URI to track a HTTP dependency", nameof(request)));
Guard.For(() => request.Method is null, new ArgumentException("Requires a HTTP request method to track a HTTP dependency", nameof(request)));
Guard.For(() => !Enum.IsDefined(typeof(HttpStatusCode), statusCode),
new ArgumentException("Requires a response HTTP status code that's within the bound of the enumeration to track a HTTP dependency"));
Guard.NotLessThan((int)statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");
Guard.NotGreaterThan((int)statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive");

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

Expand All @@ -185,7 +185,7 @@ public static void LogHttpDependency(
duration: duration,
startTime: startTime,
dependencyId: dependencyId,
resultCode: (int) statusCode,
resultCode: (int)statusCode,
isSuccessful: isSuccessful,
context: context));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Xunit;
using Xunit.Abstractions;

namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights
namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights
{
public class HttpDependencyTests : ApplicationInsightsSinkTests
{
Expand All @@ -38,7 +38,7 @@ public async Task LogHttpDependencyWithRequestMessageWithCorrelation_SinksToAppl
string dependencyId = BogusGenerator.Random.Word();

HttpRequestMessage request = CreateHttpRequestMessage(httpMethod, requestUrl);
var statusCode = BogusGenerator.PickRandom<HttpStatusCode>();
var statusCode = (HttpStatusCode)BogusGenerator.Random.Int(100, 599);
DateTimeOffset startTime = DateTimeOffset.Now;
TimeSpan duration = BogusGenerator.Date.Timespan();
Dictionary<string, object> telemetryContext = CreateTestTelemetryContext();
Expand Down Expand Up @@ -77,7 +77,7 @@ public async Task LogHttpDependencyWithRequestMessage_SinksToApplicationInsights
string dependencyId = BogusGenerator.Random.Word();

HttpRequestMessage request = CreateHttpRequestMessage(httpMethod, requestUrl);
var statusCode = BogusGenerator.PickRandom<HttpStatusCode>();
var statusCode = (HttpStatusCode)BogusGenerator.Random.Int(100, 599);
DateTimeOffset startTime = DateTimeOffset.Now;
TimeSpan duration = BogusGenerator.Date.Timespan();
Dictionary<string, object> telemetryContext = CreateTestTelemetryContext();
Expand Down Expand Up @@ -117,8 +117,8 @@ public async Task LogHttpDependencyWithRequest_SinksToApplicationInsights_Result
HttpMethod httpMethod = GenerateHttpMethod();
HttpRequest request = CreateHttpRequest(httpMethod, "arcus.test", "/integration", "https");
string dependencyId = BogusGenerator.Random.Guid().ToString();
var statusCode = BogusGenerator.PickRandom<HttpStatusCode>();

var statusCode = (HttpStatusCode)BogusGenerator.Random.Int(100, 599);
DateTimeOffset startTime = DateTimeOffset.Now;
var duration = BogusGenerator.Date.Timespan();
Dictionary<string, object> telemetryContext = CreateTestTelemetryContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void LogHttpDependency_WithTelemetryTypeFilter_IgnoresHttpDependency()
{
// Arrange
var request = new HttpRequestMessage(HttpMethod.Get, _bogusGenerator.Internet.UrlWithPath());
var statusCode = _bogusGenerator.PickRandom<HttpStatusCode>();
var statusCode = (HttpStatusCode)_bogusGenerator.Random.Int(100, 599);
DateTimeOffset startTime = _bogusGenerator.Date.PastOffset();
TimeSpan duration = _bogusGenerator.Date.Timespan();
string propertyName = _bogusGenerator.Random.Word();
Expand Down Expand Up @@ -535,7 +535,7 @@ public void LogHttpDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_Do
{
// Arrange
var request = new HttpRequestMessage(HttpMethod.Get, _bogusGenerator.Internet.UrlWithPath());
var statusCode = _bogusGenerator.PickRandom<HttpStatusCode>();
var statusCode = (HttpStatusCode)_bogusGenerator.Random.Int(100, 599);
DateTimeOffset startTime = _bogusGenerator.Date.PastOffset();
TimeSpan duration = _bogusGenerator.Date.Timespan();
string propertyName = _bogusGenerator.Random.Word();
Expand Down
Loading