Skip to content

Commit a8af39b

Browse files
committed
Better log with QuestionPipeline throws.
1 parent 602ffbc commit a8af39b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/KernelMemory.Extensions.ConsoleTest/Samples/CustomSearchPipelineBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task RunSample2()
4646
{
4747
services.ConfigureCohereRerank(rerankApiKey);
4848
}
49-
49+
5050
services.AddHttpClient<RawCohereChatClient>()
5151
.AddStandardResilienceHandler(options =>
5252
{

src/KernelMemory.Extensions/QueryPipeline/UserQuestionPipeline.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using KernelMemory.Extensions.QueryPipeline;
2+
using Microsoft.Extensions.Logging;
3+
using Microsoft.KernelMemory.Diagnostics;
24
using System;
35
using System.Collections.Generic;
46
using System.Runtime.CompilerServices;
@@ -13,6 +15,12 @@ public class UserQuestionPipeline
1315

1416
private IReRanker _reRanker = new BaseReRanker();
1517
private IConversationQueryRewriter? _conversationQueryRewriter;
18+
private ILogger<UserQuestionPipeline> _log;
19+
20+
public UserQuestionPipeline(ILogger<UserQuestionPipeline>? log = null)
21+
{
22+
_log = log ?? DefaultLogger<UserQuestionPipeline>.Instance;
23+
}
1624

1725
public UserQuestionPipeline AddHandler(IQueryHandler queryHandler)
1826
{
@@ -96,11 +104,13 @@ public async Task ExecuteQuery(UserQuestion userQuestion, CancellationToken canc
96104
//Execute the handler and verify if the question has been answered.
97105
try
98106
{
107+
_log.LogDebug("Executing handler {handler}", handler.GetType().Name);
99108
await handler.HandleAsync(userQuestion, cancellationToken);
100109
}
101110
catch (Exception ex)
102111
{
103112
userQuestion.Errors = $"Exception in handler {handler.GetType().FullName} - {ex}";
113+
_log.LogError(ex, "Exception in handler {0}", handler.GetType().FullName);
104114
break;
105115
}
106116

0 commit comments

Comments
 (0)