Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions all/src/test/java/io/opentelemetry/all/NoGuavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ void noGuavaReferences(String artifactId, String absolutePath) throws IOExceptio

private static Stream<Arguments> artifactsAndJars() throws IOException {
return Files.readAllLines(Path.of(System.getenv("ARTIFACTS_AND_JARS"))).stream()
.map(
line -> {
String[] parts = line.split(":", 2);
return Arguments.argumentSet(parts[0], parts[0], parts[1]);
});
.map(line -> {
String[] parts = line.split(":", 2);
return Arguments.argumentSet(parts[0], parts[0], parts[1]);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,9 @@ public boolean test(JavaClass javaClass) {
private static Stream<Arguments> artifactsAndJars() throws IOException {
List<String> lines = Files.readAllLines(Path.of(System.getenv("ARTIFACTS_AND_JARS")));
return lines.stream()
.map(
line -> {
String[] parts = line.split(":", 2);
return Arguments.argumentSet(parts[0], parts[0], parts[1]);
});
.map(line -> {
String[] parts = line.split(":", 2);
return Arguments.argumentSet(parts[0], parts[0], parts[1]);
});
}
}
6 changes: 2 additions & 4 deletions all/src/test/java/io/opentelemetry/all/NullGuardsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,8 @@ private static boolean visitSupertype(
private static boolean declaresMethod(ClassModel cls, String name, String desc) {
return cls.methods().stream()
.filter(m -> !m.flags().has(AccessFlag.STATIC) && !m.flags().has(AccessFlag.PRIVATE))
.anyMatch(
m ->
name.equals(m.methodName().stringValue())
&& desc.equals(m.methodType().stringValue()));
.anyMatch(m ->
name.equals(m.methodName().stringValue()) && desc.equals(m.methodType().stringValue()));
}

private static boolean isInAuditablePackage(ClassModel cls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ public class W3CBaggagePropagatorBenchmark {
static {
List<String> baggages =
IntStream.range(0, 100)
.mapToObj(
i ->
"key"
+ i
+ " = value"
+ i
+ ";metaKey"
+ i
+ "=\tmetaVal"
+ i
+ ",broken)key"
+ i
+ "=value")
.mapToObj(i ->
"key"
+ i
+ " = value"
+ i
+ ";metaKey"
+ i
+ "=\tmetaVal"
+ i
+ ",broken)key"
+ i
+ "=value")
.collect(Collectors.toList());
SMALL_BAGGAGE = Collections.singletonMap("baggage", String.join(",", baggages.subList(0, 5)));
LARGE_BAGGAGE = Collections.singletonMap("baggage", String.join(",", baggages));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,11 @@ default BaggageEntry getEntry(String entryKey) {
return null;
}
BaggageEntry[] result = new BaggageEntry[] {null};
forEach(
(key, entry) -> {
if (entryKey.equals(key)) {
result[0] = entry;
}
});
forEach((key, entry) -> {
if (entryKey.equals(key)) {
result[0] = entry;
}
});
return result[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,39 @@ public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> se
private static String baggageToString(Baggage baggage) {
StringBuilder headerContent = new StringBuilder();
int[] entryCount = {0};
baggage.forEach(
(key, baggageEntry) -> {
if (!isValidBaggageKey(key)) {
LOGGER.log(Level.WARNING, "Skipping baggage entry with invalid key");
return;
}
if (!isValidBaggageValue(baggageEntry.getValue())) {
LOGGER.log(Level.WARNING, "Skipping baggage entry with invalid value");
return;
}
if (!isValidBaggageMetadata(baggageEntry.getMetadata().getValue())) {
LOGGER.log(Level.WARNING, "Skipping baggage entry with invalid metadata");
return;
}
if (entryCount[0] >= MAX_BAGGAGE_ENTRIES) {
return;
}
String encodedValue = encodeValue(baggageEntry.getValue());
String metadataValue = baggageEntry.getMetadata().getValue();
String metadata =
(metadataValue != null && !metadataValue.isEmpty()) ? metadataValue : null;
// Exit early if adding this entry causes the total length to exceed the limit
// encodedEntryLength includes a trailing comma; the final string trims exactly one,
// so the net contribution to the final length is entryLength - 1.
if (headerContent.length() + encodedEntryLength(key, encodedValue, metadata) - 1
> MAX_BAGGAGE_BYTES) {
return;
}
headerContent.append(key).append("=").append(encodedValue);
if (metadata != null) {
headerContent.append(";").append(metadata);
}
headerContent.append(",");
entryCount[0]++;
});
baggage.forEach((key, baggageEntry) -> {
if (!isValidBaggageKey(key)) {
LOGGER.log(Level.WARNING, "Skipping baggage entry with invalid key");
return;
}
if (!isValidBaggageValue(baggageEntry.getValue())) {
LOGGER.log(Level.WARNING, "Skipping baggage entry with invalid value");
return;
}
if (!isValidBaggageMetadata(baggageEntry.getMetadata().getValue())) {
LOGGER.log(Level.WARNING, "Skipping baggage entry with invalid metadata");
return;
}
if (entryCount[0] >= MAX_BAGGAGE_ENTRIES) {
return;
}
String encodedValue = encodeValue(baggageEntry.getValue());
String metadataValue = baggageEntry.getMetadata().getValue();
String metadata = (metadataValue != null && !metadataValue.isEmpty()) ? metadataValue : null;
// Exit early if adding this entry causes the total length to exceed the limit
// encodedEntryLength includes a trailing comma; the final string trims exactly one,
// so the net contribution to the final length is entryLength - 1.
if (headerContent.length() + encodedEntryLength(key, encodedValue, metadata) - 1
> MAX_BAGGAGE_BYTES) {
return;
}
headerContent.append(key).append("=").append(encodedValue);
if (metadata != null) {
headerContent.append(";").append(metadata);
}
headerContent.append(",");
entryCount[0]++;
});

if (headerContent.length() == 0) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ public <T> AttributesBuilder remove(AttributeKey<T> key) {
if (key.getKey().isEmpty()) {
return this;
}
return removeIf(
entryKey ->
key.getKey().equals(entryKey.getKey()) && key.getType().equals(entryKey.getType()));
return removeIf(entryKey ->
key.getKey().equals(entryKey.getKey()) && key.getType().equals(entryKey.getType()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ public static String encodeTraceState(TraceState traceState) {
return "";
}
StringBuilder builder = new StringBuilder(TRACESTATE_MAX_SIZE);
traceState.forEach(
(key, value) -> {
if (builder.length() != 0) {
builder.append(TRACESTATE_ENTRY_DELIMITER);
}
builder.append(key).append(TRACESTATE_KEY_VALUE_DELIMITER).append(value);
});
traceState.forEach((key, value) -> {
if (builder.length() != 0) {
builder.append(TRACESTATE_ENTRY_DELIMITER);
}
builder.append(key).append(TRACESTATE_KEY_VALUE_DELIMITER).append(value);
});
return builder.toString();
}
}
131 changes: 61 additions & 70 deletions api/all/src/test/java/io/opentelemetry/api/logs/ValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,90 +33,82 @@ class ValueTest {
@Test
void value_OfString() {
assertThat(Value.of("foo"))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.STRING);
assertThat(value.getValue()).isEqualTo("foo");
assertThat(value).hasSameHashCodeAs(Value.of("foo"));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.STRING);
assertThat(value.getValue()).isEqualTo("foo");
assertThat(value).hasSameHashCodeAs(Value.of("foo"));
});
}

@Test
void value_OfBoolean() {
assertThat(Value.of(true))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.BOOLEAN);
assertThat(value.getValue()).isEqualTo(true);
assertThat(value).hasSameHashCodeAs(Value.of(true));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.BOOLEAN);
assertThat(value.getValue()).isEqualTo(true);
assertThat(value).hasSameHashCodeAs(Value.of(true));
});
}

@Test
void value_OfLong() {
assertThat(Value.of(1L))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.LONG);
assertThat(value.getValue()).isEqualTo(1L);
assertThat(value).hasSameHashCodeAs(Value.of(1L));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.LONG);
assertThat(value.getValue()).isEqualTo(1L);
assertThat(value).hasSameHashCodeAs(Value.of(1L));
});
}

