Package com.ants.platform.tracing
Class Ants
java.lang.Object
com.ants.platform.tracing.Ants
High-level entry point for Agentic Ants tracing, mirroring the JS
startObservation / startActiveObservation / observe /
updateActiveTrace surface.
Call AntsPlatformOtel.configure(com.ants.platform.otel.AntsPlatformSpanProcessor.Builder) once at startup, then:
Ants.startActiveObservation("research-agent", ObservationType.AGENT, agent -> {
agent.input(question);
agent.updateTrace(TraceAttributes.builder().name("research").userId("u1").build());
AntsGeneration gen = Ants.startGeneration("draft-answer")
.model("gpt-4o-mini").input(question);
gen.output(answer).usage(120, 80).end();
AntsObservation tool = Ants.startObservation("web-search", ObservationType.TOOL);
tool.input(query).output(results).end();
agent.output(answer);
});
AntsPlatformOtel.flush();
-
Method Summary
Modifier and TypeMethodDescriptionstatic AntsObservationReturns a fluent view over the currently active span, ornullif none.static <T> Tobserve(String name, ObservationType type, Function<AntsObservation, T> fn) Runsfnwith a new active observation and returns its result.static <T> TobserveGeneration(String name, Function<AntsGeneration, T> fn) static voidstartActiveGeneration(String name, Consumer<AntsGeneration> fn) Active variant for generations.static voidstartActiveObservation(String name, ObservationType type, Consumer<AntsObservation> fn) Runsfnwith a new observation set as the active span, so any observations created inside nest under it automatically.static AntsGenerationstartGeneration(String name) Starts ageneration, nested under the current active span if any.static AntsGenerationstartGeneration(String name, AntsObservation parent) Starts agenerationexplicitly parented toparent.static AntsObservationstartObservation(String name) Starts aspan, nested under the current active span if any.static AntsObservationstartObservation(String name, ObservationType type) Starts an observation of the given type, nested under the current active span if any.static AntsObservationstartObservation(String name, ObservationType type, AntsObservation parent) Starts an observation explicitly parented toparent.static io.opentelemetry.api.trace.Tracertracer()The Ants OpenTelemetry tracer (from the globally-registered provider).static voidupdateActiveTrace(TraceAttributes attrs) Sets trace-level attributes on the currently active span.
-
Method Details
-
tracer
public static io.opentelemetry.api.trace.Tracer tracer()The Ants OpenTelemetry tracer (from the globally-registered provider). -
startObservation
Starts aspan, nested under the current active span if any. -
startObservation
Starts an observation of the given type, nested under the current active span if any. -
startObservation
public static AntsObservation startObservation(String name, ObservationType type, AntsObservation parent) Starts an observation explicitly parented toparent. -
startGeneration
Starts ageneration, nested under the current active span if any. -
startGeneration
Starts agenerationexplicitly parented toparent. -
startActiveObservation
public static void startActiveObservation(String name, ObservationType type, Consumer<AntsObservation> fn) Runsfnwith a new observation set as the active span, so any observations created inside nest under it automatically. The span is ended whenfnreturns (or throws, recording the error). -
startActiveGeneration
Active variant for generations. -
observe
Runsfnwith a new active observation and returns its result. Ends the span on completion; on exception, records the error and rethrows. -
observeGeneration
-
updateActiveTrace
Sets trace-level attributes on the currently active span. -
currentObservation
Returns a fluent view over the currently active span, ornullif none.
-