问题描述
我在 spring 应用程序中使用 elastic-apm 来监视 API 请求并跟踪为给定端点执行的所有 sql。问题是流量弹性搜索正在收集大量数据,我想仅为特定端点启用捕获跨度。 我尝试使用 elastic-apm https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html 的公共 api 我可以自定义事务和跨度,但找不到启用/禁用特定端点的方法。 我试过这个,但没有运气 -
ElasticApm.currentSpan().startSpan();
ElasticApm.currentSpan().end();
解决方法
看起来可以使用 api-server.yml 中的 drop_event 处理器来完成。
processors:
- drop_event:
when:
equals:
transaction.custom.transactions_sampled: false
并在代码集自定义上下文中:
Transaction elasticTransaction = ElasticApm.currentTransaction();
elasticTransaction.addCustomContext("transactions.sampled",false);