I'm trying out different approaches for microservices tracing (i'm mostly working with event-driven services using RabbitMQ).
What I'm testing:
- spring-cloud-sleuth + zipkin + logstash-reporter
- elastic-apm-api + elastic-apm-agent + logstash-reporter
- With both method I'm looking at what is the default output and how to add some spans / transactions that we think interesting to look at. (By "how" I mean what is the cost and impact on the code).
Given the code
@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");
}
My questions / remarks / issues
@NewSpan
does not add a span in Zipkin, the whole "transferToS3" is considered as one span. I tried several other annotations without any success.To have this new span, I'm using
ScopedSpan sp = tracer.startScopedSpanWithParent("getUrlConnection", tracer.currentSpan().context());
andsp.finish()
. The span is visible in ZipKin but it's not really appealing compared to only putting a@NewSpan
. Am I missing something ?Elasticsearch APM agent + API seems to handle this properly by just requiring the addition of
@CaptureTransaction
and@CaptureSpan
. I know it's not perfect because it doesn't hook directly on the consumer call nor support tracing effectively with my use case. But it also requires to add the agent.
Thank you :).