Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding StartTime into Span so we can add proper hierarchical spans in to telemetry #489

Merged
merged 3 commits into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,6 +34,7 @@ public final class Trace {
public static final class Span {

private final String name;
private final long startTime;
private final StopWatch stopWatch;
private final List<Span> children = new ArrayList<>();
private boolean done = false;
Expand All @@ -43,7 +44,7 @@ public static final class Span {
if (name.isBlank()) {
throw new IllegalArgumentException("A blank name is not allowed!");
}

startTime = System.currentTimeMillis();
guw marked this conversation as resolved.
Show resolved Hide resolved
stopWatch = new StopWatch();
stopWatch.start();
}
Expand All @@ -68,6 +69,10 @@ public long getDuration(TimeUnit timeUnit) {
return stopWatch.getDuration(timeUnit);
}

public long getStartTime() {
return startTime;
}

public String getName() {
return name;
}
Expand Down
Expand Up @@ -53,11 +53,13 @@ interface TraceTreeVisitor {

public static record SpanNode(
String name,
long startTime,
long durationNanos,
double percentageOfRoot,
java.util.List<SpanNode> children) {
public SpanNode(String name, long durationNanos, double percentageOfRoot, java.util.List<SpanNode> children) {
public SpanNode(String name, long startTime, long durationNanos, double percentageOfRoot, java.util.List<SpanNode> children) {
guw marked this conversation as resolved.
Show resolved Hide resolved
this.name = requireNonNull(name);
this.startTime = startTime;
guw marked this conversation as resolved.
Show resolved Hide resolved
this.durationNanos = durationNanos;
this.percentageOfRoot = percentageOfRoot;
this.children = requireNonNull(children);
Expand All @@ -73,6 +75,7 @@ void visit(TraceTreeVisitor visitor) {
public JsonObject toJson() {
var node = new JsonObject();
node.addProperty("name", name());
node.addProperty("startTime", startTime());
node.addProperty("durationNanos", durationNanos());
node.addProperty("persentageOfRoot", percentageOfRoot());
if (!children().isEmpty()) {
Expand Down Expand Up @@ -102,7 +105,8 @@ private static SpanNode createNode(Span span, long rootDurationNanos) {
}

var durationNanos = span.getDuration(TimeUnit.NANOSECONDS);
return new SpanNode(span.getName(), durationNanos, percentage(durationNanos, rootDurationNanos), children);
var startTime = span.getStartTime();
return new SpanNode(span.getName(), startTime, durationNanos, percentage(durationNanos, rootDurationNanos), children);
}

private static double percentage(long duration, long rootDuration) {
Expand Down
Expand Up @@ -34,11 +34,12 @@ void ensure_output_produced_for_sample_trace() throws Exception {
private TraceTree simpleSampleTree() {
var rootNode = new TraceTree.SpanNode(
"Root",
1999999L,
100000L,
80.0F,
List.of(
new TraceTree.SpanNode("Child 1", 50000L, 3.0F, Collections.emptyList()),
new TraceTree.SpanNode("Child 2", 30000L, 5.0F, Collections.emptyList())));
new TraceTree.SpanNode("Child 1", 1999999L, 50000L, 3.0F, Collections.emptyList()),
new TraceTree.SpanNode("Child 2", 1999999L, 30000L, 5.0F, Collections.emptyList())));

return new TraceTree(rootNode);
}
Expand Down