Search in sources :

Example 11 with TraceHeader

use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.

the class TraceHeaderTest method testLongHeaderFromStringWithSpaces.

@Test
public void testLongHeaderFromStringWithSpaces() {
    TraceHeader header = TraceHeader.fromString("Sampled=?; Root=" + TRACE_ID + "; Parent=foo; Self=2; Foo=bar");
    Assert.assertEquals(SampleDecision.REQUESTED, header.getSampled());
    Assert.assertEquals(TraceID.fromString(TRACE_ID), header.getRootTraceId());
    Assert.assertEquals("foo", header.getParentId());
    Assert.assertEquals(1, header.getAdditionalParams().size());
    Assert.assertEquals("bar", header.getAdditionalParams().get("Foo"));
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) Test(org.junit.Test)

Example 12 with TraceHeader

use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.

the class TracedHttpClient method addRequestInformation.

public static void addRequestInformation(Subsegment subsegment, HttpRequest request, String url) {
    subsegment.setNamespace(Namespace.REMOTE.toString());
    Segment parentSegment = subsegment.getParentSegment();
    TraceHeader header = new TraceHeader(parentSegment.getTraceId(), parentSegment.isSampled() ? subsegment.getId() : null, parentSegment.isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED);
    request.addHeader(TraceHeader.HEADER_KEY, header.toString());
    Map<String, Object> requestInformation = new HashMap<>();
    requestInformation.put("url", url);
    requestInformation.put("method", request.getRequestLine().getMethod());
    subsegment.putHttp("request", requestInformation);
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) HashMap(java.util.HashMap) Segment(com.amazonaws.xray.entities.Segment)

Example 13 with TraceHeader

use of com.amazonaws.xray.entities.TraceHeader in project aws-xray-sdk-java by aws.

the class TracingHandler method beforeRequest.

@Override
public void beforeRequest(Request<?> request) {
    if (S3_SERVICE_NAME.equals(extractServiceName(request)) && S3_PRESIGN_REQUEST.equals(extractOperationName(request))) {
        return;
    }
    if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
        return;
    }
    Entity entityContext = request.getHandlerContext(entityKey);
    if (null != entityContext) {
        recorder.setTraceEntity(entityContext);
    }
    Subsegment currentSubsegment = recorder.beginSubsegment(extractServiceName(request));
    if (null == currentSubsegment) {
        return;
    }
    currentSubsegment.putAllAws(extractRequestParameters(request));
    currentSubsegment.putAws(OPERATION_SUBSEGMENT_KEY, extractOperationName(request));
    if (null != accountId) {
        currentSubsegment.putAws(ACCOUNT_ID_SUBSEGMENT_KEY, accountId);
    }
    currentSubsegment.setNamespace(Namespace.AWS.toString());
    if (null != recorder.getCurrentSegment()) {
        TraceHeader header = new TraceHeader(recorder.getCurrentSegment().getTraceId(), recorder.getCurrentSegment().isSampled() ? currentSubsegment.getId() : null, recorder.getCurrentSegment().isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED);
        request.addHeader(TraceHeader.HEADER_KEY, header.toString());
    }
}
Also used : Entity(com.amazonaws.xray.entities.Entity) TraceHeader(com.amazonaws.xray.entities.TraceHeader) Subsegment(com.amazonaws.xray.entities.Subsegment)

Aggregations

TraceHeader (com.amazonaws.xray.entities.TraceHeader)13 Test (org.junit.Test)7 Subsegment (com.amazonaws.xray.entities.Subsegment)4 Emitter (com.amazonaws.xray.emitters.Emitter)3 UDPEmitter (com.amazonaws.xray.emitters.UDPEmitter)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Segment (com.amazonaws.xray.entities.Segment)2 HashMap (java.util.HashMap)2 Entity (com.amazonaws.xray.entities.Entity)1 SampleDecision (com.amazonaws.xray.entities.TraceHeader.SampleDecision)1 TraceID (com.amazonaws.xray.entities.TraceID)1 SamplingStrategy (com.amazonaws.xray.strategy.sampling.SamplingStrategy)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1