Actor 方法启动/停止日志 |添加附加信息

2023-12-02

对于 azure actor 服务,Actor Method Start Stop 会记录在“诊断”窗口中,如下所示。

如何在每次调用方法时添加一些额外的详细信息,例如 Correlation Id?

{
  "Timestamp": "2016-09-14T19:46:40.9955448+05:30",
  "ProviderName": "Microsoft-ServiceFabric-Actors",
  "Id": 7,
  "Message": "Actor method is being invoked. Method name: IStore.GetStoreById, actor type: Backend.Actor.Store.Store, actor ID: STORE_6.",
  "ProcessId": 30736,
  "Level": "Verbose",
  "Keywords": "0x0000F00000000002",
  "EventName": "ActorMethod/Start",
  "Payload": {
    "methodName": "IStore.GetStoreById",
    "methodSignature": "System.Threading.Tasks.Task`1[Backend.Models.Store.StoreView] GetStoreById(System.String)",
    "actorType": "Backend.Actor.Store.Store",
    "actorId": "STORE_6",
    "actorIdKind": 2,
    "replicaOrInstanceId": 131183360004211655,
    "partitionId": "8af1c125-3666-40d0-b630-e3570c41833b",
    "serviceName": "fabric:/MultiBannerBackend/StoreActorService",
    "applicationName": "fabric:/MultiBannerBackend",
    "serviceTypeName": "StoreActorServiceType",
    "applicationTypeName": "MultiBannerBackendType",
    "nodeName": "_Node_4"
  }
}

为了记录每个 Actor 操作的自定义数据,您可以使用以下方法:

protected override Task OnPreActorMethodAsync(ActorMethodContext c)
protected override Task OnPostActorMethodAsync(ActorMethodContext c)

为了获取调用上下文,我发现 CallContext.LogicalGetData 在这种情况下不起作用。幸运的是,演员本身确实了解其背景。您可以使用一些反射来获得它。

例如:

protected override Task OnPreActorMethodAsync(ActorMethodContext c)
        {
            var correlationID = this.GetActorContext() ?? Guid.Empty.ToString("N");
            string message = $"Actor method is being invoked. Method name: {c.MethodName}, actor type: {GetType().FullName}, actor ID: {Id}, CorrelationID:{correlationID}";
            ActorEventSource.Current.ActorMessage(this, message);
            return Task.FromResult(true);
        }

        protected override Task OnPostActorMethodAsync(ActorMethodContext c)
        {
            var correlationID = this.GetActorContext() ?? Guid.Empty.ToString("N");
            string message = $"Actor method has completed. Method name: {c.MethodName}, actor type: {GetType().FullName}, actor ID: {Id}, CorrelationID:{correlationID}";
            ActorEventSource.Current.ActorMessage(this, message);
            return Task.FromResult(true);
        }

结合:

public static class ActorContextExtensions
    {
        public static string GetActorContext(this Actor actor)
        {
            var concurrencyLockProperty = GetPropertyInfo("ConcurrencyLock", typeof(ActorBase));
            var concurrencyLockPropertyValue = concurrencyLockProperty.GetValue(actor);

            var currentContextProperty = GetPropertyInfo("Test_CurrentContext", concurrencyLockPropertyValue.GetType());
            string currentContextPropertyValue = (string)currentContextProperty.GetValue(concurrencyLockPropertyValue);
            return currentContextPropertyValue;
        }

        private static PropertyInfo GetPropertyInfo(string propertyName, IReflect owner)
        {
            var property = owner.GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Instance);
            if (property == null) throw new InvalidOperationException($"Failed to find property '{propertyName}' on '{owner}'.");
            return property;
        }
    }

