Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -26,9 +26,8 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Correlation" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="[3.1.1,4.0.0)" />
<PackageReference Include="Arcus.Observability.Correlation" Version="[3.1.1,4.0.0)" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.23.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Arcus.Observability.Correlation;
using Arcus.Observability.Correlation;
using Arcus.Observability.Telemetry.Core;
using Microsoft.Extensions.Logging;

Expand All @@ -28,8 +28,8 @@ public class HttpCorrelationMessageHandler : DelegatingHandler
/// Thrown when the <paramref name="correlationInfoAccessor"/>, <paramref name="options"/>, or <paramref name="logger"/> is <c>null</c>.
/// </exception>
public HttpCorrelationMessageHandler(
IHttpCorrelationInfoAccessor correlationInfoAccessor,
HttpCorrelationClientOptions options,
IHttpCorrelationInfoAccessor correlationInfoAccessor,
HttpCorrelationClientOptions options,
ILogger<HttpCorrelationMessageHandler> logger)
{
_correlationInfoAccessor = correlationInfoAccessor ?? throw new ArgumentNullException(nameof(correlationInfoAccessor), "Requires a HTTP context accessor to retrieve the current HTTP correlation");
Expand All @@ -52,7 +52,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage

CorrelationInfo correlation = DetermineCorrelationInfo();
request.Headers.Add(_options.TransactionIdHeaderName, correlation.TransactionId);

using (var measurement = DurationMeasurement.Start())
{
try
Expand All @@ -64,7 +64,9 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
}
finally
{
#pragma warning disable CS0618 // Type or member is obsolete
_logger.LogHttpDependency(request, statusCode, measurement, dependencyId, _options.TelemetryContext);
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Expand All @@ -75,8 +77,8 @@ private CorrelationInfo DetermineCorrelationInfo()
if (correlation is null)
{
throw new InvalidOperationException(
"Cannot enrich the HTTP request with HTTP correlation because no HTTP correlation was registered in the application, "
+ "make sure that you register the HTTP correlation services with 'services.AddHttpCorrelation()' "
"Cannot enrich the HTTP request with HTTP correlation because no HTTP correlation was registered in the application, "
+ "make sure that you register the HTTP correlation services with 'services.AddHttpCorrelation()' "
+ "and that you use the HTTP correlation middleware 'app.UseHttpCorrelation()' in API scenario's");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Arcus.Observability.Correlation;
using Arcus.Observability.Telemetry.Core;
using Arcus.WebApi.Logging.Core.Correlation;
Expand Down Expand Up @@ -114,9 +114,9 @@ public static async Task<HttpResponseMessage> SendAsync(
/// Thrown when the <paramref name="client"/>, <paramref name="request"/>, <paramref name="correlationInfo"/>, <paramref name="logger"/> is <c>null</c>.
/// </exception>
public static async Task<HttpResponseMessage> SendAsync(
this HttpClient client,
HttpRequestMessage request,
CorrelationInfo correlationInfo,
this HttpClient client,
HttpRequestMessage request,
CorrelationInfo correlationInfo,
ILogger logger,
Action<HttpCorrelationClientOptions> configureOptions)
{
Expand Down Expand Up @@ -159,8 +159,10 @@ public static async Task<HttpResponseMessage> SendAsync(
}
finally
{
#pragma warning disable CS0618 // Type or member is obsolete
logger.LogHttpDependency(request, statusCode, measurement, dependencyId, options.TelemetryContext);
}
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/Arcus.WebApi.Logging/Arcus.WebApi.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.AspNetCore" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Correlation" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Arcus.Observability.Correlation" Version="[3.1.1,4.0.0)" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="[3.1.1,4.0.0)" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
</ItemGroup>

Expand Down
12 changes: 9 additions & 3 deletions src/Arcus.WebApi.Logging/RequestTrackingMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Arcus.Observability.Telemetry.Core;
using Arcus.Observability.Telemetry.Core.Logging;
using Arcus.WebApi.Logging.Core.RequestTracking;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand Down Expand Up @@ -173,7 +174,7 @@ private async Task TrackRequest(HttpContext httpContext, Exclude attributeExclud
if (AllowedToTrackStatusCode(httpContext.Response.StatusCode, attributeTrackedStatusCodes, _logger))
{
string responseBody = await GetPotentialResponseBodyAsync(httpContext, includeResponseBody);

LogRequest(requestBody, responseBody, httpContext, duration);
}

Expand Down Expand Up @@ -228,7 +229,12 @@ private void LogRequest(string requestBody, string responseBody, HttpContext htt

var operationName = DetermineRequestOperationName(httpContext);

_logger.LogRequest(httpContext.Request, httpContext.Response, operationName, duration, telemetryContext);
var request = httpContext.Request;
_logger.LogWarning(MessageFormats.RequestFormat,
#pragma warning disable CS0618 // Type or member is obsolete
RequestLogEntry.CreateForHttpRequest(
#pragma warning restore CS0618 // Type or member is obsolete
request.Method, request.Scheme, request.Host.ToString(), request.Path, operationName, httpContext.Response.StatusCode, duration.StartTime, duration.Elapsed, telemetryContext));
}

private static string DetermineRequestOperationName(HttpContext httpContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights" Version="3.0.0" />
<PackageReference Include="Arcus.Security.Core" Version="2.0.0" />
<PackageReference Include="Arcus.Testing.Logging" Version="0.4.0" />
<PackageReference Include="Arcus.Testing.Security.Providers.InMemory" Version="0.4.0" />
Expand Down
Loading