@@ -58,16 +58,19 @@ public <T extends CoreSpan<T>> void setSamplingPriority(final T span) {
5858
5959 final RateSamplersByEnvAndService rates = serviceRates ;
6060 RateSampler sampler = rates .getSampler (env , serviceName );
61+ boolean sampled = sampler .sample (span );
62+ int samplingPriority = sampled ? PrioritySampling .SAMPLER_KEEP : PrioritySampling .SAMPLER_DROP ;
6163
62- if (sampler . sample ( span )) {
64+ if (rates . hasAgentRates ( )) {
6365 span .setSamplingPriority (
64- PrioritySampling . SAMPLER_KEEP ,
66+ samplingPriority ,
6567 SAMPLING_AGENT_RATE ,
6668 sampler .getSampleRate (),
67- SamplingMechanism .AGENT_RATE );
69+ SamplingMechanism .AGENT_RATE ,
70+ sampled );
6871 } else {
6972 span .setSamplingPriority (
70- PrioritySampling . SAMPLER_DROP ,
73+ samplingPriority ,
7174 SAMPLING_AGENT_RATE ,
7275 sampler .getSampleRate (),
7376 SamplingMechanism .AGENT_RATE );
@@ -161,7 +164,7 @@ public void onResponse(
161164 if (canIncrease && anyCapped ) {
162165 lastCappedNanos = now ;
163166 }
164- serviceRates = new RateSamplersByEnvAndService (updatedEnvServiceRates , fallbackSampler );
167+ serviceRates = new RateSamplersByEnvAndService (updatedEnvServiceRates , fallbackSampler , true );
165168 }
166169
167170 private static RateSampler createRateSampler (final double sampleRate ) {
@@ -183,15 +186,23 @@ private static final class RateSamplersByEnvAndService {
183186
184187 private final Map <String , TreeMap <String , RateSampler >> envServiceRates ;
185188 private final RateSampler fallbackSampler ;
189+ private final boolean hasAgentRates ;
186190
187191 RateSamplersByEnvAndService () {
188- this (Collections .emptyMap (), DEFAULT_SAMPLER );
192+ this (Collections .emptyMap (), DEFAULT_SAMPLER , false );
189193 }
190194
191195 RateSamplersByEnvAndService (
192- Map <String , TreeMap <String , RateSampler >> envServiceRates , RateSampler fallbackSampler ) {
196+ Map <String , TreeMap <String , RateSampler >> envServiceRates ,
197+ RateSampler fallbackSampler ,
198+ boolean hasAgentRates ) {
193199 this .envServiceRates = envServiceRates ;
194200 this .fallbackSampler = fallbackSampler ;
201+ this .hasAgentRates = hasAgentRates ;
202+ }
203+
204+ boolean hasAgentRates () {
205+ return hasAgentRates ;
195206 }
196207
197208 RateSampler getFallbackSampler () {
0 commit comments