use of com.amazonaws.xray.entities.Subsegment in project aws-xray-sdk-java by aws.
the class TracingHandler method beforeRequest.
@Override
public void beforeRequest(Request<?> request) {
String serviceName = extractServiceName(request);
String operationName = extractOperationName(request);
if (S3_SERVICE_NAME.equals(serviceName) && S3_PRESIGN_REQUEST.equals(operationName)) {
return;
}
if (XRAY_SERVICE_NAME.equals(serviceName) && (XRAY_SAMPLING_RULE_REQUEST.equals(operationName) || XRAY_SAMPLING_TARGET_REQUEST.equals(operationName))) {
return;
}
if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
return;
}
Entity entityContext = request.getHandlerContext(ENTITY_KEY);
if (null != entityContext) {
recorder.setTraceEntity(entityContext);
}
Subsegment currentSubsegment = recorder.beginSubsegment(serviceName);
currentSubsegment.putAllAws(extractRequestParameters(request));
currentSubsegment.putAws(EntityDataKeys.AWS.OPERATION_KEY, operationName);
if (null != accountId) {
currentSubsegment.putAws(EntityDataKeys.AWS.ACCOUNT_ID_SUBSEGMENT_KEY, accountId);
}
currentSubsegment.setNamespace(Namespace.AWS.toString());
if (recorder.getCurrentSegment() != null && recorder.getCurrentSubsegment().shouldPropagate()) {
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