Skip to content

Commit

Permalink
RUM-7549 add details in trace internal logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Dec 17, 2024
1 parent 32afc41 commit 340a1d1
Showing 1 changed file with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ public class PendingTrace extends LinkedList<DDSpan> {

// TODO: consider moving these time fields into DDTracer to ensure that traces have precise
// relative time
/** Trace start time in nano seconds measured up to a millisecond accuracy */
/**
* Trace start time in nano seconds measured up to a millisecond accuracy
*/
private final long startTimeNano;
/** Nano second ticks value at trace start */
/**
* Nano second ticks value at trace start
*/
private final long startNanoTicks;

private final ReferenceQueue referenceQueue = new ReferenceQueue();
Expand All @@ -57,7 +61,9 @@ public class PendingTrace extends LinkedList<DDSpan> {
*/
private final AtomicReference<WeakReference<DDSpan>> rootSpan = new AtomicReference<>();

/** Ensure a trace is never written multiple times */
/**
* Ensure a trace is never written multiple times
*/
private final AtomicBoolean isWritten = new AtomicBoolean(false);

private final InternalLogger internalLogger;
Expand Down Expand Up @@ -90,25 +96,26 @@ public long getCurrentTimeNano() {
public void registerSpan(final DDSpan span) {
if (traceId == null || span.context() == null) {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not registered because of null traceId or context; "+
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not registered because of null traceId or context; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
);
return;
}
if (!traceId.equals(span.context().getTraceId())) {
BigInteger spanTraceId = span.context().getTraceId();
if (!traceId.equals(spanTraceId)) {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not registered because of traceId mismatch; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not registered because of traceId mismatch; " +
"spanId:" + span.getSpanId() + " span.traceid:" + spanTraceId + " traceid:" + traceId,
null,
false,
new HashMap<>()
);
return;
}
Expand All @@ -120,13 +127,13 @@ public void registerSpan(final DDSpan span) {
final int count = pendingReferenceCount.incrementAndGet();
} else {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not registered because it is already registered; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
null,
false,
new HashMap<>()
);
}
}
Expand All @@ -137,20 +144,21 @@ private void expireSpan(final DDSpan span, final boolean write) {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not expired because of null traceId or context; "+
() -> "Span " + span.getOperationName() + " not expired because of null traceId or context; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
);
return;
}
if (!traceId.equals(span.context().getTraceId())) {
BigInteger spanTraceId = span.context().getTraceId();
if (!traceId.equals(spanTraceId)) {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not expired because of traceId mismatch; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
"spanId:" + span.getSpanId() + " span.traceid:" + spanTraceId + " traceid:" + traceId,
null,
false,
new HashMap<>()
Expand Down Expand Up @@ -189,13 +197,13 @@ public void addSpan(final DDSpan span) {
synchronized (this) {
if (span.getDurationNano() == 0) {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not added because duration is zero; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
null,
false,
new HashMap<>()
);
return;
}
Expand Down Expand Up @@ -228,13 +236,13 @@ public void addSpan(final DDSpan span) {
addFirst(span);
} else {
internalLogger.log(
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not added because trace already written; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
InternalLogger.Level.ERROR,
InternalLogger.Target.USER,
() -> "Span " + span.getOperationName() + " not added because trace already written; " +
"spanId:" + span.getSpanId() + " traceid:" + traceId,
null,
false,
new HashMap<>()
);
}
expireSpan(span, true);
Expand Down

0 comments on commit 340a1d1

Please sign in to comment.