use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class TracedResponseHandlerTest method testHandleResponse200SetsNoFlags.
@Test
public void testHandleResponse200SetsNoFlags() {
Segment segment = segmentInResponseToCode(200);
Subsegment subsegment = segment.getSubsegments().get(0);
Assert.assertFalse(subsegment.isFault());
Assert.assertFalse(subsegment.isError());
Assert.assertFalse(subsegment.isThrottle());
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class TracingHandlerTest method testS3PutObjectSubsegmentContainsBucketName.
@Test
public void testS3PutObjectSubsegmentContainsBucketName() {
// Setup test
AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();
mockHttpClient(s3, null);
final String BUCKET = "test-bucket", KEY = "test-key";
// Test logic
Segment segment = AWSXRay.beginSegment("test");
s3.putObject(BUCKET, KEY, "This is a test from java");
Assert.assertEquals(1, segment.getSubsegments().size());
Assert.assertEquals("PutObject", segment.getSubsegments().get(0).getAws().get("operation"));
System.out.println(segment.getSubsegments().get(0).getAws());
Assert.assertEquals(BUCKET, segment.getSubsegments().get(0).getAws().get("bucket_name"));
Assert.assertEquals(KEY, segment.getSubsegments().get(0).getAws().get("key"));
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class TracingHandlerTest method testLambdaInvokeSubsegmentContainsFunctionName.
@Test
public void testLambdaInvokeSubsegmentContainsFunctionName() {
// Setup test
AWSLambda lambda = AWSLambdaClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();
// Lambda returns "null" on successful fn. with no return value
mockHttpClient(lambda, "null");
// Test logic
Segment segment = AWSXRay.beginSegment("test");
InvokeRequest request = new InvokeRequest();
request.setFunctionName("testFunctionName");
InvokeResult r = lambda.invoke(request);
System.out.println(r.getStatusCode());
System.out.println(r);
Assert.assertEquals(1, segment.getSubsegments().size());
Assert.assertEquals("Invoke", segment.getSubsegments().get(0).getAws().get("operation"));
System.out.println(segment.getSubsegments().get(0).getAws());
Assert.assertEquals("testFunctionName", segment.getSubsegments().get(0).getAws().get("function_name"));
}
use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.
the class LambdaSegmentContext method beginSubsegment.
@Override
public Subsegment beginSubsegment(AWSXRayRecorder recorder, String name) {
if (logger.isDebugEnabled()) {
logger.debug("Beginning subsegment named: " + name);
}
if (null == getTraceEntity()) {
// First subsgment of a subsegment branch.
Segment parentSegment = null;
if (LambdaSegmentContext.isInitializing(LambdaSegmentContext.getTraceHeaderFromEnvironment())) {
logger.warn(LAMBDA_TRACE_HEADER_KEY + " is missing a trace ID, parent ID, or sampling decision. Subsegment " + name + " discarded.");
parentSegment = new FacadeSegment(recorder, new TraceID(), "", SampleDecision.NOT_SAMPLED);
} else {
parentSegment = LambdaSegmentContext.newFacadeSegment(recorder);
}
Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSegment);
subsegment.setParent(parentSegment);
setTraceEntity(subsegment);
return subsegment;
} else {
// Continuation of a subsegment branch.
Subsegment parentSubsegment = (Subsegment) getTraceEntity();
// Ensure customers have not leaked subsegments across invocations
TraceID environmentRootTraceId = LambdaSegmentContext.getTraceHeaderFromEnvironment().getRootTraceId();
if (null != environmentRootTraceId && !environmentRootTraceId.equals(parentSubsegment.getParentSegment().getTraceId())) {
clearTraceEntity();
return beginSubsegment(recorder, name);
}
Subsegment subsegment = new SubsegmentImpl(recorder, name, parentSubsegment.getParentSegment());
subsegment.setParent(parentSubsegment);
parentSubsegment.addSubsegment(subsegment);
setTraceEntity(subsegment);
return subsegment;
}
}
Aggregations