现在,我们的ASF集群正在运行:
我们正在尝试Application Insights,并且我可以像这里的文档一样为我们的Web API项目设置未处理的错误跟踪。
问题是,我也希望我们的Actor项目也能做到这一点。
是否存在在Actor中捕获未处理的错误的全球场所?我知道它是新的,也许这就是为什么我找不到关于此的文档。
现在,我正在每个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;
}
}
您有几种选择:
演员确实具有一个Microsoft-ServiceFabric-Actors
带有ActorMethodThrewException
事件的内置ETW提供程序()。您可以:
EventListener
该类来侦听正在进行的事件,并将其转发给App Insights(可靠性稍差,但更简单)使用custom ActorServiceRemotingDispatcher
,这是负责向操作者分派操作的类
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;
}
}
}
要使用此类,您需要创建一个自定义ActorService
类并覆盖该CreateServiceReplicaListeners
方法。请注意,这将覆盖ActorRemotingProviderAttribute
您可能正在使用的所有。
旁注:
IServiceRemotingClientFactory
添加标头)ServiceRemotingDispatcher
类)本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句