Package com.tnsai.quality.sampling
Class SamplingLLMCallPublisher
java.lang.Object
com.tnsai.quality.sampling.SamplingLLMCallPublisher
- All Implemented Interfaces:
com.tnsai.llm.observability.LLMCallPublisher
public final class SamplingLLMCallPublisher
extends Object
implements com.tnsai.llm.observability.LLMCallPublisher
LLMCallPublisher decorator that consults an
EventSamplingPolicy before delegating each captured call
(TNS-417, follow-up to TNS-374).
Mirrors SamplingAgentEventPublisher for the
LLMCallPublisher SPI: keeps the SPI in tnsai-llm
unchanged, lets consumers opt in by wrapping. Reuses the existing
sampling policy machinery (head-based, rate-limited, error-always,
priority-based, …) — the bridge is constructed by mapping each
LLMCallLog into a SamplingInput:
- eventKind = "llm.called"
- level =
EventLevel.ERRORwhenLLMCallLog.isFailure(), otherwiseEventLevel.INFO. This is what makesErrorAlwaysPolicypass every failed call regardless of the tenant's nominal sample rate. - context =
LLMCallLog.context()(tenant, agent, capability, …) so tenant-aware policies can read tenant id.
Composition:
LLMCallPublisher otlp = ...;
LLMCallPublisher chain = new SamplingLLMCallPublisher(
new RedactingLLMCallPublisher(otlp, redactor),
SamplingPolicies.production());
Order matters: redaction inside, sampling outside, so calls that
survive sampling are already PII-safe and the redactor only pays
the cost of the events that actually ship downstream.
Thread-safety: stateless beyond the immutable delegate + policy. Policies are required by their SPI to be thread-safe.
- Since:
- 0.10.1 (TNS-417)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringStableSamplingInput.eventKind()value used for every captured LLM call.Fields inherited from interface com.tnsai.llm.observability.LLMCallPublisher
NOOP -
Constructor Summary
ConstructorsConstructorDescriptionSamplingLLMCallPublisher(com.tnsai.llm.observability.LLMCallPublisher delegate, EventSamplingPolicy policy) -
Method Summary
-
Field Details
-
EVENT_KIND
StableSamplingInput.eventKind()value used for every captured LLM call. Lets rule-based policies key off "llm.called" the same way they key off "tool.invoked" or "chat.chunk" forAgentEventPublisher.- See Also:
-
-
Constructor Details
-
SamplingLLMCallPublisher
public SamplingLLMCallPublisher(com.tnsai.llm.observability.LLMCallPublisher delegate, EventSamplingPolicy policy)
-
-
Method Details
-
publish
public void publish(com.tnsai.llm.observability.LLMCallLog call) - Specified by:
publishin interfacecom.tnsai.llm.observability.LLMCallPublisher
-