Azure Service Fabric Actors - unhandled exceptions?

六眼飞鱼酱① 提交于 2019-11-30 03:59:18

You have a few options:

  • Actors do have a built-in ETW provider (Microsoft-ServiceFabric-Actors) that has an ActorMethodThrewException 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 actors

    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. Note this will override any ActorRemotingProviderAttributes 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)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!