Skip to content

Commit

Permalink
pr-remove: remaining obsolete types
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnmoreels committed Apr 11, 2023
1 parent a78cd3f commit 5363199
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,7 @@ public static IServiceCollection AddHttpCorrelation(this IFunctionsHostBuilder b
{
Guard.NotNull(builder, nameof(builder), "Requires a function host builder instance to add the HTTP correlation services");

return AddHttpCorrelation(builder, (HttpCorrelationInfoOptions options) => { });
}

/// <summary>
/// Adds operation and transaction correlation to the application.
/// </summary>
/// <param name="builder">The functions host builder containing the dependency injection services.</param>
/// <param name="configureOptions">The function to configure additional options how the correlation works.</param>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="builder"/> is <c>null</c>.</exception>
[Obsolete("Use the " + nameof(AddHttpCorrelation) + " method overload with the " + nameof(HttpCorrelationInfoOptions) + " instead")]
public static IServiceCollection AddHttpCorrelation(this IFunctionsHostBuilder builder, Action<CorrelationInfoOptions> configureOptions)
{
Guard.NotNull(builder, nameof(builder), "Requires a functions host builder instance to add the HTTP correlation services");

IServiceCollection services = builder.Services;
services.AddHttpContextAccessor();
services.AddCorrelation(
serviceProvider => (HttpCorrelationInfoAccessor) serviceProvider.GetRequiredService<IHttpCorrelationInfoAccessor>(),
configureOptions);
services.AddScoped<IHttpCorrelationInfoAccessor>(serviceProvider =>
{
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
return new HttpCorrelationInfoAccessor(httpContextAccessor);
});
services.AddScoped(serviceProvider =>
{
var options = serviceProvider.GetRequiredService<IOptions<CorrelationInfoOptions>>();
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
var correlationInfoAccessor = serviceProvider.GetRequiredService<IHttpCorrelationInfoAccessor>();
var logger = serviceProvider.GetService<ILogger<HttpCorrelation>>();

return new HttpCorrelation(options, httpContextAccessor, correlationInfoAccessor, logger);
});

return services;
return AddHttpCorrelation(builder, options => { });
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class CorrelationInfoUpstreamServiceOptions
private Func<string> _generateId = () => Guid.NewGuid().ToString();

/// <summary>
/// Gets or sets the flag indicating whether or not the upstream service information should be extracted from the <see cref="OperationParentIdHeaderName"/> following the W3C Trace-Context standard.
/// Gets or sets the flag indicating whether or not the upstream service information should be extracted from the <see cref="HeaderName"/> following the W3C Trace-Context standard.
/// </summary>
/// <remarks>
/// This is only used when the <see cref="HttpCorrelationInfoOptions.Format"/> is set to <see cref="HttpCorrelationFormat.Hierarchical"/>.
Expand All @@ -29,21 +29,6 @@ public class CorrelationInfoUpstreamServiceOptions
/// </remarks>
public bool IncludeInResponse { get; set; } = true;

/// <summary>
/// Gets or sets the request header name where te operation parent ID is located (default: <c>"Request-Id"</c>).
/// </summary>
/// <exception cref="ArgumentException">Thrown when the <paramref name="value"/> is blank.</exception>
[Obsolete("Use '" + nameof(HeaderName) + "' instead")]
public string OperationParentIdHeaderName
{
get => _headerName;
set
{
Guard.NotNullOrWhitespace(value, nameof(value), "Requires a non-blank value for the operation parent ID request header name");
_headerName = value;
}
}

/// <summary>
/// Gets or sets the request header name where te operation parent ID is located (default: <c>"Request-Id"</c>).
/// </summary>
Expand Down
145 changes: 5 additions & 140 deletions src/Arcus.WebApi.Logging.Core/Correlation/HttpCorrelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,121 +37,21 @@ public HttpCorrelation(
IHttpContextAccessor httpContextAccessor,
IHttpCorrelationInfoAccessor correlationInfoAccessor,
ILogger<HttpCorrelation> logger)
#pragma warning disable CS0618 // Until we can remove the other constructor.
: this(options, httpContextAccessor, (ICorrelationInfoAccessor<CorrelationInfo>) correlationInfoAccessor, logger)
#pragma warning restore CS0618
: base(options?.Value ?? new HttpCorrelationInfoOptions(), correlationInfoAccessor, logger)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="HttpCorrelation"/> class.
/// </summary>
/// <param name="options">The options controlling how the correlation should happen.</param>
/// <param name="correlationInfoAccessor">The instance to set and retrieve the <see cref="CorrelationInfo"/> instance.</param>
/// <param name="logger">The logger to trace diagnostic messages during the correlation.</param>
/// <param name="httpContextAccessor">The instance to have access to the current HTTP context.</param>
/// <exception cref="ArgumentNullException">When any of the parameters are <c>null</c>.</exception>
/// <exception cref="ArgumentException">When the <paramref name="options"/> doesn't contain a non-<c>null</c> <see cref="IOptions{TOptions}.Value"/></exception>
[Obsolete("Use the constructor overload with the " + nameof(IHttpCorrelationInfoAccessor) + " instead")]
public HttpCorrelation(
IOptions<HttpCorrelationInfoOptions> options,
IHttpContextAccessor httpContextAccessor,
ICorrelationInfoAccessor<CorrelationInfo> correlationInfoAccessor,
ILogger<HttpCorrelation> logger)
: base(options?.Value, new HttpCorrelationInfoAccessorProxy(correlationInfoAccessor), logger)
{
Guard.NotNull(options, nameof(options), "Requires a set of options to configure the correlation process");
Guard.NotNull(httpContextAccessor, nameof(httpContextAccessor), "Requires a HTTP context accessor to get the current HTTP context");
Guard.NotNull(correlationInfoAccessor, nameof(correlationInfoAccessor), "Requires a correlation info instance to set and retrieve the correlation information");
Guard.NotNull(options.Value, nameof(options.Value), "Requires a value in the set of options to configure the correlation process");

options ??= Options.Create(new HttpCorrelationInfoOptions());
Guard.NotNull(options, nameof(options), "Requires a value in the set of options to configure the correlation process");
Guard.NotNull(options.Value, nameof(options), "Requires a value in the set of options to configure the correlation process");

_httpContextAccessor = httpContextAccessor;
_options = options.Value;
_correlationInfoAccessor = correlationInfoAccessor;
_logger = logger ?? NullLogger<HttpCorrelation>.Instance;
}

private class HttpCorrelationInfoAccessorProxy : IHttpCorrelationInfoAccessor
{
private readonly ICorrelationInfoAccessor<CorrelationInfo> _accessor;

public HttpCorrelationInfoAccessorProxy(ICorrelationInfoAccessor<CorrelationInfo> accessor)
{
Guard.NotNull(accessor, nameof(accessor), "Requires a correlation info instance to set and retrieve the correlation information");
_accessor = accessor;
}

public CorrelationInfo GetCorrelationInfo()
{
return _accessor.GetCorrelationInfo();
}

public void SetCorrelationInfo(CorrelationInfo correlationInfo)
{
_accessor.SetCorrelationInfo(correlationInfo);
}
}

/// <summary>
/// Initializes a new instance of the <see cref="HttpCorrelation"/> class.
/// </summary>
/// <param name="options">The options controlling how the correlation should happen.</param>
/// <param name="correlationInfoAccessor">The instance to set and retrieve the <see cref="CorrelationInfo"/> instance.</param>
/// <param name="logger">The logger to trace diagnostic messages during the correlation.</param>
/// <param name="httpContextAccessor">The instance to have access to the current HTTP context.</param>
/// <exception cref="ArgumentNullException">When any of the parameters are <c>null</c>.</exception>
/// <exception cref="ArgumentException">When the <paramref name="options"/> doesn't contain a non-<c>null</c> <see cref="IOptions{TOptions}.Value"/></exception>
[Obsolete("Use the constructor overload with the " + nameof(HttpCorrelationInfoOptions) + " instead")]
public HttpCorrelation(
IOptions<CorrelationInfoOptions> options,
IHttpContextAccessor httpContextAccessor,
ICorrelationInfoAccessor<CorrelationInfo> correlationInfoAccessor,
ILogger<HttpCorrelation> logger)
: this(Microsoft.Extensions.Options.Options.Create(CreateHttpCorrelationOptions(options?.Value)), httpContextAccessor, correlationInfoAccessor, logger)
{
}

[Obsolete]
private static HttpCorrelationInfoOptions CreateHttpCorrelationOptions(CorrelationInfoOptions options)
{
if (options is null)
{
return new HttpCorrelationInfoOptions();
}

var httpOptions = new HttpCorrelationInfoOptions
{
Format = HttpCorrelationFormat.Hierarchical,
Operation =
{
GenerateId = options.Operation.GenerateId,
IncludeInResponse = options.Operation.IncludeInResponse
},
Transaction =
{
GenerateId = options.Transaction.GenerateId,
HeaderName = options.Transaction.HeaderName,
IncludeInResponse = options.Transaction.IncludeInResponse,
AllowInRequest = options.Transaction.AllowInRequest,
GenerateWhenNotSpecified = options.Transaction.GenerateWhenNotSpecified
},
UpstreamService =
{
GenerateId = options.OperationParent.GenerateId,
ExtractFromRequest = options.OperationParent.ExtractFromRequest,
HeaderName = options.OperationParent.OperationParentIdHeaderName
}
};

var oldDefaultOperationIdHeader = "RequestId";
if (options.Operation.HeaderName != oldDefaultOperationIdHeader)
{
httpOptions.Operation.HeaderName = options.Operation.HeaderName;
}

return httpOptions;
}

/// <summary>
/// Gets the current correlation information initialized in this context.
/// </summary>
Expand All @@ -171,41 +71,6 @@ public void SetCorrelationInfo(CorrelationInfo correlationInfo)
_correlationInfoAccessor.SetCorrelationInfo(correlationInfo);
}

/// <summary>
/// Correlate the current HTTP request according to the previously configured <see cref="CorrelationInfoOptions"/>;
/// returning an <paramref name="errorMessage"/> when the correlation failed.
/// </summary>
/// <param name="errorMessage">The failure message that describes why the correlation of the HTTP request wasn't successful.</param>
/// <returns>
/// <para>[true] when the HTTP request was successfully correlated and the HTTP response was altered accordingly;</para>
/// <para>[false] there was a problem with the correlation, describing the failure in the <paramref name="errorMessage"/>.</para>
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when the given <see cref="HttpContext"/> is not available to correlate the request with the response.</exception>
/// <exception cref="ArgumentException">Thrown when the given <see cref="HttpContext"/> doesn't have any response headers to set the correlation headers.</exception>
[Obsolete("Use the " + nameof(CorrelateHttpRequest) + " instead which let's you decide the current scope of the received HTTP request in which additional dependencies should be tracked")]
public bool TryHttpCorrelate(out string errorMessage)
{
HttpContext httpContext = _httpContextAccessor.HttpContext;

Guard.NotNull(httpContext, nameof(httpContext), "Requires a HTTP context from the HTTP context accessor to start correlating the HTTP request");
Guard.For<ArgumentException>(() => httpContext.Response is null, "Requires a 'Response'");
Guard.For<ArgumentException>(() => httpContext.Response.Headers is null, "Requires a 'Response' object with headers");

using (HttpCorrelationResult result = TrySettingCorrelationFromRequest(httpContext.Request, httpContext.TraceIdentifier))
{
if (result.IsSuccess)
{
AddCorrelationResponseHeaders(httpContext, result.RequestId);

errorMessage = null;
return true;
}

errorMessage = result.ErrorMessage;
return false;
}
}

/// <summary>
/// Correlate the current HTTP request according to the previously configured <see cref="CorrelationInfoOptions"/>;
/// returning an <see cref="HttpCorrelationResult"/> which acts as the current scope in which additional dependencies should be tracked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public async Task SendRequest_WithCorrelateOptionsUpstreamServiceCustomOperation
{
opt.Format = HttpCorrelationFormat.Hierarchical;
opt.UpstreamService.ExtractFromRequest = extractFromRequest;
opt.UpstreamService.OperationParentIdHeaderName = operationParentIdHeaderName;
opt.UpstreamService.HeaderName = operationParentIdHeaderName;
}))
.PreConfigure(app => app.UseHttpCorrelation());

Expand Down
1 change: 0 additions & 1 deletion src/Arcus.WebApi.Tests.Unit/Arcus.WebApi.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
<DocumentationFile>Arcus.WebApi.Tests.Unit.Open-Api.xml</DocumentationFile>
<NoWarn>CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 5363199

Please sign in to comment.