Class AntsObservation

java.lang.Object
com.ants.platform.tracing.AntsObservation
Direct Known Subclasses:
AntsGeneration

public class AntsObservation extends Object
A thin, fluent wrapper over an OpenTelemetry Span that writes the Ants-specific attributes the backend maps to observations.

Mirrors the JS AntsPlatformSpan / Python AntsPlatformSpan wrappers. Setters write attributes immediately and return this for chaining. Specialized generation behaviour lives in AntsGeneration.

Create observations via Ants.startObservation(java.lang.String) / Ants.startActiveObservation(java.lang.String, com.ants.platform.tracing.ObservationType, java.util.function.Consumer<com.ants.platform.tracing.AntsObservation>), or nest them with startChild(String, ObservationType).

  • Field Details

    • otelSpan

      protected final io.opentelemetry.api.trace.Span otelSpan
  • Method Details

    • otelSpan

      public io.opentelemetry.api.trace.Span otelSpan()
      The underlying OpenTelemetry span.
    • traceId

      public String traceId()
      The trace id (32-char hex) this observation belongs to.
    • id

      public String id()
      The observation id (16-char hex span id).
    • type

      public ObservationType type()
      The observation type.
    • input

      public AntsObservation input(Object input)
      Sets the observation input (serialized to JSON).
    • output

      public AntsObservation output(Object output)
      Sets the observation output (serialized to JSON).
    • metadata

      public AntsObservation metadata(Object metadata)
      Sets observation metadata. A map is flattened to one attribute per top-level key (ants-platform.observation.metadata.<key>), matching the other SDKs; anything else is serialized whole.
    • level

      public AntsObservation level(String level)
      Sets the observation level (e.g. DEBUG, DEFAULT, WARNING, ERROR).
    • statusMessage

      public AntsObservation statusMessage(String statusMessage)
      Sets a human-readable status message (typically with level("ERROR")).
    • version

      public AntsObservation version(String version)
      Sets a version identifier for the code/model being traced.
    • recordError

      public AntsObservation recordError(Throwable error)
      Records an error on this observation: sets the OTel status to ERROR, level=ERROR and a status message, and records the exception.
    • updateTrace

      public AntsObservation updateTrace(TraceAttributes attrs)
      Updates trace-level attributes on this observation's span.
    • startChild

      public AntsObservation startChild(String name, ObservationType childType)
      Starts a child observation parented to this one. The child nests under this span regardless of the current OTel context.
    • startChildGeneration

      public AntsGeneration startChildGeneration(String name)
      Starts a child generation parented to this observation.
    • end

      public void end()
      Ends the observation at the current time.
    • end

      public void end(Instant endTime)
      Ends the observation at an explicit instant.