【问题标题】:Add application insights to stateless service fabric app将应用程序洞察添加到无状态服务结构应用程序
【发布时间】:2019-05-12 02:20:10
【问题描述】:

我正在尝试关注 this documentation,以开始在我部署到服务结构的 .net 核心应用程序中使用应用程序洞察力。

我的代码很简单

public FailedAuthorise(StatelessServiceContext context, IConfigManager config)
        : base(context)
{
    _worker = new Worker<PaymentFailedAuthorise>(config, FailedAuthoriseHandlerFactory.Create, "FailedAuthorise", "FailedAuthoriseError");
}

    protected override async Task RunAsync(CancellationToken cancellationToken)
{
    await _worker.RunAsync(cancellationToken);
}

作为工作者只是一个从一些队列中读取并处理消息的通用类

但是,如果我要按照该文档进行操作,我将需要安装一些 nuget 包(这实际上给我查找和/或安装带来了问题,例如无法访问 使用 Microsoft.ApplicationInsights.ServiceFabric; 或者需要在管道上修改配置文件时更改检测密钥)并开始使用我的解决方案中不需要的“托管”类。

在不需要托管位的情况下,将应用程序洞察力添加到曾经是云服务中的工作人员角色中,这不是一种简单的方法吗?

谢谢,

【问题讨论】:

  • 我认为这是不可能的。如果您知道 azure web app 或 azure function,在 azure 门户中,有一个名为 applicationInsights 的刀片,您只需单击它并进行非常简单的 ui 操作即可添加应用程序见解。但是对于服务结构,没有这样的选择。因此,唯一的方法可能是遵循该文档。但我需要应用洞察团队的确认,如果有任何反馈,我会及时通知您。

标签: azure .net-core azure-service-fabric azure-application-insights


【解决方案1】:

您可以添加 this nuget package 并像这样创建自己的自定义遥测:

public class MyService
{
    private readonly TelemetryClient telemetryClient;

    public MyService()
    {
        telemetryClient = new TelemetryClient(configuration);
        telemetryClient.Context.InstrumentationKey = "[Your Key Here]";
    }

    public FailedAuthorise(StatelessServiceContext context, IConfigManager config)
            : base(context)
    {
        _worker = new Worker<PaymentFailedAuthorise>(config, FailedAuthoriseHandlerFactory.Create, "FailedAuthorise", "FailedAuthoriseError");
    }

    protected override async Task RunAsync(CancellationToken cancellationToken)
    {
        telemetryClient.TrackEvent("Worker started");
        await _worker.RunAsync(cancellationToken);
    }
}

您可以跟踪几件事,例如 exceptions, traces, events, metrics and requests,但如果您不使用 Asp.Net Core,则必须手动发送这些事件,而不是让一些中间件将遥测数据发送到 App Insigths。

如果您的服务调用其他服务,您可以添加this package 以自动跟踪与其他服务的通信。

【讨论】:

  • 我也在尝试将 AI 与我的服务集成,2022 年此指南是否更改?我看到 Microsoft.ApplicationInsights.ServiceFabric.Native 包我们有 FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer()
猜你喜欢
  • 1970-01-01
  • 2019-01-24
  • 2018-08-15
  • 2015-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-08
  • 1970-01-01
相关资源
最近更新 更多