Created
January 18, 2018 11:48
-
-
Save ScienJus/9b7804ed56c58f7bb0c90fbb9913a1c1 to your computer and use it in GitHub Desktop.
Custom sampler for special api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.scienjus.spring.cloud.sleuth; | |
import lombok.Data; | |
import org.springframework.boot.context.properties.ConfigurationProperties; | |
import java.util.List; | |
@Data | |
@ConfigurationProperties("spring.sleuth.sampler") | |
public class SleuthSamplerProperties { | |
private List<String> whitelist; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.scienjus.spring.cloud.sleuth; | |
import org.apache.commons.collections4.CollectionUtils; | |
import org.springframework.cloud.sleuth.Span; | |
import org.springframework.cloud.sleuth.sampler.PercentageBasedSampler; | |
import org.springframework.cloud.sleuth.sampler.SamplerProperties; | |
import java.util.List; | |
public class SpanNameWhitelistSampler extends PercentageBasedSampler { | |
private final List<String> spanNameWhitelist; | |
public SpanNameWhitelistSampler(SamplerProperties config, SleuthSamplerProperties extension) { | |
super(config); | |
this.spanNameWhitelist = extension.getWhitelist(); | |
} | |
@Override | |
public boolean isSampled(Span currentSpan) { | |
String spanName = currentSpan.getName(); | |
if (CollectionUtils.isNotEmpty(spanNameWhitelist) && spanNameWhitelist.contains(spanName)) { | |
return true; | |
} | |
return super.isSampled(currentSpan); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment