Skip to content

Commit 084958d

Browse files
committed
support config span queue
1 parent 082cda1 commit 084958d

3 files changed

Lines changed: 62 additions & 9 deletions

File tree

cozeloop-core/src/main/java/com/coze/loop/client/CozeLoopClientBuilder.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,53 @@ public CozeLoopClientBuilder finishEventProcessor(FinishEventProcessor processor
188188
return this;
189189
}
190190

191+
/**
192+
* Set maximum span queue size (default: 1024). When the queue is full, new spans will be dropped.
193+
*
194+
* @param size maximum queue size
195+
* @return this builder
196+
*/
197+
public CozeLoopClientBuilder maxSpanExportQueueSize(int size) {
198+
config.getTraceConfig().setMaxQueueSize(size);
199+
return this;
200+
}
201+
202+
/**
203+
* Set maximum span export batch size (default: 100). This is the maximum number of spans sent to
204+
* the exporter in a single batch.
205+
*
206+
* @param size maximum batch size
207+
* @return this builder
208+
*/
209+
public CozeLoopClientBuilder maxSpanExportBatchSize(int size) {
210+
config.getTraceConfig().setBatchSize(size);
211+
return this;
212+
}
213+
214+
/**
215+
* Set span exporter timeout in milliseconds (default: 3000). This is the maximum time to wait for
216+
* the export to complete.
217+
*
218+
* @param timeoutMillis timeout in milliseconds
219+
* @return this builder
220+
*/
221+
public CozeLoopClientBuilder spanExportTimeout(long timeoutMillis) {
222+
config.getTraceConfig().setExportTimeoutMillis(timeoutMillis);
223+
return this;
224+
}
225+
226+
/**
227+
* Set schedule delay between batch exports in milliseconds (default: 1000). This is the time
228+
* interval between automatic batch exports.
229+
*
230+
* @param delayMillis delay in milliseconds
231+
* @return this builder
232+
*/
233+
public CozeLoopClientBuilder spanExportScheduleDelay(long delayMillis) {
234+
config.getTraceConfig().setScheduleDelayMillis(delayMillis);
235+
return this;
236+
}
237+
191238
/**
192239
* Build the CozeLoopClient instance.
193240
*

cozeloop-core/src/main/java/com/coze/loop/trace/CozeLoopTracerProvider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,17 @@ public void shutdown() {
335335
* </ul>
336336
*/
337337
public static class TraceConfig {
338-
/** Maximum number of spans in the queue before dropping (default: 2048) */
339-
private int maxQueueSize = 2048;
338+
/** Maximum number of spans in the queue before dropping (default: 1024) */
339+
private int maxQueueSize = 1024;
340340

341-
/** Maximum spans per batch sent to exporter (default: 512) */
342-
private int batchSize = 512;
341+
/** Maximum spans per batch sent to exporter (default: 100) */
342+
private int batchSize = 100;
343343

344-
/** Delay between automatic batch exports in milliseconds (default: 5000) */
345-
private long scheduleDelayMillis = 5000;
344+
/** Delay between automatic batch exports in milliseconds (default: 1000) */
345+
private long scheduleDelayMillis = 1000;
346346

347-
/** Timeout for export operations in milliseconds (default: 30000) */
348-
private long exportTimeoutMillis = 30000;
347+
/** Timeout for export operations in milliseconds (default: 3000) */
348+
private long exportTimeoutMillis = 3000;
349349

350350
/** Finish event processor for span finish events */
351351
private FinishEventProcessor finishEventProcessor;

examples/src/main/java/trace/simple/SimpleTraceExample.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ public static void main(String[] args) {
3535
}
3636

3737
// workspaceId and apiToken from env are set to client automatically
38-
CozeLoopClient client = new CozeLoopClientBuilder().build();
38+
CozeLoopClient client =
39+
new CozeLoopClientBuilder()
40+
.spanExportTimeout(3000) // export timeout in milliseconds, default is 3000
41+
.spanExportScheduleDelay(1000) // schedule delay in milliseconds, default is 1000
42+
.maxSpanExportQueueSize(1024) // maximum queue size, default is 1024
43+
.maxSpanExportBatchSize(100) // maximum batch size, default is 100
44+
.build();
3945

4046
try {
4147
// 1. 创建根 span

0 commit comments

Comments
 (0)