Skip to content

Commit

Permalink
[pinpoint-apm#9575] Refactor AsyncTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jan 13, 2023
1 parent 33191a1 commit c0ad587
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ public static boolean hasScope(final Trace trace, final String scopeName) {
final TraceScope scope = trace.getScope(scopeName);
return scope != null;
}

public static boolean addScope(Trace trace, String scopeName) {
// add async scope.
final TraceScope oldScope = trace.addScope(scopeName);
if (oldScope != null) {
// delete corrupted trace.
// deleteAsyncTrace(trace);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public final class ScopeUtils {
private static final Logger logger = LogManager.getLogger(ScopeUtils.class);
public final class AsyncScopeUtils {
private static final Logger logger = LogManager.getLogger(AsyncScopeUtils.class);

private ScopeUtils() {
private AsyncScopeUtils() {
}

public static boolean nestedScope(Trace trace, String scopeName) {
public static boolean nested(Trace trace, String scopeName) {
// add async scope.
final TraceScope oldScope = trace.addScope(scopeName);
if (oldScope != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private Trace newAsyncContextTrace(Reference<Trace> reference) {
logger.debug("asyncTraceContext.continuAsyncTraceObject(e) AsyncTrace:{}", asyncTrace);
}

if (ScopeUtils.nestedScope(asyncTrace, ASYNC_TRACE_SCOPE)) {
if (AsyncScopeUtils.nested(asyncTrace, ASYNC_TRACE_SCOPE)) {
return null;
}

Expand All @@ -112,21 +112,15 @@ private void bind(Reference<Trace> reference, Trace asyncTrace) {

@Override
public Trace currentAsyncTraceObject() {
final Reference<Trace> reference = currentTraceObject();
return reference.get();
}


private Reference<Trace> currentTraceObject() {
final Reference<Trace> reference = binder.get();
final Trace trace = reference.get();
if (trace == null) {
return DefaultReference.emptyReference();
return null;
}
if (trace.canSampled()) {
return reference;
return trace;
}
return DefaultReference.emptyReference();
return null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private Trace newAsyncContextTrace(Reference<Trace> reference) {
logger.debug("asyncTraceContext.continueDisableAsyncContextTraceObject() AsyncTrace:{}", asyncTrace);
}

if (ScopeUtils.nestedScope(asyncTrace, ASYNC_TRACE_SCOPE)) {
if (AsyncScopeUtils.nested(asyncTrace, ASYNC_TRACE_SCOPE)) {
return null;
}

Expand Down

0 comments on commit c0ad587

Please # to comment.