Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ public final class BraintrustConfig extends BaseConfig {
private final Boolean autoConvertAIAttachments =
getConfig("BRAINTRUST_AUTO_CONVERT_AI_ATTACHMENTS", true);

/** Maximum number of attachment uploads waiting for the background uploader. */
private final int attachmentUploaderQueueSize =
assertPositive(getConfig("BRAINTRUST_ATTACHMENT_UPLOADER_QUEUE_SIZE", 1024));

/** Per-request timeout for attachment upload HTTP calls. */
private final Duration attachmentUploaderRequestTimeout =
Duration.ofMillis(
assertPositive(
getConfig(
"BRAINTRUST_ATTACHMENT_UPLOADER_REQUEST_TIMEOUT_MILLIS",
60_000)));

/** Maximum number of retries for transient attachment upload failures. */
private final int attachmentUploaderMaxRetries =
assertPositive(getConfig("BRAINTRUST_ATTACHMENT_UPLOADER_MAX_RETRIES", 8));

/** Initial attachment upload retry delay. The uploader doubles it after each failure. */
private final Duration attachmentUploaderInitialRetryDelay =
Duration.ofMillis(
assertPositive(
getConfig(
"BRAINTRUST_ATTACHMENT_UPLOADER_INITIAL_RETRY_DELAY_MILLIS",
500)));

/** Custom SSL context for OTLP exporter. Builder-only field, not backed by envars. */
private final SSLContext sslContext;

Expand Down Expand Up @@ -288,6 +312,32 @@ public Builder autoConvertAIAttachments(boolean value) {
return this;
}

public Builder attachmentUploaderQueueSize(int queueSize) {
envOverrides.put(
"BRAINTRUST_ATTACHMENT_UPLOADER_QUEUE_SIZE", String.valueOf(queueSize));
return this;
}

public Builder attachmentUploaderRequestTimeout(Duration requestTimeout) {
envOverrides.put(
"BRAINTRUST_ATTACHMENT_UPLOADER_REQUEST_TIMEOUT_MILLIS",
String.valueOf(requestTimeout.toMillis()));
return this;
}

public Builder attachmentUploaderMaxRetries(int maxRetries) {
envOverrides.put(
"BRAINTRUST_ATTACHMENT_UPLOADER_MAX_RETRIES", String.valueOf(maxRetries));
return this;
}

public Builder attachmentUploaderInitialRetryDelay(Duration initialRetryDelay) {
envOverrides.put(
"BRAINTRUST_ATTACHMENT_UPLOADER_INITIAL_RETRY_DELAY_MILLIS",
String.valueOf(initialRetryDelay.toMillis()));
return this;
}

public Builder sslContext(SSLContext value) {
this.sslContext = value;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static Pattern buildHeuristic() {
String processAndUpload(String json) {
if ((!config.autoConvertAIAttachments())
|| json == null
|| uploader.isShutdown()
|| !uploader.isAcceptingJobs()
|| !BASE64_HEURISTIC.matcher(json).find()) {
return json;
}
Expand Down
Loading
Loading