简体   繁体   English

Azure Service Fabric Actors - 未处理的异常?

[英]Azure Service Fabric Actors - unhandled exceptions?

Right now our ASF cluster is running: 现在我们的ASF集群正在运行:

  • Web API project - stateless and public facing Web API项目 - 无状态和面向公众
  • Actor project - mostly volatile, keeping data in memory, used by certain APIs Actor项目 - 主要是volatile,将数据保存在内存中,由某些API使用

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: 你可以:

    • Use an external process to collect ETW events and forward them to Application Insights (eg using SLAB or Azure Diagnostics) 使用外部进程收集ETW事件并将其转发到Application Insights(例如,使用SLAB或Azure诊断)
    • Use the 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: 附注:

    • You can also use this method to read your own headers (you'll also need a client-side custom IServiceRemotingClientFactory to add them) 您也可以使用此方法读取您自己的标题(您还需要一个客户端自定义IServiceRemotingClientFactory来添加它们)
    • The same technique can be applied to Reliable Services (using the ServiceRemotingDispatcher class) 相同的技术可以应用于Reliable Services(使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM