Skip to content

Commit a32b71e

Browse files
committed
adapt Ratelimiter to check for both ProfileChunk and ProfileChunkUi ratelimiting
1 parent 2979b16 commit a32b71e

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

sentry/src/main/java/io/sentry/transport/RateLimiter.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.Closeable;
2121
import java.io.IOException;
2222
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.Collections;
2325
import java.util.Date;
2426
import java.util.List;
2527
import java.util.Map;
@@ -171,8 +173,8 @@ private void markHintWhenSendingFailed(final @NotNull Hint hint, final boolean r
171173
*/
172174
@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
173175
private boolean isRetryAfter(final @NotNull String itemType) {
174-
final DataCategory dataCategory = getCategoryFromItemType(itemType);
175-
return isActiveForCategory(dataCategory);
176+
final List<DataCategory> dataCategory = getCategoryFromItemType(itemType);
177+
return dataCategory.stream().anyMatch(this::isActiveForCategory);
176178
}
177179

178180
/**
@@ -181,33 +183,33 @@ private boolean isRetryAfter(final @NotNull String itemType) {
181183
* @param itemType the item itemType (eg event, session, attachment, ...)
182184
* @return the DataCategory eg (DataCategory.Error, DataCategory.Session, DataCategory.Attachment)
183185
*/
184-
private @NotNull DataCategory getCategoryFromItemType(final @NotNull String itemType) {
186+
private @NotNull List<DataCategory> getCategoryFromItemType(final @NotNull String itemType) {
185187
switch (itemType) {
186188
case "event":
187-
return DataCategory.Error;
189+
return Collections.singletonList(DataCategory.Error);
188190
case "session":
189-
return DataCategory.Session;
191+
return Collections.singletonList(DataCategory.Session);
190192
case "attachment":
191-
return DataCategory.Attachment;
193+
return Collections.singletonList(DataCategory.Attachment);
192194
case "profile":
193-
return DataCategory.Profile;
195+
return Collections.singletonList(DataCategory.Profile);
194196
// When we send a profile chunk, we have to check for profile_chunk_ui rate limiting,
195-
// because that's what relay returns to rate limit Android. When (if) we will implement JVM
196-
// profiling we will have to check both rate limits.
197+
// because that's what relay returns to rate limit Android.
198+
// And ProfileChunk rate limiting for JVM.
197199
case "profile_chunk":
198-
return DataCategory.ProfileChunkUi;
200+
return Arrays.asList(DataCategory.ProfileChunkUi, DataCategory.ProfileChunk);
199201
case "transaction":
200-
return DataCategory.Transaction;
202+
return Collections.singletonList(DataCategory.Transaction);
201203
case "check_in":
202-
return DataCategory.Monitor;
204+
return Collections.singletonList(DataCategory.Monitor);
203205
case "replay_video":
204-
return DataCategory.Replay;
206+
return Collections.singletonList(DataCategory.Replay);
205207
case "feedback":
206-
return DataCategory.Feedback;
208+
return Collections.singletonList(DataCategory.Feedback);
207209
case "log":
208-
return DataCategory.LogItem;
210+
return Collections.singletonList(DataCategory.LogItem);
209211
default:
210-
return DataCategory.Unknown;
212+
return Collections.singletonList(DataCategory.Unknown);
211213
}
212214
}
213215

0 commit comments

Comments
 (0)