Skip to content

Commit

Permalink
Renamed methods in Patient for AB#16872.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMaki committed Jan 7, 2025
1 parent 70eccda commit 390c76b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
40 changes: 26 additions & 14 deletions Apps/Common/src/AspNetConfiguration/Modules/Observability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ public static IApplicationBuilder UseDefaultHttpRequestLogging(this IApplication
opts =>
{
opts.IncludeQueryInRequestPath = true;

// ReSharper disable once RedundantDelegateCreation
opts.GetLevel = new Func<HttpContext, double, Exception?, LogEventLevel>((httpCtx, _, exception) => ExcludePaths(httpCtx, exception, excludePaths ?? []));
opts.GetLevel = (httpCtx, _, exception) => ExcludePaths(httpCtx, exception, excludePaths ?? []);
opts.EnrichDiagnosticContext = (diagCtx, httpCtx) =>
{
diagCtx.Set("Host", httpCtx.Request.Host.Value);
Expand All @@ -106,7 +104,7 @@ public static IApplicationBuilder UseDefaultHttpRequestLogging(this IApplication
/// <param name="otlpConfig">OpenTelemetry configuration values.</param>
/// <returns>The DI container.</returns>
#pragma warning disable CA1506 //Avoid excessive class coupling
public static IServiceCollection AddOpenTelemetryDefaults(this IServiceCollection services, OpenTelemetryConfig otlpConfig) // NOSONAR
public static IServiceCollection AddOpenTelemetryDefaults(this IServiceCollection services, OpenTelemetryConfig otlpConfig)
{
if (string.IsNullOrEmpty(otlpConfig.ServiceName))
{
Expand All @@ -129,14 +127,14 @@ public static IServiceCollection AddOpenTelemetryDefaults(this IServiceCollectio
.AddAspNetCoreInstrumentation(
options =>
{
// ReSharper disable once RedundantLambdaParameterType
options.Filter = (HttpContext httpContext) => !Array.Exists(
options.Filter = httpContext => !Array.Exists(
otlpConfig.IgnorePathPrefixes,
s => httpContext.Request.Path.ToString().StartsWith(s, StringComparison.OrdinalIgnoreCase));
})
.AddRedisInstrumentation()
.AddEntityFrameworkCoreInstrumentation()
.AddNpgsql();
.AddNpgsql()
;

foreach (string source in otlpConfig.Sources)
{
Expand Down Expand Up @@ -169,7 +167,8 @@ public static IServiceCollection AddOpenTelemetryDefaults(this IServiceCollectio
builder
.AddHttpClientInstrumentation()
.AddAspNetCoreInstrumentation()
.AddRuntimeInstrumentation();
.AddRuntimeInstrumentation()
;

if (otlpConfig.MetricsConsoleExporterEnabled)
{
Expand Down Expand Up @@ -271,16 +270,29 @@ private static LogEventLevel ExcludePaths(HttpContext ctx, Exception? ex, string
return LogEventLevel.Error;
}

bool isWildcardMatch = Array.Exists(excludedPaths, path => IsWildcardMatch(ctx.Request.Path, path));
return isWildcardMatch ? LogEventLevel.Verbose : LogEventLevel.Information;
return Array.Exists(excludedPaths, path => IsWildcardMatch(ctx.Request.Path, path))
? LogEventLevel.Verbose
: LogEventLevel.Information;
}

private static bool IsWildcardMatch(PathString requestPath, string path)
{
return requestPath.HasValue &&
(path.StartsWith('*')
? requestPath.Value!.EndsWith(path.Replace("*", string.Empty, StringComparison.InvariantCultureIgnoreCase), StringComparison.InvariantCultureIgnoreCase)
: requestPath.Equals(path, StringComparison.InvariantCultureIgnoreCase));
if (!requestPath.HasValue)
{
return false;
}

if (path.EndsWith('*'))
{
return requestPath.Value!.StartsWith(path.Replace("*", string.Empty, StringComparison.InvariantCultureIgnoreCase), StringComparison.InvariantCultureIgnoreCase);
}

if (path.StartsWith('*'))
{
return requestPath.Value!.EndsWith(path.Replace("*", string.Empty, StringComparison.InvariantCultureIgnoreCase), StringComparison.InvariantCultureIgnoreCase);
}

return requestPath.Equals(path, StringComparison.InvariantCultureIgnoreCase);
}
}
}
8 changes: 4 additions & 4 deletions Apps/Patient/src/Controllers/PatientDataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public PatientDataController(IPatientDataService patientDataService)
[ProducesResponseType(StatusCodes.Status502BadGateway, Type = typeof(ProblemDetails))]
public async Task<ActionResult<PatientDataResponse>> Get(string hdid, [FromQuery] PatientDataType[] patientDataTypes, CancellationToken ct)
{
ValidateGetRequest(hdid, patientDataTypes);
ValidateRequest(hdid, patientDataTypes);
PatientDataQuery query = new(hdid, patientDataTypes);
return await this.patientDataService.QueryAsync(query, ct);
}
Expand All @@ -86,13 +86,13 @@ public async Task<ActionResult<PatientDataResponse>> Get(string hdid, [FromQuery
[ProducesResponseType(StatusCodes.Status502BadGateway, Type = typeof(ProblemDetails))]
public async Task<ActionResult<PatientFileResponse>> GetFile(string hdid, string fileId, CancellationToken ct)
{
ValidateGetFileRequest(hdid, fileId);
ValidateFileRequest(hdid, fileId);
PatientFileQuery query = new(hdid, fileId);
return await this.patientDataService.QueryAsync(query, ct) ??
throw new NotFoundException($"file {fileId} not found");
}

private static void ValidateGetRequest(string hdid, PatientDataType[] patientDataTypes)
private static void ValidateRequest(string hdid, PatientDataType[] patientDataTypes)
{
if (string.IsNullOrEmpty(hdid))
{
Expand All @@ -105,7 +105,7 @@ private static void ValidateGetRequest(string hdid, PatientDataType[] patientDat
}
}

private static void ValidateGetFileRequest(string hdid, string fileId)
private static void ValidateFileRequest(string hdid, string fileId)
{
if (string.IsNullOrEmpty(hdid))
{
Expand Down

0 comments on commit 390c76b

Please sign in to comment.