azure - 向无状态 Service Fabric 应用程序添加应用程序洞察

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

我正在尝试关注this documentation为了开始在我部署到服务结构的 .net core 应用程序中使用应用程序洞察。

我的代码非常简单

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 访问 ; 或者需要更改管道上配置文件修改的检测 key )并开始使用我的解决方案中并不真正需要的“托管”类。

这不是一种简单的方法,只需将应用程序洞察力添加到云服务中过去的辅助角色中,而不需要托管位吗?

谢谢

最佳答案

您只需添加 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自动跟踪与其他服务的通信。

关于azure - 向无状态 Service Fabric 应用程序添加应用程序洞察,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53718275/

相关文章:

.net-core - 当前上下文中不存在名称 configurationmanager

c# - EF Core Fluent API 配置防止 TPC 继承

azure - 如何将持续运行的应用程序部署到 Azure Service Fabric?

c# - 在 docker 容器外公开日志文件

azure-service-fabric - HTTPS 终结点在 Service Fabric 本地群集中不起作用

ssl - 从自定义域使用反向代理和 SSL 访问 Service Fabric

azure - CosmosDB 集合中的更改是否会触发每个分区相同的 Azure 函数实例?

Azure 数据工厂 - 管道执行顺序中的多个事件

javascript - 对 AZURE STORAGE BLOB 中的 GET 容器详细信息进行 REST API 调用时身份验证失败

Azure 流量管理器配置