Skip to content
Merged
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
19 changes: 16 additions & 3 deletions src/external-api/Services/FhirClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http.Headers;
using Hl7.Fhir.Rest;
Expand All @@ -10,8 +11,11 @@ public interface IFhirClientFactory
}

[ExcludeFromCodeCoverage(Justification = "Cannot test third party library")]
public class FhirClientFactory(ITokenService tokenService, IConfiguration config)
: IFhirClientFactory
public class FhirClientFactory(
ILogger<FhirClientFactory> logger,
ITokenService tokenService,
IConfiguration config
) : IFhirClientFactory
{
public FhirClient CreateFhirClient()
{
Expand All @@ -26,7 +30,16 @@ public FhirClient CreateFhirClient()
"Bearer",
accessToken
);
fhirClient.RequestHeaders.Add("X-Request-ID", Guid.NewGuid().ToString());

// This traceRequestId is not sensitive and is only used for tracing between us and PDS
var pdsTraceRequestId = Guid.NewGuid().ToString();
#pragma warning disable CA1873
// Not necessary, but useful if the AddTag method is not working for some reason.
logger.LogInformation("PDS Trace Request ID: {TraceRequestId}", pdsTraceRequestId);
#pragma warning restore CA1873
// This will show on dependency logs in Application Insights and can be used to correlate requests between us and PDS
Activity.Current?.AddTag("PdsTraceRequestId", pdsTraceRequestId);
fhirClient.RequestHeaders.Add("X-Request-ID", pdsTraceRequestId);
}

return fhirClient;
Expand Down
Loading