问题描述
目前我们的ASF集群正在运行:
- 的Web API项目 - 无状态的,面向公众的
- 演员的项目 - 在内存中大多是易挥发,保持数据,某些API一起使用
我们正在尝试应用洞察力,以及喜欢他们的文档,我可以设置未处理的误差跟踪的对我们的Web API项目。
问题是,我想这对于我们演员的项目也是如此。
有一个演员中捕捉未处理的错误一个全球性的地方吗?我知道这是新的,也许这就是为什么我不能在此找到文档。
现在我做这个每个演员方法中,但似乎并不像一个很好的解决方案:
公共异步任务DoStuff()
{
尝试
{
//难道我所有的东西
}
赶上(例外EXC)
{
//发送到Windows事件来源
ActorEventSource.Current.ActorMessage(这一点,在{0}未处理的错误:{1},nameof(DoStuff),EXC); //发送到应用洞察
新TelemetryClient()TrackException(EXC)。 扔EXC;
}
}
您有几种选择:
-
演员确实有一个内置的ETW提供商(
微软ServiceFabric-演员
),它有一个ActorMethodThrewException
事件。您可以:- 使用一个外部程序来收集ETW事件,并转发给应用洞察(例如,使用板或Azure诊断)
- 使用
的EventListener
类收听过程中的事件,并将其转发到App洞察(略少可靠,但更简单)
-
使用自定义的
ActorServiceRemotingDispatcher
,它负责调度操作演员类类CustomActorServiceRemotingDispatcher:ActorServiceRemotingDispatcher
{
公共CustomActorServiceRemotingDispatcher(ActorService actorService):基地(actorService)
{
} 公共覆盖异步任务<字节[]> RequestResponseAsync(IServiceRemotingRequestContext的RequestContext,ServiceRemotingMessageHeaders messageHeaders,
字节[] requestBodyBytes)
{
尝试
{
LogServiceMethodStart(...); 结果=等待base.RequestResponseAsync(RequestContext的,messageHeaders,requestBodyBytes).ConfigureAwait(假); LogServiceMethodStop(...); 返回结果;
}
赶上(例外的例外)
{
LogServiceMethodException(...); 扔;
}
}
}要使用这个类,你需要创建一个自定义
ActorService
类和重写CreateServiceReplicaListeners
方法。请注意,这将覆盖任何ActorRemotingProviderAttribute
就是你可能会使用。旁注:
- 您也可以使用此方法来读取你自己的头文件(你还需要一个客户端自定义的
IServiceRemotingClientFactory
来添加的话) - 同样的技术可以应用到可靠的服务(使用
ServiceRemotingDispatcher
类)
- 您也可以使用此方法来读取你自己的头文件(你还需要一个客户端自定义的
Right now our ASF cluster is running:
- Web API project - stateless and public facing
- Actor project - mostly volatile, keeping data in memory, used by certain APIs
We are trying out Application Insights, and I can setup unhandled error tracking like their docs here have for our Web API project.
Issue is, I want this for our Actor project as well.
Is there a global place for catching unhandled errors within an Actor? I know it's new, and maybe that is why I can't find documentation on this.
Right now I'm doing this inside every actor method, but doesn't seem like a great solution:
public async Task DoStuff()
{
try
{
//Do all my stuff
}
catch (Exception exc)
{
//Send to Windows Event Source
ActorEventSource.Current.ActorMessage(this, "Unhandled error in {0}: {1}", nameof(DoStuff), exc);
//Send to Application Insights
new TelemetryClient().TrackException(exc);
throw exc;
}
}
You have a few options:
Actors do have a built-in ETW provider (
Microsoft-ServiceFabric-Actors
) that has anActorMethodThrewException
event. You can either:- Use an external process to collect ETW events and forward them to Application Insights (e.g. using SLAB or Azure Diagnostics)
- Use the
EventListener
class to listen to the events in-process and forward it to App Insights (slightly less reliable, but simpler)
Use a custom
ActorServiceRemotingDispatcher
, which is the class responsible for dispatching operations to the actorsclass CustomActorServiceRemotingDispatcher : ActorServiceRemotingDispatcher { public CustomActorServiceRemotingDispatcher(ActorService actorService) : base(actorService) { } public override async Task<byte[]> RequestResponseAsync(IServiceRemotingRequestContext requestContext, ServiceRemotingMessageHeaders messageHeaders, byte[] requestBodyBytes) { try { LogServiceMethodStart(...); result = await base.RequestResponseAsync(requestContext, messageHeaders, requestBodyBytes).ConfigureAwait(false); LogServiceMethodStop(...); return result; } catch (Exception exception) { LogServiceMethodException(...); throw; } } }
To use this class, you'll need to create a custom
ActorService
class and override theCreateServiceReplicaListeners
method. Note this will override anyActorRemotingProviderAttribute
s you may be using.Side notes:
- You can also use this method to read your own headers (you'll also need a client-side custom
IServiceRemotingClientFactory
to add them) - The same technique can be applied to Reliable Services (using the
ServiceRemotingDispatcher
class)
- You can also use this method to read your own headers (you'll also need a client-side custom
这篇关于Azure的服务面料演员 - 未处理的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!