Search in sources :

Example 1 with TraceStateBuilder

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;
}
Also used : TraceStateBuilder(io.opentelemetry.api.trace.TraceStateBuilder) TraceState(io.opentelemetry.api.trace.TraceState)

Example 2 with TraceStateBuilder

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();
}
Also used : TraceStateBuilder(io.opentelemetry.api.trace.TraceStateBuilder) HistogramDataPoint(io.opentelemetry.proto.metrics.v1.HistogramDataPoint) NumberDataPoint(io.opentelemetry.proto.metrics.v1.NumberDataPoint) SummaryDataPoint(io.opentelemetry.proto.metrics.v1.SummaryDataPoint)

Example 3 with TraceStateBuilder

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();
}
Also used : TraceStateBuilder(io.opentelemetry.api.trace.TraceStateBuilder)

Aggregations

TraceStateBuilder (io.opentelemetry.api.trace.TraceStateBuilder)3 TraceState (io.opentelemetry.api.trace.TraceState)1 HistogramDataPoint (io.opentelemetry.proto.metrics.v1.HistogramDataPoint)1 NumberDataPoint (io.opentelemetry.proto.metrics.v1.NumberDataPoint)1 SummaryDataPoint (io.opentelemetry.proto.metrics.v1.SummaryDataPoint)1