Skip to content

Commit

Permalink
fix BanyanDB debugging trace (apache#12418)
Browse files Browse the repository at this point in the history
  • Loading branch information
wankai123 authored Jul 8, 2024
1 parent 06cdf99 commit 3acad52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ public DebuggingTraceContext(String condition, boolean debug, boolean dumpStorag
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);
Expand All @@ -54,6 +57,20 @@ public DebuggingSpan createSpan(String operation) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void addDBTrace2DebuggingTrace(Trace trace, DebuggingTraceContext traceC
}

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());
Expand Down

0 comments on commit 3acad52

Please sign in to comment.