Skip to content

Commit

Permalink
Update $convert-data error log (#3859)
Browse files Browse the repository at this point in the history
* Update log error message for exceptions to only log exception type, code and stack trace.

* nit

* fix UT
  • Loading branch information
pallar-ms committed May 17, 2024
1 parent d0bf2b4 commit 81cd22e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,7 @@ private string GetConvertDataResult(ConvertDataRequest convertRequest, ITemplate
throw new ConvertDataTimeoutException(Core.Resources.ConvertDataOperationTimeout, convertException.InnerException);
}

if (convertException is PostprocessException)
{
_logger.LogInformation($"An exception of type {convertException.GetType()} occurred during postprocessing. {convertException.StackTrace}", "Convert data failed.");
}
else
{
_logger.LogInformation(convertException, "Convert data failed.");
}

_logger.LogError($"Convert data failed. An exception of type {convertException.GetType()} occurred with error code - {convertException.FhirConverterErrorCode}. {convertException.StackTrace}");
throw new ConvertDataFailedException(string.Format(Core.Resources.ConvertDataFailed, convertException.Message), convertException);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,16 @@ public async Task GivenFhirTemplateNotInJsonFormat_WhenConvert_ExceptionShouldBe

var request = GetFhirRequestWithDefaultTemplates();
var exception = await Assert.ThrowsAsync<ConvertDataFailedException>(() => convertEngine.Process(request, CancellationToken.None));
Assert.True(exception.InnerException is PostprocessException);
var fhirConverterException = exception.InnerException as FhirConverterException;
Assert.True(fhirConverterException is PostprocessException);

logger
.Received()
.Log(LogLevel.Information, Arg.Any<string>());
.Log(LogLevel.Error, Arg.Is<string>(s => s.Equals($"Convert data failed. An exception of type {fhirConverterException.GetType()} occurred with error code - {fhirConverterException.FhirConverterErrorCode}. {fhirConverterException.StackTrace}")), Arg.Is<FhirConverterException>(e => e == null));

logger
.DidNotReceive()
.Log(LogLevel.Information, Arg.Any<string>(), Arg.Is<PostprocessException>(e => e != null));
.Log(Arg.Any<LogLevel>(), Arg.Any<string>(), Arg.Is<FhirConverterException>(e => e != null));
}

private static ConvertDataRequest GetHl7V2RequestWithDefaultTemplates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Health.Fhir.Shared.Core.UnitTests.Features.Operations.Conver
public abstract class MockLogger<T> : ILogger<T>
{
void ILogger.Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
=> Log(logLevel, formatter(state, exception));
=> Log(logLevel, formatter(state, exception), exception);

public abstract void Log(LogLevel logLevel, object state, Exception exception = null);

Expand Down

0 comments on commit 81cd22e

Please sign in to comment.