@Test
void value_OfDouble() {
assertThat(Value.of(1.1))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.DOUBLE);
assertThat(value.getValue()).isEqualTo(1.1);
assertThat(value).hasSameHashCodeAs(Value.of(1.1));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.DOUBLE);
assertThat(value.getValue()).isEqualTo(1.1);
assertThat(value).hasSameHashCodeAs(Value.of(1.1));
});
}

@Test
void value_OfByteArray() {
assertThat(Value.of(new byte[] {'a', 'b'}))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.BYTES);
ByteBuffer buf = value.getValue();
// ValueBytes returns read only view of ByteBuffer
assertThatThrownBy(buf::array).isInstanceOf(ReadOnlyBufferException.class);
byte[] bytes = new byte[buf.remaining()];
buf.get(bytes);
assertThat(bytes).isEqualTo(new byte[] {'a', 'b'});
assertThat(value).hasSameHashCodeAs(Value.of(new byte[] {'a', 'b'}));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.BYTES);
ByteBuffer buf = value.getValue();
// ValueBytes returns read only view of ByteBuffer
assertThatThrownBy(buf::array).isInstanceOf(ReadOnlyBufferException.class);
byte[] bytes = new byte[buf.remaining()];
buf.get(bytes);
assertThat(bytes).isEqualTo(new byte[] {'a', 'b'});
assertThat(value).hasSameHashCodeAs(Value.of(new byte[] {'a', 'b'}));
});
}

