Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
> - Java 8 support will be dropped. SDK 9.0.0 requires Java 11+. See [#6469](https://github.com/getsentry/sentry-java/issues/6469).
> - The Android `minSdk` will be raised from 21 to 24. See [#5508](https://github.com/getsentry/sentry-java/issues/5508).

## Unreleased

### Fixes

- Send outbox attachments together with their event or transaction so parent filtering also drops its attachments. Grouped attachments now respect the configured per-attachment `maxAttachmentSize` limit. ([#6513](https://github.com/getsentry/sentry-java/pull/6513))

## 8.65.0

### Features
Expand Down
59 changes: 57 additions & 2 deletions sentry/src/main/java/io/sentry/OutboxSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -121,13 +123,52 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN
CollectionUtils.size(envelope.getItems()));
int currentItem = 0;

int parentCount = 0;
boolean transactionParent = false;
for (final SentryEnvelopeItem item : envelope.getItems()) {
if (item.getHeader() != null
&& (SentryItemType.Event.equals(item.getHeader().getType())
|| SentryItemType.Transaction.equals(item.getHeader().getType()))) {
parentCount++;
transactionParent = SentryItemType.Transaction.equals(item.getHeader().getType());
}
}

final List<Attachment> attachments = new ArrayList<>();
if (parentCount == 1) {
// Collect before dispatch so attachments may precede or follow their parent. Multiple parents
// are ambiguous and retain the legacy per-item path.
for (final SentryEnvelopeItem item : envelope.getItems()) {
final SentryEnvelopeItemHeader header = item.getHeader();
if (header != null
&& SentryItemType.Attachment.equals(header.getType())
&& header.getFileName() != null) {
attachments.add(
new Attachment(
() -> item.getData(),
header.getFileName(),
header.getContentType(),
header.getAttachmentType(),
transactionParent));
}
}
}
// Hint.clear() leaves attachments intact, so restore this snapshot after each grouped capture.
final List<Attachment> originalAttachments = hint.getAttachments();

for (final SentryEnvelopeItem item : envelope.getItems()) {
currentItem++;

if (item.getHeader() == null) {
logger.log(SentryLevel.ERROR, "Item %d has no header", currentItem);
continue;
}
if (parentCount == 1
&& SentryItemType.Attachment.equals(item.getHeader().getType())
&& item.getHeader().getFileName() != null) {
// Even an invalid or filtered parent owns these attachments. Never send them on their own.
continue;
}
if (SentryItemType.Event.equals(item.getHeader().getType())) {
try (final Reader eventReader =
new BufferedReader(
Expand All @@ -144,7 +185,14 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN
logUnexpectedEventId(envelope, event.getEventId(), currentItem);
continue;
}
scopes.captureEvent(event, hint);
try {
hint.addAttachments(attachments);
scopes.captureEvent(event, hint);
} finally {
if (!attachments.isEmpty()) {
hint.replaceAttachments(originalAttachments);
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}
logItemCaptured(currentItem);

if (!waitFlush(hint)) {
Expand Down Expand Up @@ -181,7 +229,14 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN
.getTrace()
.setSamplingDecision(extractSamplingDecision(traceContext));
}
scopes.captureTransaction(transaction, traceContext, hint);
try {
hint.addAttachments(attachments);
scopes.captureTransaction(transaction, traceContext, hint);
} finally {
if (!attachments.isEmpty()) {
hint.replaceAttachments(originalAttachments);
}
}
logItemCaptured(currentItem);

if (!waitFlush(hint)) {
Expand Down
Loading
Loading