Class TenantPolicySamplingPolicy

java.lang.Object
com.tnsai.quality.sampling.TenantPolicySamplingPolicy
All Implemented Interfaces:
EventSamplingPolicy

public final class TenantPolicySamplingPolicy extends Object implements EventSamplingPolicy
EventSamplingPolicy that dispatches each call to a per-tenant policy based on EventContext.tenantId() (issue #82).

Mirrors TenantPolicyRedactor's shape — every call resolves the active policy from the framework's correlation context. A multi-tenant agent group can therefore apply different sampling rates per tenant without the publisher needing to know tenant boundaries:


 EventSamplingPolicy dispatcher = TenantPolicySamplingPolicy.builder()
         .tenant("acme",   SamplingPolicies.verbose())            // power user — keep everything
         .tenant("globex", new ErrorAlwaysPolicy(0.001))          // chatty — aggressive sampling
         .defaultPolicy(SamplingPolicies.production())            // everyone else
         .build();

 AgentEventPublisher publisher = new SamplingAgentEventPublisher(slf4j, dispatcher);
 

Resolution order:

  1. EventContext.tenantId() — explicit tenant from the framework's correlation context
  2. Configured default policy — fallback for unmatched / null / blank tenant ids

Composition: per-tenant values are themselves EventSamplingPolicys, so operators can compose nested dispatch — e.g. wrap each per-tenant policy in something tail-based later without changing the dispatcher.

Thread-safety: registry is immutable after construction; dispatch is a single Map.get on each call. Per-tenant policies must themselves be thread-safe (the SPI requires it).

Since:
0.9.0 (issue #82)