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"));
}
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);
}
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());
}
}
Aggregations