protected boolean getSamplingDecision()

in aws-xray-agent/src/main/java/com/amazonaws/xray/agent/runtime/handlers/XRayHandler.java [141:163]


    protected boolean getSamplingDecision(XRayTransactionState transactionState) {
        // If the trace header string is null, then this is the origin call.
        TraceHeader traceHeader = TraceHeader.fromString(transactionState.getTraceHeader());

        TraceHeader.SampleDecision sampleDecision = traceHeader.getSampled();
        if (TraceHeader.SampleDecision.SAMPLED.equals(sampleDecision)) {
            log.debug("Received SAMPLED decision from upstream X-Ray trace header");
            return true;
        } else if (TraceHeader.SampleDecision.NOT_SAMPLED.equals(sampleDecision)) {
            log.debug("Received NOT SAMPLED decision from upstream X-Ray trace header");
            return false;
        }

        // No sampling decision made on the upstream. So use the in-house rules.
        SamplingRequest samplingRequest = new SamplingRequest(
                XRayTransactionState.getServiceName(),
                transactionState.getHost(),
                transactionState.getURL(),
                transactionState.getMethod(),
                transactionState.getServiceType());
        SamplingResponse samplingResponse = AWSXRay.getGlobalRecorder().getSamplingStrategy().shouldTrace(samplingRequest);
        return samplingResponse.isSampled();
    }