Skip to content

Commit

Permalink
Fix flush on JVM shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Nov 10, 2023
1 parent a367610 commit 6f7c523
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
- [Fix flush on JVM shutdown](https://github.com/Azure/azure-sdk-for-java/pull/37618)

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public CompletableResultCode send(List<TelemetryItem> telemetryItems) {
for (Map.Entry<TelemetryItemBatchKey, List<TelemetryItem>> batch : batches.entrySet()) {
resultCodeList.add(internalSendByBatch(batch.getKey(), batch.getValue()));
}
return maybeAddToActiveExportResults(resultCodeList);
maybeAddToActiveExportResults(resultCodeList);
return CompletableResultCode.ofAll(resultCodeList);
}

// visible for tests
Expand All @@ -106,14 +107,13 @@ Map<TelemetryItemBatchKey, List<TelemetryItem>> splitIntoBatches(
return groupings;
}

private CompletableResultCode maybeAddToActiveExportResults(List<CompletableResultCode> results) {
private void maybeAddToActiveExportResults(List<CompletableResultCode> results) {
if (activeExportResults.size() >= MAX_CONCURRENT_EXPORTS) {
// this is just a failsafe to limit concurrent exports, it's not ideal because it blocks
// waiting for the most recent export instead of waiting for the first export to return
operationLogger.recordFailure(
"Hit max " + MAX_CONCURRENT_EXPORTS + " active concurrent requests",
TELEMETRY_ITEM_EXPORTER_ERROR);
return CompletableResultCode.ofAll(results);
}

operationLogger.recordSuccess();
Expand All @@ -122,8 +122,6 @@ private CompletableResultCode maybeAddToActiveExportResults(List<CompletableResu
for (CompletableResultCode result : results) {
result.whenComplete(() -> activeExportResults.remove(result));
}

return CompletableResultCode.ofSuccess();
}

public CompletableResultCode flush() {
Expand Down

0 comments on commit 6f7c523

Please sign in to comment.