Class RedactingAgentEventPublisher

java.lang.Object
com.tnsai.quality.redaction.RedactingAgentEventPublisher
All Implemented Interfaces:
com.tnsai.observability.events.AgentEventPublisher

public final class RedactingAgentEventPublisher extends Object implements com.tnsai.observability.events.AgentEventPublisher
AgentEventPublisher decorator that scrubs PII / secrets out of every event before delegating (issue #80, sink integration #2 of 6).

Why a decorator: keeps the AgentEventPublisher SPI in tnsai-core unchanged. Redaction is opt-in by wrapping:


 AgentEventPublisher slf4j = new Slf4jAgentEventPublisher();
 AgentEventPublisher redacted = new RedactingAgentEventPublisher(
         slf4j, PatternRedactor.withDefaults());
 

What gets scrubbed: every event variant carries at least one field that can leak user input — the decorator rebuilds each record with redacted values. Map / List / arbitrary-Object fields route through Redactor.scrubValue(java.lang.Object, com.tnsai.quality.redaction.RedactionContext) which walks recursively. Pure-metadata events (event-id, timestamps, run-ids, agent-names) pass straight through.

Per-variant rebuild is verbose but mechanical, and Java 21's exhaustive pattern switch keeps it future-proof: a new variant added to the TnsAIEvent sealed hierarchy fails to compile here until handled, so we can't accidentally leak through a forgotten branch.

Thread-safety: delegates to the underlying publisher; the decorator itself is stateless beyond holding the immutable delegate + redactor + context supplier.

Since:
0.9.0 (issue #80, sink integration #2 of 6)
  • Constructor Summary

    Constructors
    Constructor
    Description
    RedactingAgentEventPublisher(com.tnsai.observability.events.AgentEventPublisher delegate, Redactor redactor)
    Wrap delegate with redaction using redactor, passing EventContext.empty() on every scrub call.
    RedactingAgentEventPublisher(com.tnsai.observability.events.AgentEventPublisher delegate, Redactor redactor, Supplier<com.tnsai.observability.events.EventContext> contextSupplier)
    Wrap delegate with redaction using redactor and a contextSupplier that returns the EventContext to attach to each scrub call.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    isEnabled(com.tnsai.observability.events.EventLevel level)
     
    void
    publish(com.tnsai.events.TnsAIEvent event)
     
    void
    publish(com.tnsai.events.TnsAIEvent event, com.tnsai.observability.events.EventLevel level, com.tnsai.observability.events.EventContext context)
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RedactingAgentEventPublisher

      public RedactingAgentEventPublisher(com.tnsai.observability.events.AgentEventPublisher delegate, Redactor redactor)
      Wrap delegate with redaction using redactor, passing EventContext.empty() on every scrub call.
    • RedactingAgentEventPublisher

      public RedactingAgentEventPublisher(com.tnsai.observability.events.AgentEventPublisher delegate, Redactor redactor, Supplier<com.tnsai.observability.events.EventContext> contextSupplier)
      Wrap delegate with redaction using redactor and a contextSupplier that returns the EventContext to attach to each scrub call.
      Throws:
      NullPointerException - if any arg is null
  • Method Details

    • publish

      public void publish(com.tnsai.events.TnsAIEvent event)
      Specified by:
      publish in interface com.tnsai.observability.events.AgentEventPublisher
    • publish

      public void publish(com.tnsai.events.TnsAIEvent event, com.tnsai.observability.events.EventLevel level, com.tnsai.observability.events.EventContext context)
      Specified by:
      publish in interface com.tnsai.observability.events.AgentEventPublisher
    • isEnabled

      public boolean isEnabled(com.tnsai.observability.events.EventLevel level)
      Specified by:
      isEnabled in interface com.tnsai.observability.events.AgentEventPublisher