public class CozeLoopTracerProvider extends Object
This class provides a bridge between CozeLoop SDK and OpenTelemetry, managing the complete trace lifecycle from span creation to export. It configures and initializes the OpenTelemetry SDK with OTLP/HTTP exporter and BatchSpanProcessor.
Architecture Overview:
Context Propagation: The TracerProvider automatically handles OpenTelemetry context propagation, ensuring that trace context (trace ID, span ID, baggage) is automatically propagated to child spans within the same thread and across async boundaries.
Example Usage:
TraceConfig config = TraceConfig.builder()
.maxQueueSize(2048)
.batchSize(512)
.scheduleDelayMillis(5000)
.exportTimeoutMillis(30000)
.build();
CozeLoopTracerProvider provider = CozeLoopTracerProvider.create(
spanEndpoint, workspaceId, serviceName, config);
Tracer tracer = provider.getTracer("my-instrumentation");
Shutdown: Always call shutdown() when the application is shutting down to
ensure all pending spans are flushed and exported:
provider.shutdown(); // Flushes and exports all pending spans
BatchSpanProcessor,
CozeLoopSpanExporter| Modifier and Type | Class and Description |
|---|---|
static class |
CozeLoopTracerProvider.TraceConfig
Trace configuration for OpenTelemetry BatchSpanProcessor.
|
| Modifier and Type | Method and Description |
|---|---|
static CozeLoopTracerProvider |
create(Auth auth,
String spanEndpoint,
String workspaceId,
String serviceName,
CozeLoopTracerProvider.TraceConfig config)
Create a new CozeLoopTracerProvider.
|
void |
flush()
Force flush all pending spans.
|
FinishEventProcessor |
getFinishEventProcessor() |
io.opentelemetry.context.propagation.ContextPropagators |
getPropagators()
Get the ContextPropagators configured for this SDK.
|
io.opentelemetry.api.trace.Tracer |
getTracer(String instrumentationName,
String instrumentationVersion)
Get a Tracer for creating spans.
|
io.opentelemetry.api.trace.TracerProvider |
getTracerProvider()
Get the underlying OpenTelemetry TracerProvider.
|
void |
shutdown()
Shutdown the tracer provider and flush all pending spans.
|
public FinishEventProcessor getFinishEventProcessor()
public static CozeLoopTracerProvider create(Auth auth, String spanEndpoint, String workspaceId, String serviceName, CozeLoopTracerProvider.TraceConfig config)
auth - the authentication providerspanEndpoint - the span upload endpointworkspaceId - the workspace IDserviceName - the service nameconfig - the trace configuration (includes optional FinishEventProcessor)public io.opentelemetry.context.propagation.ContextPropagators getPropagators()
public io.opentelemetry.api.trace.Tracer getTracer(String instrumentationName, String instrumentationVersion)
The instrumentation name identifies the library or framework that is creating spans. This helps organize spans in the CozeLoop platform.
Example:
Tracer tracer = provider.getTracer("my-application", "1.0.0");
Span span = tracer.spanBuilder("operation").startSpan();
instrumentationName - the name of the instrumentation library (e.g., "cozeloop-java-sdk",
"my-application")public io.opentelemetry.api.trace.TracerProvider getTracerProvider()
This provides direct access to the OpenTelemetry TracerProvider for advanced use cases that require OpenTelemetry-specific APIs.
Example:
TracerProvider provider = tracerProvider.getTracerProvider();
// Use OpenTelemetry APIs directly
public void flush()
public void shutdown()
This method should be called when the application is shutting down to ensure:
Important: After shutdown, the TracerProvider cannot be used again. You must create a new instance if needed.
The shutdown process:
Example:
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
tracerProvider.shutdown();
}));
Copyright © 2026. All rights reserved.