Skip to content

Commit 20c7590

Browse files
To remove cross module internal utility usage from trace propagators (#8955)
Co-authored-by: Jack Berg <34418638+jack-berg@users.noreply.github.com>
1 parent 835d05c commit 20c7590

21 files changed

Lines changed: 198 additions & 92 deletions

File tree

api/all/src/main/java/io/opentelemetry/api/internal/TemporaryBuffers.java renamed to api/all/src/main/java/io/opentelemetry/api/impl/TemporaryBuffers.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.api.internal;
6+
package io.opentelemetry.api.impl;
77

88
/**
99
* {@link ThreadLocal} buffers for use when creating new derived objects such as {@link String}s.
@@ -12,8 +12,8 @@
1212
* should get a temporary buffer, fill it with data, and finish by converting into the derived
1313
* object within the same method to avoid multiple usages of the same buffer.
1414
*
15-
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
16-
* at any time.
15+
* <p>This class is not intended for use by application developers. Its API is stable and will not
16+
* be changed or removed in a backwards-incompatible manner.
1717
*/
1818
public final class TemporaryBuffers {
1919

@@ -24,6 +24,9 @@ public final class TemporaryBuffers {
2424
* {@code len} as this buffer will remain for the lifetime of the thread. The returned buffer will
2525
* not be zeroed and may be larger than the requested size, you must make sure to fill the entire
2626
* content to the desired value and set the length explicitly when converting to a {@link String}.
27+
*
28+
* @param len the minimum buffer capacity
29+
* @return a reusable thread-local character buffer with capacity of at least {@code len}
2730
*/
2831
public static char[] chars(int len) {
2932
char[] buffer = CHAR_ARRAY.get();

‎api/all/src/main/java/io/opentelemetry/api/internal/PercentEscaper.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package io.opentelemetry.api.internal;
2222

23+
import io.opentelemetry.api.impl.TemporaryBuffers;
2324
import javax.annotation.CheckForNull;
2425

2526
/**

‎api/all/src/main/java/io/opentelemetry/api/internal/StringUtils.java‎

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.api.internal;
77

8-
import java.util.Objects;
98
import javax.annotation.Nullable;
109
import javax.annotation.concurrent.Immutable;
1110

@@ -32,52 +31,6 @@ public static boolean isNullOrEmpty(@Nullable String string) {
3231
return string == null || string.isEmpty();
3332
}
3433

35-
/**
36-
* Pads a given string on the left with leading 0's up the length.
37-
*
38-
* @param value the string to pad
39-
* @param minLength the minimum length the resulting padded string must have. Can be zero or
40-
* negative, in which case the input string is always returned.
41-
* @return the padded string
42-
*/
43-
public static String padLeft(String value, int minLength) {
44-
return padStart(value, minLength, '0');
45-
}
46-
47-
/**
48-
* Returns a string, of length at least {@code minLength}, consisting of {@code string} prepended
49-
* with as many copies of {@code padChar} as are necessary to reach that length. For example,
50-
*
51-
* <ul>
52-
* <li>{@code padStart("7", 3, '0')} returns {@code "007"}
53-
* <li>{@code padStart("2010", 3, '0')} returns {@code "2010"}
54-
* </ul>
55-
*
56-
* <p>See {@link java.util.Formatter} for a richer set of formatting capabilities.
57-
*
58-
* <p>This method was copied almost verbatim from Guava library method
59-
* com.google.common.base.Strings#padStart(java.lang.String, int, char).
60-
*
61-
* @param string the string which should appear at the end of the result
62-
* @param minLength the minimum length the resulting string must have. Can be zero or negative, in
63-
* which case the input string is always returned.
64-
* @param padChar the character to insert at the beginning of the result until the minimum length
65-
* is reached
66-
* @return the padded string
67-
*/
68-
private static String padStart(String string, int minLength, char padChar) {
69-
Objects.requireNonNull(string);
70-
if (string.length() >= minLength) {
71-
return string;
72-
}
73-
StringBuilder sb = new StringBuilder(minLength);
74-
for (int i = string.length(); i < minLength; i++) {
75-
sb.append(padChar);
76-
}
77-
sb.append(string);
78-
return sb.toString();
79-
}
80-
8134
/**
8235
* Determines whether the {@code String} contains only printable characters.
8336
*

‎api/all/src/main/java/io/opentelemetry/api/trace/SpanId.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
package io.opentelemetry.api.trace;
77

8+
import io.opentelemetry.api.impl.TemporaryBuffers;
89
import io.opentelemetry.api.internal.OtelEncodingUtils;
9-
import io.opentelemetry.api.internal.TemporaryBuffers;
1010
import io.opentelemetry.common.impl.ApiUsageLogger;
1111
import javax.annotation.concurrent.Immutable;
1212

‎api/all/src/main/java/io/opentelemetry/api/trace/TraceId.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
package io.opentelemetry.api.trace;
77

8+
import io.opentelemetry.api.impl.TemporaryBuffers;
89
import io.opentelemetry.api.internal.OtelEncodingUtils;
9-
import io.opentelemetry.api.internal.TemporaryBuffers;
1010
import io.opentelemetry.common.impl.ApiUsageLogger;
1111
import javax.annotation.concurrent.Immutable;
1212

‎api/all/src/main/java/io/opentelemetry/api/trace/propagation/W3CTraceContextPropagator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import static io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.decodeTraceState;
99
import static io.opentelemetry.api.trace.propagation.internal.W3CTraceContextEncoding.encodeTraceState;
1010

11+
import io.opentelemetry.api.impl.TemporaryBuffers;
1112
import io.opentelemetry.api.internal.OtelEncodingUtils;
12-
import io.opentelemetry.api.internal.TemporaryBuffers;
1313
import io.opentelemetry.api.trace.Span;
1414
import io.opentelemetry.api.trace.SpanContext;
1515
import io.opentelemetry.api.trace.SpanId;

api/all/src/test/java/io/opentelemetry/api/internal/TemporaryBuffersTest.java renamed to api/all/src/test/java/io/opentelemetry/api/impl/TemporaryBuffersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.api.internal;
6+
package io.opentelemetry.api.impl;
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

‎api/all/src/test/java/io/opentelemetry/api/internal/StringUtilsTest.java‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.opentelemetry.api.internal;
77

88
import static org.assertj.core.api.Assertions.assertThat;
9-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
109

1110
import org.junit.jupiter.api.Test;
1211

@@ -27,22 +26,4 @@ void isNullOrEmpty() {
2726
assertThat(StringUtils.isNullOrEmpty("hello")).isFalse();
2827
assertThat(StringUtils.isNullOrEmpty(" ")).isFalse();
2928
}
30-
31-
@Test
32-
void padLeft() {
33-
assertThat(StringUtils.padLeft("value", 10)).isEqualTo("00000value");
34-
}
35-
36-
@Test
37-
void padLeft_throws_for_null_value() {
38-
assertThatThrownBy(() -> StringUtils.padLeft(null, 10))
39-
.isInstanceOf(NullPointerException.class);
40-
}
41-
42-
@Test
43-
void padLeft_length_does_not_exceed_length() {
44-
assertThat(StringUtils.padLeft("value", 3)).isEqualTo("value");
45-
assertThat(StringUtils.padLeft("value", -10)).isEqualTo("value");
46-
assertThat(StringUtils.padLeft("value", 0)).isEqualTo("value");
47-
}
4829
}

‎docs/apidiffs/current_vs_latest/opentelemetry-api.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Comparing source compatibility of opentelemetry-api-1.68.0-SNAPSHOT.jar against
77
+++ NEW METHOD: PUBLIC(+) STATIC(+) boolean isValidBase16String(java.lang.CharSequence)
88
+++ NEW METHOD: PUBLIC(+) STATIC(+) long longFromBase16String(java.lang.CharSequence, int)
99
+++ NEW METHOD: PUBLIC(+) STATIC(+) void longToBase16String(long, char[], int)
10+
+++ NEW CLASS: PUBLIC(+) FINAL(+) io.opentelemetry.api.impl.TemporaryBuffers (not serializable)
11+
+++ CLASS FILE FORMAT VERSION: 52.0 <- n.a.
12+
+++ NEW SUPERCLASS: java.lang.Object
13+
+++ NEW METHOD: PUBLIC(+) STATIC(+) char[] chars(int)

‎extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/B3PropagatorExtractorSingleHeader.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package io.opentelemetry.extension.trace.propagation;
77

8-
import io.opentelemetry.api.internal.StringUtils;
98
import io.opentelemetry.api.trace.Span;
109
import io.opentelemetry.context.Context;
1110
import io.opentelemetry.context.propagation.TextMapGetter;
@@ -34,7 +33,7 @@ public <C> Optional<Context> extract(
3433
private static <C> Optional<Context> extractSpanContextFromSingleHeader(
3534
Context context, @Nullable C carrier, TextMapGetter<C> getter) {
3635
String value = getter.get(carrier, B3Propagator.COMBINED_HEADER);
37-
if (StringUtils.isNullOrEmpty(value)) {
36+
if (value == null || value.isEmpty()) {
3837
return Optional.empty();
3938
}
4039

0 commit comments

Comments
 (0)