Skip to content

Commit f58deff

Browse files
authored
Merge pull request #179 from braintrustdata/ark/SDK-355-attachment-upload-regression
s3 attachment-processor improvements
2 parents 7dbd053 + 0fcf486 commit f58deff

6 files changed

Lines changed: 1068 additions & 176 deletions

File tree

‎braintrust-sdk/src/main/java/dev/braintrust/config/BraintrustConfig.java‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,30 @@ public final class BraintrustConfig extends BaseConfig {
5858
private final Boolean autoConvertAIAttachments =
5959
getConfig("BRAINTRUST_AUTO_CONVERT_AI_ATTACHMENTS", true);
6060

61+
/** Maximum number of attachment uploads waiting for the background uploader. */
62+
private final int attachmentUploaderQueueSize =
63+
assertPositive(getConfig("BRAINTRUST_ATTACHMENT_UPLOADER_QUEUE_SIZE", 1024));
64+
65+
/** Per-request timeout for attachment upload HTTP calls. */
66+
private final Duration attachmentUploaderRequestTimeout =
67+
Duration.ofMillis(
68+
assertPositive(
69+
getConfig(
70+
"BRAINTRUST_ATTACHMENT_UPLOADER_REQUEST_TIMEOUT_MILLIS",
71+
60_000)));
72+
73+
/** Maximum number of retries for transient attachment upload failures. */
74+
private final int attachmentUploaderMaxRetries =
75+
assertPositive(getConfig("BRAINTRUST_ATTACHMENT_UPLOADER_MAX_RETRIES", 8));
76+
77+
/** Initial attachment upload retry delay. The uploader doubles it after each failure. */
78+
private final Duration attachmentUploaderInitialRetryDelay =
79+
Duration.ofMillis(
80+
assertPositive(
81+
getConfig(
82+
"BRAINTRUST_ATTACHMENT_UPLOADER_INITIAL_RETRY_DELAY_MILLIS",
83+
500)));
84+
6185
/** Custom SSL context for OTLP exporter. Builder-only field, not backed by envars. */
6286
private final SSLContext sslContext;
6387

@@ -288,6 +312,32 @@ public Builder autoConvertAIAttachments(boolean value) {
288312
return this;
289313
}
290314

315+
public Builder attachmentUploaderQueueSize(int queueSize) {
316+
envOverrides.put(
317+
"BRAINTRUST_ATTACHMENT_UPLOADER_QUEUE_SIZE", String.valueOf(queueSize));
318+
return this;
319+
}
320+
321+
public Builder attachmentUploaderRequestTimeout(Duration requestTimeout) {
322+
envOverrides.put(
323+
"BRAINTRUST_ATTACHMENT_UPLOADER_REQUEST_TIMEOUT_MILLIS",
324+
String.valueOf(requestTimeout.toMillis()));
325+
return this;
326+
}
327+
328+
public Builder attachmentUploaderMaxRetries(int maxRetries) {
329+
envOverrides.put(
330+
"BRAINTRUST_ATTACHMENT_UPLOADER_MAX_RETRIES", String.valueOf(maxRetries));
331+
return this;
332+
}
333+
334+
public Builder attachmentUploaderInitialRetryDelay(Duration initialRetryDelay) {
335+
envOverrides.put(
336+
"BRAINTRUST_ATTACHMENT_UPLOADER_INITIAL_RETRY_DELAY_MILLIS",
337+
String.valueOf(initialRetryDelay.toMillis()));
338+
return this;
339+
}
340+
291341
public Builder sslContext(SSLContext value) {
292342
this.sslContext = value;
293343
return this;

‎braintrust-sdk/src/main/java/dev/braintrust/trace/AttachmentProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static Pattern buildHeuristic() {
140140
String processAndUpload(String json) {
141141
if ((!config.autoConvertAIAttachments())
142142
|| json == null
143-
|| uploader.isShutdown()
143+
|| !uploader.isAcceptingJobs()
144144
|| !BASE64_HEURISTIC.matcher(json).find()) {
145145
return json;
146146
}

0 commit comments

Comments
 (0)