Package com.tnsai.llm.observability
Record Class LLMCallLog
java.lang.Object
java.lang.Record
com.tnsai.llm.observability.LLMCallLog
public record LLMCallLog(String callId, Instant startedAt, Instant completedAt, Duration elapsed, String provider, String model, String endpoint, com.tnsai.observability.events.EventContext context, LLMPrompt prompt, ToolSurface tools, LLMResponse response, TokenUsage usage, CostEstimate cost, com.tnsai.llm.ChatChunk.FinishReason finishReason, Optional<StreamMetrics> streamMetrics, Optional<ErrorInfo> error, int retryAttempt, Map<String,Object> providerExtensions)
extends Record
One observed LLM call, end-to-end (issue #79).
Captures everything an operator needs to answer the "what happened on this call?" questions:
- Routing — which provider + model + endpoint
- Identity — which tenant / agent / capability called
(
EventContext) - Input — the typed
LLMPrompt+ToolSurface - Output — typed
LLMResponse+TokenUsage+CostEstimate+ChatChunk.FinishReason - Stream timing — optional
StreamMetricsfor streaming calls (TTFT, inter-chunk percentiles) - Errors — optional
ErrorInfofor failed calls, plusretryAttemptcount - Provider-specific extensions — opaque bag for things that don't fit the typed shape (Anthropic stop_reason variants, OpenAI request fingerprints, etc.)
This record is the data shape only. Wiring it into
AbstractLLMClient so every provider auto-emits one per call
is a focused follow-up — that change touches every provider's
chat / streamChat hot path and deserves its own PR
with regression tests. Same goes for the Prometheus derivation +
SLF4J / OTel publication path.
Privacy: the record holds raw prompt + response text. Production deployments must route this through the redaction SPI (issue #80, not yet built) before persisting or shipping to external trackers (LangFuse, Helicone, Phoenix). The capture wrapper is responsible for that — this record itself stays unaware of redaction.
- Since:
- 0.5.0 (issue #79)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMutable builder — collects fields as the call executes (start → response → finish), then produces the immutable record. -
Constructor Summary
ConstructorsConstructorDescriptionLLMCallLog(String callId, Instant startedAt, Instant completedAt, Duration elapsed, String provider, String model, String endpoint, com.tnsai.observability.events.EventContext context, LLMPrompt prompt, ToolSurface tools, LLMResponse response, TokenUsage usage, CostEstimate cost, com.tnsai.llm.ChatChunk.FinishReason finishReason, Optional<StreamMetrics> streamMetrics, Optional<ErrorInfo> error, int retryAttempt, Map<String, Object> providerExtensions) Creates an instance of aLLMCallLogrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic LLMCallLog.Builderbuilder()Returns a builder pre-populated with the minimum required fields.callId()Returns the value of thecallIdrecord component.Returns the value of thecompletedAtrecord component.com.tnsai.observability.events.EventContextcontext()Returns the value of thecontextrecord component.cost()Returns the value of thecostrecord component.elapsed()Returns the value of theelapsedrecord component.endpoint()Returns the value of theendpointrecord component.final booleanIndicates whether some other object is "equal to" this one.error()Returns the value of theerrorrecord component.com.tnsai.llm.ChatChunk.FinishReasonReturns the value of thefinishReasonrecord component.final inthashCode()Returns a hash code value for this object.booleantruewhen this call ended inErrorInfo.booleantruewhen streaming-specific metrics were recorded.model()Returns the value of themodelrecord component.prompt()Returns the value of thepromptrecord component.provider()Returns the value of theproviderrecord component.Returns the value of theproviderExtensionsrecord component.Stable identifier of the(provider, model)pair — useful as a Prometheus label and as a dashboard group key.response()Returns the value of theresponserecord component.intReturns the value of theretryAttemptrecord component.Returns the value of thestartedAtrecord component.Returns the value of thestreamMetricsrecord component.tools()Returns the value of thetoolsrecord component.final StringtoString()Returns a string representation of this record class.usage()Returns the value of theusagerecord component.
-
Constructor Details
-
LLMCallLog
public LLMCallLog(String callId, Instant startedAt, Instant completedAt, Duration elapsed, String provider, String model, String endpoint, com.tnsai.observability.events.EventContext context, LLMPrompt prompt, ToolSurface tools, LLMResponse response, TokenUsage usage, CostEstimate cost, com.tnsai.llm.ChatChunk.FinishReason finishReason, Optional<StreamMetrics> streamMetrics, Optional<ErrorInfo> error, int retryAttempt, Map<String, Object> providerExtensions) Creates an instance of aLLMCallLogrecord class.- Parameters:
callId- the value for thecallIdrecord componentstartedAt- the value for thestartedAtrecord componentcompletedAt- the value for thecompletedAtrecord componentelapsed- the value for theelapsedrecord componentprovider- the value for theproviderrecord componentmodel- the value for themodelrecord componentendpoint- the value for theendpointrecord componentcontext- the value for thecontextrecord componentprompt- the value for thepromptrecord componenttools- the value for thetoolsrecord componentresponse- the value for theresponserecord componentusage- the value for theusagerecord componentcost- the value for thecostrecord componentfinishReason- the value for thefinishReasonrecord componentstreamMetrics- the value for thestreamMetricsrecord componenterror- the value for theerrorrecord componentretryAttempt- the value for theretryAttemptrecord componentproviderExtensions- the value for theproviderExtensionsrecord component
-
-
Method Details
-
isFailure
public boolean isFailure()truewhen this call ended inErrorInfo. -
isStreamed
public boolean isStreamed()truewhen streaming-specific metrics were recorded. -
providerModel
Stable identifier of the(provider, model)pair — useful as a Prometheus label and as a dashboard group key. -
builder
Returns a builder pre-populated with the minimum required fields. Callers fill in input / output / cost as the call progresses. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
callId
Returns the value of thecallIdrecord component.- Returns:
- the value of the
callIdrecord component
-
startedAt
Returns the value of thestartedAtrecord component.- Returns:
- the value of the
startedAtrecord component
-
completedAt
Returns the value of thecompletedAtrecord component.- Returns:
- the value of the
completedAtrecord component
-
elapsed
Returns the value of theelapsedrecord component.- Returns:
- the value of the
elapsedrecord component
-
provider
Returns the value of theproviderrecord component.- Returns:
- the value of the
providerrecord component
-
model
Returns the value of themodelrecord component.- Returns:
- the value of the
modelrecord component
-
endpoint
Returns the value of theendpointrecord component.- Returns:
- the value of the
endpointrecord component
-
context
public com.tnsai.observability.events.EventContext context()Returns the value of thecontextrecord component.- Returns:
- the value of the
contextrecord component
-
prompt
Returns the value of thepromptrecord component.- Returns:
- the value of the
promptrecord component
-
tools
Returns the value of thetoolsrecord component.- Returns:
- the value of the
toolsrecord component
-
response
Returns the value of theresponserecord component.- Returns:
- the value of the
responserecord component
-
usage
Returns the value of theusagerecord component.- Returns:
- the value of the
usagerecord component
-
cost
Returns the value of thecostrecord component.- Returns:
- the value of the
costrecord component
-
finishReason
public com.tnsai.llm.ChatChunk.FinishReason finishReason()Returns the value of thefinishReasonrecord component.- Returns:
- the value of the
finishReasonrecord component
-
streamMetrics
Returns the value of thestreamMetricsrecord component.- Returns:
- the value of the
streamMetricsrecord component
-
error
Returns the value of theerrorrecord component.- Returns:
- the value of the
errorrecord component
-
retryAttempt
public int retryAttempt()Returns the value of theretryAttemptrecord component.- Returns:
- the value of the
retryAttemptrecord component
-
providerExtensions
Returns the value of theproviderExtensionsrecord component.- Returns:
- the value of the
providerExtensionsrecord component
-