[英]Azure Service Fabric Actors - unhandled exceptions?
Right now our ASF cluster is running: 现在我们的ASF集群正在运行:
We are trying out Application Insights, and I can setup unhandled error tracking like their docs here have for our Web API project. 我们正在尝试应用见解,我也喜欢他们的文档设置未处理的错误跟踪这里有我们的Web API项目。
Issue is, I want this for our Actor project as well. 问题是,我想要我们的Actor项目。
Is there a global place for catching unhandled errors within an Actor? 在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: 现在我在每个actor方法中都这样做,但似乎不是一个很好的解决方案:
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 an ActorMethodThrewException
event. Actor有一个内置的ETW提供程序(
Microsoft-ServiceFabric-Actors
),它有一个ActorMethodThrewException
事件。 You can either: 你可以:
EventListener
class to listen to the events in-process and forward it to App Insights (slightly less reliable, but simpler) EventListener
类来监听进程中的事件并将其转发到App Insights(稍微不那么可靠,但更简单) Use a custom ActorServiceRemotingDispatcher
, which is the class responsible for dispatching operations to the actors 使用自定义
ActorServiceRemotingDispatcher
,它是负责向actor调度操作的类
class 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 the CreateServiceReplicaListeners
method. 要使用此类,您需要创建一个自定义的
ActorService
类并重写CreateServiceReplicaListeners
方法。 Note this will override any ActorRemotingProviderAttribute
s you may be using. 请注意,这将覆盖您可能正在使用的任何
ActorRemotingProviderAttribute
。
Side notes: 附注:
IServiceRemotingClientFactory
to add them) IServiceRemotingClientFactory
来添加它们) ServiceRemotingDispatcher
class) ServiceRemotingDispatcher
类) No, there is no global place to get exceptions thrown from an actor in the actor framework today. 不,今天没有全球的地方可以从演员框架中的演员抛出异常。 The framework itself does catch exception that are thrown from methods that are managed by the actor runtime - these are your actor interface methods (the ones that are callable from ActorProxy), timer callbacks, reminder callbacks, and base actor overrides like OnActivateAsync - but they're not exposed through the actor API.
框架本身确实捕获了由actor运行时管理的方法引发的异常 - 这些是您的actor接口方法(可从ActorProxy调用的方法),计时器回调,提醒回调和基本actor重写,如OnActivateAsync - 但它们'不是通过actor API公开的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.