Skip to content

Commit 0aaea5e

Browse files
authored
Improve disk buffering example to retry exporting unsuccessfully exported batches (#2539)
1 parent 5438ce6 commit 0aaea5e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

disk-buffering/README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,24 @@ In order to read data, we can iterate through our signal storage objects and the
108108
a network exporter, as shown in the example for spans below.
109109

110110
```java
111-
// Example of reading an exporting spans from disk
112-
OtlpHttpSpanExporter networkExporter;
113-
Iterator<Collection<SpanData>> spanCollections = spanStorage.iterator();
114-
while(spanCollections.hasNext()){
115-
networkExporter.export(spanCollections.next());
111+
/**
112+
* Example of reading and exporting spans from disk.
113+
*
114+
* @return true, if the exporting was successful, false, if it needs to be retried
115+
*/
116+
public boolean exportSpansFromDisk(SpanExporter networkExporter, long timeout) {
117+
for (Collection<SpanData> spanData : spanStorage) {
118+
CompletableResultCode resultCode = networkExporter.export(spanData);
119+
resultCode.join(timeout, TimeUnit.MILLISECONDS);
120+
121+
if (!resultCode.isSuccess()) {
122+
logger.trace("Error while exporting", resultCode.getFailureThrowable());
123+
// The iteration should be aborted here to avoid consuming batches, which were not exported successfully
124+
return false;
125+
}
126+
}
127+
logger.trace("Finished exporting");
128+
return true;
116129
}
117130
```
118131

0 commit comments

Comments
 (0)