Skip to content

Commit

Permalink
Fix span trimming logic
Browse files Browse the repository at this point in the history
  • Loading branch information
markushi committed Feb 1, 2023
1 parent aa9f166 commit 81f1ba5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions sentry/src/main/java/io/sentry/SentryDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public long diff(final @NotNull SentryDate otherDate) {
return nanoTimestamp() - otherDate.nanoTimestamp();
}

public boolean beforeOrEqual(final @NotNull SentryDate otherDate) {
return diff(otherDate) <= 0;
}

public boolean afterOrEqual(final @NotNull SentryDate otherDate) {
return diff(otherDate) >= 0;
}

@Override
public int compareTo(@NotNull SentryDate otherDate) {
return Long.valueOf(nanoTimestamp()).compareTo(otherDate.nanoTimestamp());
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/SentryTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ public void finish(@Nullable SpanStatus status, @Nullable SentryDate finishDate)
for (Span child : children) {
if (child.getParentSpanId() != null && child.getParentSpanId().equals(span.getSpanId())) {
childCount++;
if (minChildStart == null || minChildStart.diff(child.getStartDate()) < 0) {
if (minChildStart == null || child.getStartDate().beforeOrEqual(minChildStart)) {
minChildStart = child.getStartDate();
}
if (maxChildEnd == null
|| (child.getFinishDate() != null && maxChildEnd.diff(child.getFinishDate()) < 0)) {
|| (child.getFinishDate() != null && child.getFinishDate().afterOrEqual(maxChildEnd))) {
maxChildEnd = child.getFinishDate();
}
}
Expand Down

0 comments on commit 81f1ba5

Please sign in to comment.