用于 C# 作业的弹性 apm

elastic apm for c# jobs

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

app.UseAllElasticApm(Configuration);

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

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

您可以做的是使用 Public Agent 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();
}