Skip to content

Commit ec91944

Browse files
committed
code review changes
1 parent af4060d commit ec91944

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

sentry/src/main/java/io/sentry/util/EventSizeLimitingUtils.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class EventSizeLimitingUtils {
2424

2525
private static final long MAX_EVENT_SIZE_BYTES = 1024 * 1024;
2626
private static final int MAX_FRAMES_PER_STACK = 500;
27+
private static final int FRAMES_PER_SIDE = MAX_FRAMES_PER_STACK / 2;
2728

2829
private EventSizeLimitingUtils() {}
2930

@@ -133,19 +134,8 @@ private static boolean isSizeOk(
133134
for (final @NotNull SentryException exception : exceptions) {
134135
final @Nullable SentryStackTrace stacktrace = exception.getStacktrace();
135136
if (stacktrace != null) {
136-
final @Nullable List<SentryStackFrame> frames = stacktrace.getFrames();
137-
if (frames != null && frames.size() > (FRAMES_PER_SIDE * 2)) {
138-
final @NotNull List<SentryStackFrame> truncatedFrames = new ArrayList<>();
139-
truncatedFrames.addAll(frames.subList(0, FRAMES_PER_SIDE));
140-
truncatedFrames.addAll(frames.subList(frames.size() - FRAMES_PER_SIDE, frames.size()));
141-
stacktrace.setFrames(truncatedFrames);
142-
options
143-
.getLogger()
144-
.log(
145-
SentryLevel.DEBUG,
146-
"Truncated exception stack frames of event %s",
147-
event.getEventId());
148-
}
137+
truncateStackFramesInStackTrace(
138+
stacktrace, event, options, "Truncated exception stack frames of event %s");
149139
}
150140
}
151141
}
@@ -155,24 +145,27 @@ private static boolean isSizeOk(
155145
for (final SentryThread thread : threads) {
156146
final @Nullable SentryStackTrace stacktrace = thread.getStacktrace();
157147
if (stacktrace != null) {
158-
final @Nullable List<SentryStackFrame> frames = stacktrace.getFrames();
159-
if (frames != null && frames.size() > (FRAMES_PER_SIDE * 2)) {
160-
final @NotNull List<SentryStackFrame> truncatedFrames =
161-
new ArrayList<>(FRAMES_PER_SIDE * 2);
162-
truncatedFrames.addAll(frames.subList(0, FRAMES_PER_SIDE));
163-
truncatedFrames.addAll(frames.subList(frames.size() - FRAMES_PER_SIDE, frames.size()));
164-
stacktrace.setFrames(truncatedFrames);
165-
options
166-
.getLogger()
167-
.log(
168-
SentryLevel.DEBUG,
169-
"Truncated thread stack frames for event %s",
170-
event.getEventId());
171-
}
148+
truncateStackFramesInStackTrace(
149+
stacktrace, event, options, "Truncated thread stack frames for event %s");
172150
}
173151
}
174152
}
175153

176154
return event;
177155
}
156+
157+
private static void truncateStackFramesInStackTrace(
158+
final @NotNull SentryStackTrace stacktrace,
159+
final @NotNull SentryEvent event,
160+
final @NotNull SentryOptions options,
161+
final @NotNull String logMessage) {
162+
final @Nullable List<SentryStackFrame> frames = stacktrace.getFrames();
163+
if (frames != null && frames.size() > MAX_FRAMES_PER_STACK) {
164+
final @NotNull List<SentryStackFrame> truncatedFrames = new ArrayList<>(MAX_FRAMES_PER_STACK);
165+
truncatedFrames.addAll(frames.subList(0, FRAMES_PER_SIDE));
166+
truncatedFrames.addAll(frames.subList(frames.size() - FRAMES_PER_SIDE, frames.size()));
167+
stacktrace.setFrames(truncatedFrames);
168+
options.getLogger().log(SentryLevel.DEBUG, logMessage, event.getEventId());
169+
}
170+
}
178171
}

0 commit comments

Comments
 (0)