.net - Service Fabric QoS 日志记录
问题描述
我有一个微服务应用程序,我想在其中记录服务质量 (QoS) 日志 - 每个服务调用一个日志行,无论服务调用是什么。我还希望每个呼叫都有详细的呼叫,这些呼叫在 QoS 日志和详细日志中具有相同的 ID。
我不想更改服务方法的签名以获取更多参数。相反,我想以某种方式更改远程处理堆栈,以便涵盖所有当前和未来的服务调用。
我按照这个答案写了一个IServiceRemotingClient
用来AsyncLocal
存储上下文信息的。例如,这不允许我检查响应类型和记录异常堆栈跟踪。
我的问题是 - 有没有办法将 SF 的调用包装到我自己的方法中,更接近我的服务方法,我可以在其中记录异常和结果,而不是在远程级别,所有内容都已打包为黑盒
public class LoggingServiceRemotingClient: IServiceRemotingClient
{
IServiceRemotingClient standardClient;
...
public async Task<IServiceRemotingResponseMessage> RequestResponseAsync(IServiceRemotingRequestMessage requestMessage)
{
var callId = Guid.NewGuid();
try{
SetCallIdInAsyncLocal(callId); // trimmed down pseudo code
var response = await this.standardClient.RequestResponseAsync(requestMessage);
Log.Ok(callId); // trimmed down pseudo code
} catch (Exception x){
// this will never be hit because the response body was already created with an exception serialized in it.
// how do I catch such exceptions across all calls?
// also some calls a due to client errors, others are internal - a single place to differentiate would be nice.
Log.Fail(callId, x);
}
}
}
服务本身也将callId
用于记录自己的进程:
public class MyService: StatelessService, IMyService
{
public async Task<string> GetMeAString(string prefix)
{
Debug.Assert(prefix!=null); // this exception is a caller fault
Guid callId = GetFromAsyncLocal();
Log(callId, "Got a call here")
string result = prefix+": "+Guid.NewGuid().ToString();
Log(callId, "returning "+result);
return result;
}
}
我不明白为什么AsyncLocal
在这里工作,但显然,它确实如此。
解决方案
我认为您正在从Microsoft Application Insights for Service Fabric包中寻找与 Service Remoting 的 Trace Correlation 。
它将所有依赖跟踪信息发送到应用程序洞察力,不需要对代码进行太多更改,还可以与其他应用程序洞察力监控功能结合使用。
如果您想从头开始或不使用 AppInsights,Peter Bons 提到的选项也是有效的。
推荐阅读
- excel - 在 Access 中使用 VBA 更改 Excel 单元格文本颜色
- java - 使用 java 和 Xpath 获取 xml 的所有属性
- sql - 如何修复数据库中的拼写错误 在该记录中有多个记录 还有更多记录
- python - Python Matplotlib 在后台更新绘图
- sphinx - 在 sphinx-query 中使用不同 user_weights 的字段两次
- python-3.x - 'map' 对象在 python3 中不可下标
- scala - 如何从单个字符串列 RDD 中有效地提取多列?
- linux - http:接受错误:接受tcp [::]:8080:accept4:打开的文件太多;
- c# - Python 上的 C# DLL
- blazor - Blazor,使用 Fabric-js 控件