这样做的明显缺点是,只要 ActorBase 的内部发生变化,您就需要相应地更改反射代码。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Actor 方法启动/停止日志 |添加附加信息 的相关文章

  • 部署期间 Azure 中的 Service Fabric 错误

    将集群部署到 Azure 时遇到问题 一切都在本地运行 但是当部署到 Azure 时 我在尝试调用其中一项服务时收到错误 在 Azure 中 服务结构是6 1 480 9494 并且无法升级 但我的本地版本是6 2 262 94946天前发
  • 具有通用服务的 Service Fabric

    我希望有一个通用类型的服务 即 public interface IFooService
  • 通过 VSTS CI/CD 升级 Azure Service Fabric 时出错

    我正在使用 VSTS 来设置 CI CD 以进行服务结构构建和部署 第一次部署没有错误 但第二次更新部署给出了以下错误 ConfigPackage中的内容名称 Config 版本 1 0 0 20180312 1 服务清单中的 Sample
  • 在开发人员计算机上自动创建没有 DefaultServices 的服务

    在最近的 Service Fabric 社区问答第 24 版中 有很多关于在 Service Fabric 中使用 DefaultService 构造的讨论 ApplicationManifest xml以及它的缺点 Microsoft 建
  • Azure Service Fabric 和消息队列

    现在有了 Azure Service Fabric 是否还有使用单独的队列解决方案 例如 Windows Service Bus 的用例 缺点可能会成为新的单点故障 但有优点吗 队列可以添加一些缓冲 但另一方面 Service Fabric
  • Service Fabric 资源平衡器使用陈旧的报告负载

    在研究 Service Fabric 上的资源平衡器和动态负载指标时 我们遇到了一些问题 运行 devbox SDK GA 2 0 135 在 Service Fabric Explorer 门户和独立应用程序 中 我们可以看到平衡运行非常
  • Service Fabric 服务远程处理

    过去几周我一直在从云服务迁移到 Service Fabric 并且在两个服务之间使用远程处理时遇到了一些障碍 我一直在使用服务远程处理的官方文档和示例代码 特别是我试图让此处概述的示例正常工作 https learn microsoft c
  • Azure Service Fabric 有状态服务中的可靠字典对象自动过期

    是否有任何内置方法可以将可靠字典对象的过期时间设置为在特定时间后过期 尝试看看我们是否可以开始使用可靠的集合来存储用户会话对象 无状态服务可以访问有状态服务创建的字典对象吗 抱歉 如果这些都是蹩脚的问题 尝试理解这些概念 Thanks 不
  • 部署中的密钥保管库值和链接的模板参数

    我有一个模板来创建密钥保管库和其中的秘密 我还有一个 Service Fabric 模板 它需要密钥保管库中的 3 个内容 保管库 URI 证书 URL 和证书指纹 如果我使用 powershell 创建密钥保管库和密钥 则可以轻松地从输出
  • 由于缺少服务结构包,不会添加依赖项

    启动一个新的空 NET Core 2 类库 我尝试使用 nuget 添加任何依赖项 但出现此错误 错误本地源 C Program Files Microsoft SDKs Service Fabric packages 不存在 但服务结构应
  • azure服务结构可靠字典linq查询非常慢

    我在服务结构有状态服务中有一本可靠的字典 我有一个简单的 linq 表达式 我正在使用 Ix Async 包来构建异步枚举 using ITransaction tx this StateManager CreateTransaction
  • 将证书添加到 Azure VM 规模集

    基本上我正在尝试遵循本指南 http ronaldwildenberg com custom domain name and certificate for your azure service fabric cluster http ro
  • Service Fabric 无状态服务器自定义 UDP 侦听器

    我们正在尝试定义一个 Service Fabric 无状态服务 用于侦听 UDP 数据 我们正在与 Microsoft 合作 他们表示支持 TCP 并且我应该设置 TCP 以下是 ServiceManifest xml 文件的片段
  • 服务结构提醒

    文档 https learn microsoft com en us azure service fabric service fabric reliable actors timers reminders actor reminders
  • 动态 Servicefabric 设置和覆盖

    有没有办法完全不告诉服务有关设置 而只在应用程序级别提供它们 我仍然对 servicefabric 配置的工作方式不满意 据我所知 我必须在服务的 settings xml 中指定所有可能的配置值 然后我可以覆盖应用程序的 Applicat
  • Azure Service Fabric 节点、节点类型、实例和规模集

    在尝试了几天Azure的Service Fabric之后 我仍然对以下四个关键词感到不舒服 实例 节点 节点类型 规模设定 他们的意思是什么 有什么区别 Instance 取决于上下文 它可能意味着虚拟机 服务实例等 Node 集群内的节点
  • 将 C# Stateful Service Fabric 应用程序从 Visual Studio 部署到 Linux

    编辑 04 06 18 gt 更新了问题的最新状态 因此 我有一个正在运行的 Net 4 6 Stateful Service 它当前在部署在 Azure 上的 Windows Service Fabric 集群上运行 从 09 2017
  • 访问 Azure Service Fabric 有状态服务状态

    我已将 Web API 添加到我的有状态服务并想要访问StateManager从它 从外面StatefulService类实现 最好的方法是什么 目前我正在为此使用一个小类 internal static class InstanceAcc
  • 在 Service Fabric 应用程序中动态创建服务

    这有点描述性 所以请耐心等待 在我尝试构建的应用程序中 产品具有独特的功能 用户可以选择选择功能 A B D 但不能选择 C 我构建此功能的方式是 每个不同的功能都是一个服务 无状态 我正在考虑将数据存储在 Azure SQL 中 数据库并
  • 如何为 Azure Service Fabric 中的 docker 容器指定命令行参数

    我有一个泊坞窗图像wiremock net nano https hub docker com r sheyenrath wiremock net nano 它接受额外的命令行参数 例如 Port and AdminUsername 正常的

随机推荐