Skip to content

Commit

Permalink
BCMOHAM-16286 Logging Update: added tracking between methods
Browse files Browse the repository at this point in the history
  • Loading branch information
daveb-hni committed Mar 12, 2024
1 parent 6c2c766 commit 3085087
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Services/Common/src/Controllers/ServiceBaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected async Task<ActionResult<DocumentReference>> PharmanetRequest()

ClaimsPrincipal? user = this.HttpContext!.User;

var traceId = this.Request.Headers.TryGetValue("Kong-Request-ID", out var value) ? value.SingleOrDefault() : null;
var traceId = this.Request.Headers.TryGetValue("Kong-Request-ID", out var value) ? value.FirstOrDefault() : "";
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest. Extracted Kong-Request-ID header as the Trace ID.");

string jsonString = await this.Request.GetRawBodyStringAsync().ConfigureAwait(true);
Expand All @@ -140,6 +140,8 @@ protected async Task<ActionResult<DocumentReference>> PharmanetRequest()
return this.StatusCode((int)HttpStatusCode.BadRequest, ex.Message);
}

HL7.Dotnetcore.Segment? mshSegment = hl7v2Message.Segments("MSH").FirstOrDefault();
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Message MSH: {mshSegment?.Value}");

Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Authorizing...");
AuthorizationResult authResult = await this.authorizationService.AuthorizeAsync(
Expand All @@ -152,7 +154,7 @@ protected async Task<ActionResult<DocumentReference>> PharmanetRequest()
}
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: ServiceBaseController.PharmanetRequest: Authorization completed. Submitting request...");

RequestResult<DocumentReference> response = await this.service.SubmitRequest(fhirRequest).ConfigureAwait(true);
RequestResult<DocumentReference> response = await this.service.SubmitRequest(fhirRequest, traceId + "").ConfigureAwait(true);
if (response.IsSuccessStatusCode == false)
{
Logger.LogError(this.logger, $"An Error occurred while invoking Pharmanet endpoint: {response.ErrorMessage}");
Expand Down
3 changes: 2 additions & 1 deletion Services/Common/src/Services/IPharmanetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public interface IPharmanetService
/// Submit request of type DocumentReference containing HL7v2 message to PharmaNet.
/// </summary>
/// <param name="request">An HL7 FHIR DocumentReference request containing HL7v2 payload.</param>
/// <param name="traceId">The value used to track messages from API Gateway.</param>
/// <returns>Returns a DocumentReference response.</returns>
Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request);
Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request, string traceId);
}
}
9 changes: 5 additions & 4 deletions Services/Common/src/Services/PharmanetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ public PharmanetService(
/// Submit Request to Pharmanet.
/// </summary>
/// <param name="request">The DocumentReference to be submitted.</param>
/// <param name="traceId">The value used to track messages from API Gateway.</param>
/// <returns>Returns a DocumentReference containing the response from PharmaNet.</returns>
public async Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request)
public async Task<RequestResult<DocumentReference>> SubmitRequest(DocumentReference request, string traceId)
{
Logger.LogInformation(this.logger, $"PharmanetService.SubmitRequest start");
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: PharmanetService.SubmitRequest start");

RequestResult<DocumentReference> response = new RequestResult<DocumentReference>();
bool base64Encode = this.configuration.GetSection(PharmanetDelegateConfig.ConfigurationSectionKey).GetValue<bool>("Base64EncodeHl7Message");
Logger.LogInformation(this.logger, $"PharmanetService.SubmitRequest: UUID exists in FHIR? {request.MasterIdentifier != null} ");
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: PharmanetService.SubmitRequest: UUID exists in FHIR? {request.MasterIdentifier != null} ");
PharmanetMessageModel requestMessage = PharmanetDelegateAdapter.ToPharmanetMessageModel(request, base64Encode);
Logger.LogInformation(this.logger, $"Transaction UUID: {requestMessage.TransactionId}: PharmanetService.SubmitRequest: PharmanetMessageModel created.");
Logger.LogInformation(this.logger, $"Trace ID: {traceId}: Transaction UUID: {requestMessage.TransactionId}: PharmanetService.SubmitRequest: PharmanetMessageModel created.");

try
{
Expand Down

0 comments on commit 3085087

Please sign in to comment.