use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.
the class AWSXRayServletFilter method fromSamplingStrategy.
private SamplingResponse fromSamplingStrategy(HttpServletRequest httpServletRequest) {
AWSXRayRecorder recorder = getRecorder();
SamplingRequest samplingRequest = new SamplingRequest(getSegmentName(httpServletRequest), getHost(httpServletRequest).orElse(null), httpServletRequest.getRequestURI(), httpServletRequest.getMethod(), recorder.getOrigin());
SamplingResponse sample = recorder.getSamplingStrategy().shouldTrace(samplingRequest);
return sample;
}
use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.
the class AWSXRayRecorder method beginSegmentWithSampling.
/**
* Begins a new segment after applying the configured sampling strategy. This method only uses the segment name and origin
* (if defined) to compute a sampling decision.
*
* @param name the segment name, to be used for the sampling decision
* @return Returns a proper segment if a sampled decision is made, and a no-op segment otherwise.
*/
public Segment beginSegmentWithSampling(String name) {
final SamplingRequest samplingRequest = new SamplingRequest(name, null, null, null, this.origin);
final SamplingResponse samplingResponse = this.getSamplingStrategy().shouldTrace(samplingRequest);
if (samplingResponse.isSampled()) {
Segment segment = beginSegment(name);
if (samplingResponse.getRuleName().isPresent()) {
segment.setRuleName(samplingResponse.getRuleName().get());
}
return segment;
} else if (this.getSamplingStrategy().isForcedSamplingSupported()) {
Segment segment = beginSegment(name);
segment.setSampled(false);
if (samplingResponse.getRuleName().isPresent()) {
segment.setRuleName(samplingResponse.getRuleName().get());
}
return segment;
}
return beginNoOpSegment();
}
use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testPositiveDefaultRuleMatch.
@Test
void testPositiveDefaultRuleMatch() {
Instant now = Instant.ofEpochSecond(1500000000);
CentralizedManifest manifest = new CentralizedManifest();
SamplingRule r2 = new SamplingRule().withRuleName(CentralizedRule.DEFAULT_RULE_NAME).withReservoirSize(20).withFixedRate(0.05);
manifest.putRules(Arrays.asList(rule("r1"), r2), now);
// Request that matches against the default rule
SamplingRequest req = new SamplingRequest("privileged", "resourceARN", "service", "host", "method", "url", "serviceType", null);
Assertions.assertEquals(CentralizedRule.DEFAULT_RULE_NAME, manifest.match(req, now).sample(now).getRuleName().get());
}
use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.
the class MatchersTest method testSimpleMismatch.
@Test
void testSimpleMismatch() {
SamplingRule rule = new SamplingRule().withAttributes(null).withHost("192.168.1.1").withServiceName("www.foo.com").withHTTPMethod("POST").withResourceARN("arn:aws:service:us-east-1:111111111111:resource").withURLPath("/bar/123").withServiceType("AWS::EC2::Instance");
SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.bar.com", "192.168.1.1", "POST", "/bar/123", "AWS::EC2::Instance", null);
Matchers m = new Matchers(rule);
Assertions.assertFalse(m.match(req));
}
use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.
the class MatchersTest method testPartialRequestMismatch.
@Test
void testPartialRequestMismatch() {
SamplingRule rule = new SamplingRule().withAttributes(null).withHost("192.168.1.1").withServiceName("www.foo.com").withHTTPMethod("POST").withResourceARN("arn:aws:service:us-east-1:111111111111:resource").withURLPath("/bar/123").withServiceType("AWS::EC2::Instance");
SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.bar.com", null, "POST", "/bar/123", "AWS::EC2::Instance", null);
Matchers m = new Matchers(rule);
Assertions.assertFalse(m.match(req));
}
Aggregations