【发布时间】:2019-02-06 17:35:34
【问题描述】:
我正在尝试不同的微服务跟踪方法(我主要使用 RabbitMQ 处理事件驱动服务)。
我在测试什么:
- spring-cloud-sleuth + zipkin + logstash-reporter
- elastic-apm-api + elastic-apm-agent + logstash-reporter
- 通过这两种方法,我正在查看默认输出是什么以及如何添加一些我们认为有趣的跨度/事务。 (“如何”是指成本和对代码的影响)。
给定代码
@Autowired
Tracer tracer;
@NewSpan
@CaptureSpan
private URLConnection getUrlConnection(String url) throws IOException {
ScopedSpan sp = tracer.startScopedSpanWithParent("getUrlConnection", tracer.currentSpan().context());
LOGGER.info("COUOSQUDQSUD");
sp.finish();
return new URL(url).openConnection();
}
@StreamListener(Sink.INPUT)
@CaptureTransaction
public void transferToS3(FileEntry fileEntry) throws IOException {
MDC.put("document_id", fileEntry.getId());
LOGGER.info("Handling Transfer");
URLConnection fileUrlConnection = getUrlConnection(fileEntry.getUrl());
PutObjectResponse response = s3Client.putObject(PutObjectRequest.builder()
.bucket(fileEntry.getS3().getBucket())
.key(fileEntry.getFileName())
.build(), RequestBody.fromInputStream(
new BufferedInputStream(fileUrlConnection.getInputStream()),
fileUrlConnection.getContentLength()
)
);
fileEntry.getS3().setPushedAt(new Date().getTime());
fileEntry.getS3().setPath(response.getValueForField("key", String.class).toString());
LOGGER.info("Transfer done");
}
我的问题/评论/问题
-
@NewSpan在 Zipkin 中没有添加 span,整个“transferToS3”被认为是一个 span。我尝试了其他几个注释都没有成功。 为了拥有这个新的跨度,我使用
ScopedSpan sp = tracer.startScopedSpanWithParent("getUrlConnection", tracer.currentSpan().context());和sp.finish()。跨度在 ZipKin 中是可见的,但与仅放置@NewSpan相比,它并没有真正吸引人。 我错过了什么吗?Elasticsearch APM 代理 + API 似乎只需添加
@CaptureTransaction和@CaptureSpan即可正确处理此问题。我知道它并不完美,因为它不直接挂接到消费者调用上,也不支持对我的用例进行有效跟踪。 但它也需要添加代理。
谢谢你:)。
【问题讨论】:
标签: java spring-cloud spring-cloud-sleuth