Kibana version: 7.4
Elasticsearch version: 7.4
APM Server version: 7.4
APM Agent language and version: Java Programmatic API (ElasticApmAttacher) 1.10.0
Description of the problem including expected versus actual behavior:
I am responding to calls from a third-party API and would like to start my transaction at the time the information was sent from the third-party (so I can track latency across deployed sites/regions).
What's happening is that when I setStartTimestamp
to be earlier than the default transaction start, that whole time is added to the "app" type in the "Time spent by span type", even when there are spans in that time frame.
A simplified timeline ("absolute" ms):
- 0ms (Timestamped) message is sent from third-party
- 20ms Message is received by my app and starts processing
- 30ms A service is called
- 40ms service responds and returns
What I expect in "Time spent by span type":
50% Message Latency, 25% app, 25% service
What is actually reported:
33% Message Latency, 50% app, 17% service
This seems to be because when the transaction is moved 20ms earlier (making it 40ms instead of the local 20ms), that's automatically added to the "app" type, even though the full 20ms span is added in that time frame.
The times that I think it's calculating:
20ms Message Latency
30ms app
10ms service
The "app" should be 10ms.
Basic code:
long now = <get micros>;
long msgTs = <get micros from message>;
Transaction trans = createTransaction.setStartTimestamp(msgTs);
Span msgLatency = trans.createSpan().setStartTimestamp(msgTs).end(now);
// some work for 10ms
Span serviceTime = trans.createSpan();
try{
return service.doStuff();
} finally {
serviceTime.end();
}
"Workaround":
Set the latency span's times as in the code above, but do not call tran.setStartTimestamp
. This fixes the percentages and the graph, with the annoyance that the message latency is no longer visible in the Trace view, since the transaction does not cover that time period.