/** * Creates a TraceHeader object from a String. Note that this will silently ignore any "Self=" trace ids injected from ALB. * * @param string * the string from an incoming trace-id header * @return the TraceHeader object */ public static TraceHeader fromString(String string) { TraceHeader traceHeader = new TraceHeader(); if (null != string) { String[] parts = string.split(";"); for(String part : parts) { String trimmedPart = part.trim(); String value = valueFromKeyEqualsValue(trimmedPart); if (trimmedPart.startsWith(ROOT_PREFIX)) { traceHeader.setRootTraceId(TraceID.fromString(value)); } else if (trimmedPart.startsWith(PARENT_PREFIX)) { traceHeader.setParentId(value); } else if (trimmedPart.startsWith(SAMPLED_PREFIX)) { traceHeader.setSampled(SampleDecision.fromString(trimmedPart)); } else if (!trimmedPart.startsWith(SELF_PREFIX)) { String key = keyFromKeyEqualsValue(trimmedPart); if (null != key && null != value) { traceHeader.putAdditionalParam(key, value); } } } } return traceHeader; }
/** * Creates a TraceHeader object from a String. Note that this will silently ignore any "Self=" trace ids injected from ALB. * * @param string * the string from an incoming trace-id header * @return the TraceHeader object */ public static TraceHeader fromString(String string) { TraceHeader traceHeader = new TraceHeader(); if (null != string) { String[] parts = string.split(";"); for(String part : parts) { String trimmedPart = part.trim(); String value = valueFromKeyEqualsValue(trimmedPart); if (trimmedPart.startsWith(ROOT_PREFIX)) { traceHeader.setRootTraceId(TraceID.fromString(value)); } else if (trimmedPart.startsWith(PARENT_PREFIX)) { traceHeader.setParentId(value); } else if (trimmedPart.startsWith(SAMPLED_PREFIX)) { traceHeader.setSampled(SampleDecision.fromString(trimmedPart)); } else if (!trimmedPart.startsWith(SELF_PREFIX)) { String key = keyFromKeyEqualsValue(trimmedPart); if (null != key && null != value) { traceHeader.putAdditionalParam(key, value); } } } } return traceHeader; }