Small cleanups in the propagators extension (#2717)

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
Bogdan Drutu 2021-02-05 12:13:09 -08:00 committed by GitHub
parent a18376a942
commit 5f155f1495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 8 deletions

View File

@ -29,9 +29,6 @@ final class B3PropagatorExtractorMultipleHeaders implements B3PropagatorExtracto
private static <C> Optional<Context> extractSpanContextFromMultipleHeaders(
Context context, C carrier, TextMapPropagator.Getter<C> getter) {
String traceId = getter.get(carrier, B3Propagator.TRACE_ID_HEADER);
if (StringUtils.isNullOrEmpty(traceId)) {
return Optional.empty();
}
if (!Common.isTraceIdValid(traceId)) {
logger.fine(
"Invalid TraceId in B3 header: " + traceId + "'. Returning INVALID span context.");

View File

@ -12,6 +12,7 @@ import io.opentelemetry.api.trace.TraceId;
import io.opentelemetry.api.trace.TraceState;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
@ -47,13 +48,13 @@ final class Common {
}
}
static boolean isTraceIdValid(String value) {
static boolean isTraceIdValid(@Nullable String value) {
return !(StringUtils.isNullOrEmpty(value)
|| (value.length() != MIN_TRACE_ID_LENGTH && value.length() != MAX_TRACE_ID_LENGTH)
|| !TraceId.isValid(StringUtils.padLeft(value, TraceId.getLength())));
}
static boolean isSpanIdValid(String value) {
static boolean isSpanIdValid(@Nullable String value) {
return !StringUtils.isNullOrEmpty(value) && SpanId.isValid(value);
}
}

View File

@ -12,6 +12,7 @@
package io.opentelemetry.extension.trace.propagation;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/** Utilities for working with strings. */
@ -39,7 +40,7 @@ final class StringUtils {
* is reached
* @return the padded string
*/
public static String padStart(String string, int minLength, char padChar) {
static String padStart(String string, int minLength, char padChar) {
Objects.requireNonNull(string);
if (string.length() >= minLength) {
return string;
@ -61,7 +62,7 @@ final class StringUtils {
* @param string a string reference to check
* @return {@code true} if the string is null or is the empty string
*/
public static boolean isNullOrEmpty(String string) {
static boolean isNullOrEmpty(@Nullable String string) {
return string == null || string.isEmpty();
}
@ -73,7 +74,7 @@ final class StringUtils {
* negative, in which case the input string is always returned.
* @return the padded string
*/
public static String padLeft(String value, int minLength) {
static String padLeft(String value, int minLength) {
return padStart(value, minLength, '0');
}