fix BanyanDB debugging trace (#12418)

This commit is contained in:
Wan Kai 2024-07-08 12:27:28 +08:00 committed by GitHub
parent 06cdf991f5
commit 3acad529f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -36,14 +36,17 @@ public class DebuggingTraceContext {
this.dumpStorageRsp = dumpStorageRsp;
}
/**
* Create a new span for OAP internal debugging trace and start.
* @param operation operation
* @return DebuggingSpan
*/
public DebuggingSpan createSpan(String operation) {
DebuggingSpan span = new DebuggingSpan(spanIdGenerator++, operation);
if (debug) {
//default start time, could be overwritten by setStartTime (BanyanDB Trace)
span.setStartTime(System.nanoTime());
DebuggingSpan parentSpan = spanStack.isEmpty() ? null : spanStack.peek();
if (parentSpan != null) {
//default parent span id, could be overwritten by setParentSpanId (BanyanDB Trace)
span.setParentSpanId(parentSpan.getSpanId());
} else {
span.setParentSpanId(-1);
@ -54,6 +57,20 @@ public class DebuggingTraceContext {
return span;
}
/**
* Use for transform the other Span to DebuggingSpan, such as BanyanDB trace span.
* The start time , end time, duration, parent span id should be set manually.
* @param operation operation
* @return DebuggingSpan
*/
public DebuggingSpan createSpanForTransform(String operation) {
DebuggingSpan span = new DebuggingSpan(spanIdGenerator++, operation);
if (debug) {
execTrace.addSpan(span);
}
return span;
}
public DebuggingSpan getParentSpan() {
if (spanStack.isEmpty()) {
return null;

View File

@ -242,7 +242,7 @@ public abstract class AbstractBanyanDBDAO extends AbstractDAO<BanyanDBStorageCli
}
private void addDBSpan2DebuggingTrace(Span span, DebuggingTraceContext traceContext, DebuggingSpan parentSpan) {
DebuggingSpan debuggingSpan = traceContext.createSpan("BanyanDB: " + span.getMessage());
DebuggingSpan debuggingSpan = traceContext.createSpanForTransform("BanyanDB: " + span.getMessage());
debuggingSpan.setStartTime(span.getStartTime().getSeconds() * 1000_000_000 + span.getStartTime().getNanos());
debuggingSpan.setEndTime(span.getEndTime().getSeconds() * 1000_000_000 + span.getEndTime().getNanos());
debuggingSpan.setDuration(span.getDuration());