@Test
void value_OfvalueArray() {
assertThat(Value.of(Value.of(true), Value.of(1L)))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.ARRAY);
assertThat(value.getValue()).isEqualTo(Arrays.asList(Value.of(true), Value.of(1L)));
assertThat(value).hasSameHashCodeAs(Value.of(Value.of(true), Value.of(1L)));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.ARRAY);
assertThat(value.getValue()).isEqualTo(Arrays.asList(Value.of(true), Value.of(1L)));
assertThat(value).hasSameHashCodeAs(Value.of(Value.of(true), Value.of(1L)));
});
}

@Test
@SuppressWarnings("DoubleBraceInitialization")
void value_OfKeyValueList() {
assertThat(Value.of(KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.KEY_VALUE_LIST);
assertThat(value.getValue())
.isEqualTo(
Arrays.asList(
KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))));
assertThat(value)
.hasSameHashCodeAs(
Value.of(
KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.KEY_VALUE_LIST);
assertThat(value.getValue())
.isEqualTo(
Arrays.asList(
KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))));
assertThat(value)
.hasSameHashCodeAs(
Value.of(KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))));
});

assertThat(
Value.of(
Expand All @@ -126,23 +118,22 @@ void value_OfKeyValueList() {
put("long", Value.of(1L));
}
}))
.satisfies(
value -> {
assertThat(value.getType()).isEqualTo(ValueType.KEY_VALUE_LIST);
assertThat(value.getValue())
.isEqualTo(
Arrays.asList(
KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))));
assertThat(value)
.hasSameHashCodeAs(
Value.of(
new LinkedHashMap<String, Value<?>>() {
{
put("bool", Value.of(true));
put("long", Value.of(1L));
}
}));
});
.satisfies(value -> {
assertThat(value.getType()).isEqualTo(ValueType.KEY_VALUE_LIST);
assertThat(value.getValue())
.isEqualTo(
Arrays.asList(
KeyValue.of("bool", Value.of(true)), KeyValue.of("long", Value.of(1L))));
assertThat(value)
.hasSameHashCodeAs(
Value.of(
new LinkedHashMap<String, Value<?>>() {
{
put("bool", Value.of(true));
put("long", Value.of(1L));
}
}));
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ void loggerEnabled() {
// omitted from the results even if logs were emitted. The check if enabled simply avoids
// unnecessary computation.
assertThat(exporter.getFinishedLogRecordItems())
.allSatisfy(
logRecordData ->
assertThat(logRecordData.getInstrumentationScopeInfo().getName())
.isEqualTo("loggerA"));
.allSatisfy(logRecordData ->
assertThat(logRecordData.getInstrumentationScopeInfo().getName()).isEqualTo("loggerA"));
}

private static final Random random = new Random();
Expand Down
Loading
Loading