Skip to content

Commit

Permalink
rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
mhlidd committed Dec 16, 2024
1 parent 3490fe8 commit 3e4955a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ public void onRootSpanFinished(AgentSpan root, EndpointTracker tracker) {
if (!root.isOutbound()) {
profilingContextIntegration.onRootSpanFinished(root, tracker);
}
TracerDump.suspendRootSpan(root);
}

/**
Expand All @@ -277,7 +276,6 @@ public EndpointTracker onRootSpanStarted(AgentSpan root) {
if (!root.isOutbound()) {
return profilingContextIntegration.onRootSpanStarted(root);
}
TracerDump.addUnfinishedRootSpan(root);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

import datadog.communication.ddagent.SharedCommunicationObjects;
import datadog.trace.api.Config;
import datadog.trace.api.flare.TracerFlare;
import datadog.trace.api.time.TimeSource;
import datadog.trace.core.monitor.HealthMetrics;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipOutputStream;
import org.jctools.queues.MessagePassingQueue;
import org.jctools.queues.MpscBlockingConsumerArrayQueue;
import org.slf4j.Logger;
Expand Down Expand Up @@ -44,6 +48,7 @@ public interface Element {
}

private static class DelayingPendingTraceBuffer extends PendingTraceBuffer {
private static final Logger log = LoggerFactory.getLogger(DelayingPendingTraceBuffer.class);
private static final long FORCE_SEND_DELAY_MS = TimeUnit.SECONDS.toMillis(5);
private static final long SEND_DELAY_NS = TimeUnit.MILLISECONDS.toNanos(500);
private static final long SLEEP_TIME_MS = 100;
Expand Down Expand Up @@ -78,6 +83,7 @@ public void enqueue(Element pendingTrace) {

@Override
public void start() {
TracerFlare.addReporter(new TracerDump(this));
worker.start();
}

Expand Down Expand Up @@ -235,6 +241,45 @@ public DelayingPendingTraceBuffer(
config, bufferSize, sharedCommunicationObjects, healthMetrics)
: null;
}

static class TracerDump implements TracerFlare.Reporter {

private final DelayingPendingTraceBuffer buffer;

public TracerDump(DelayingPendingTraceBuffer buffer) {
this.buffer = buffer;
}

@Override
public void addReportToFlare(ZipOutputStream zip) throws IOException {
TracerFlare.addText(zip, "trace_dump.txt", getDumpText());
}

private String getDumpText() {
StringBuilder dumpText = new StringBuilder();
try {
Element head = buffer.queue.poll(1, TimeUnit.SECONDS);
ArrayList<Element> dumpSpans = new ArrayList<>();
while (head != null && dumpSpans.size() < 100) { // temp arbitrary limit
dumpSpans.add(head);
head = buffer.queue.poll();
}
for (Element e : dumpSpans) {
buffer.queue.offer(e);
if (e instanceof PendingTrace) {
PendingTrace trace = (PendingTrace) e;
for (DDSpan span : trace.getSpans()) {
dumpText.append(span.toString()).append("\n");
}
}
}
} catch (InterruptedException e) {
log.error("Error with polling the buffer queue. Buffer: {}", buffer);
Thread.currentThread().interrupt();
}
return dumpText.toString();
}
}
}

static class DiscardingPendingTraceBuffer extends PendingTraceBuffer {
Expand Down

This file was deleted.

0 comments on commit 3e4955a

Please sign in to comment.