use of io.opentelemetry.api.trace.TraceStateBuilder in project opentelemetry-java by open-telemetry.
the class W3CTraceContextEncoding method decodeTraceState.
/**
* Decodes a trace state header into a {@link TraceState} object.
*
* @throws IllegalArgumentException if {@code traceStateHeader} does not comply with the
* specification
*/
public static TraceState decodeTraceState(String traceStateHeader) {
TraceStateBuilder traceStateBuilder = TraceState.builder();
String[] listMembers = TRACESTATE_ENTRY_DELIMITER_SPLIT_PATTERN.split(traceStateHeader);
checkArgument(listMembers.length <= TRACESTATE_MAX_MEMBERS, "TraceState has too many elements.");
// front of the list.
for (int i = listMembers.length - 1; i >= 0; i--) {
String listMember = listMembers[i];
int index = listMember.indexOf(TRACESTATE_KEY_VALUE_DELIMITER);
checkArgument(index != -1, "Invalid TraceState list-member format.");
traceStateBuilder.put(listMember.substring(0, index), listMember.substring(index + 1));
}
TraceState traceState = traceStateBuilder.build();
if (traceState.size() != listMembers.length) {
// Validation failure, drop the tracestate
return TraceState.getDefault();
}
return traceState;
}
use of io.opentelemetry.api.trace.TraceStateBuilder in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingExporterAccess method extractTraceState.
private static TraceState extractTraceState(String traceStateHeader) {
if (traceStateHeader.isEmpty()) {
return TraceState.getDefault();
}
TraceStateBuilder traceStateBuilder = TraceState.builder();
String[] listMembers = TRACESTATE_ENTRY_DELIMITER_SPLIT_PATTERN.split(traceStateHeader);
// front of the list.
for (int i = listMembers.length - 1; i >= 0; i--) {
String listMember = listMembers[i];
int index = listMember.indexOf(TRACESTATE_KEY_VALUE_DELIMITER);
traceStateBuilder.put(listMember.substring(0, index), listMember.substring(index + 1));
}
return traceStateBuilder.build();
}
use of io.opentelemetry.api.trace.TraceStateBuilder in project opentelemetry-java by open-telemetry.
the class SpanConverter method mapTracestate.
private static TraceState mapTracestate(Tracestate tracestate) {
TraceStateBuilder builder = TraceState.builder();
tracestate.getEntries().forEach(entry -> builder.put(entry.getKey(), entry.getValue()));
return builder.build();
}
Aggregations