Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# vNext


* Fix: Remove experimental annotation for Attachment #1257
* Fix: Mark stacktrace as snapshot if captured at arbitrary moment #1231
* Enchancement: Improve EventProcessor nullability annotations (#1229).
Expand All @@ -18,6 +19,7 @@
* Enchancement: Add Request to the Scope. #1270
* Fix: Fix SentryTransaction#getStatus NPE (#1273)
* Enchancement: Optimize SentryTracingFilter when hub is disabled.
* Fix: Discard unfinished Spans before sending them over to Sentry (#1279)
* Fix: Interrupt the thread in QueuedThreadPoolExecutor (#1276)
* Fix: SentryTransaction#finish should not clear another transaction from the scope (#1278)

Expand Down
12 changes: 12 additions & 0 deletions sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@ public void captureSession(final @NotNull Session session, final @Nullable Objec
}
}
}
final List<Span> unfinishedSpans = new ArrayList<>();
for (Span span : transaction.getSpans()) {
if (!span.isFinished()) {
unfinishedSpans.add(span);
}
}
if (!unfinishedSpans.isEmpty()) {
options
.getLogger()
.log(SentryLevel.WARNING, "Dropping %d unfinished spans", unfinishedSpans.size());
}
transaction.getSpans().removeAll(unfinishedSpans);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to log out. Maybe check if logging is enabled to warn level, if yes we log count of dropped span and the operations?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd log it too

return transaction;
}

Expand Down
19 changes: 19 additions & 0 deletions sentry/src/test/java/io/sentry/SentryClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,25 @@ class SentryClientTest {
}, eq(null))
}

@Test
fun `when captureTransactions unfinished spans are removed`() {
val sut = fixture.getSut()
val transaction = SentryTransaction("a-transaction", "op")
val span1 = transaction.startChild("span1")
span1.finish()
val span2 = transaction.startChild("span2")

sut.captureTransaction(transaction, mock(), null)
verify(fixture.transport).send(check {
val sentTransaction = it.items.first().getTransaction(fixture.sentryOptions.serializer)
assertNotNull(sentTransaction) { tx ->
val sentSpanIds = tx.spans.map { span -> span.spanId }
assertTrue(sentSpanIds.contains(span1.spanContext.spanId))
assertFalse(sentSpanIds.contains(span2.spanContext.spanId))
}
}, eq(null))
}

@Test
fun `when captureTransaction with attachments`() {
val transaction = SentryTransaction("a-transaction", "op")
Expand Down