首页 > 解决方案 > 用于 c# 作业的弹性 apm

问题描述

我将 ElasticAPM 添加到我在 AspNetCore 3.1 上的启动中

app.UseAllElasticApm(Configuration);

在我的项目中,rest api services 记录为 kibana-apm 的事务选项卡。但是我的后台服务没有被 apm 代理记录,只有指标选项卡对我有用。

标签: c#asp.net-coreelastic-apm

解决方案


目前后台服务不是开箱即用的。

您可以做的是使用公共代理 API,并使用一些额外的代码,您也可以将它们捕获为事务。

在后台服务中是这样的:

var transaction = Elastic.Apm.Agent
        .Tracer.StartTransaction("MyTransaction", ApiConstants.TypeRequest);
try
{
    //background service code that is captured as a transaction
}
catch (Exception e)
{
    transaction?.CaptureException(e);
    throw;
}
finally
{
    transaction?.End();
}

推荐阅读