Skip to content

Commit 30fb180

Browse files
committed
updates
1 parent 8c951bd commit 30fb180

File tree

6 files changed

+39
-52
lines changed

6 files changed

+39
-52
lines changed

exporters/otlp/common/src/main/java/io/opentelemetry/exporter/internal/otlp/AttributeArrayAnyValueStatelessMarshaler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public void writeTo(Serializer output, AttributeType type, List<T> list, Marshal
5252
DoubleAnyValueStatelessMarshaler.INSTANCE,
5353
context);
5454
return;
55-
// TODO this class is named *ArrayAnyValue*, does that mean it covers List<Value<?>> as well?
5655
default:
5756
throw new IllegalArgumentException("Unsupported attribute type.");
5857
}
@@ -83,7 +82,6 @@ public int getBinarySerializedSize(AttributeType type, List<T> list, MarshalerCo
8382
(List<Double>) list,
8483
DoubleAnyValueStatelessMarshaler.INSTANCE,
8584
context);
86-
// TODO this class is named *ArrayAnyValue*, does that mean it covers List<Value<?>> as well?
8785
default:
8886
throw new IllegalArgumentException("Unsupported attribute type.");
8987
}

exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverterTest.java

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
import static org.assertj.core.api.Assertions.assertThat;
1818
import static org.assertj.core.api.Assertions.assertThatCode;
1919

20-
import com.fasterxml.jackson.core.JsonProcessingException;
21-
import com.fasterxml.jackson.databind.ObjectMapper;
22-
import io.opentelemetry.api.common.AttributeType;
2320
import io.opentelemetry.api.common.Attributes;
2421
import io.opentelemetry.api.common.KeyValue;
2522
import io.opentelemetry.api.common.Value;
@@ -71,7 +68,6 @@ class Otel2PrometheusConverterTest {
7168
"(.|\\n)*# HELP (?<help>.*)\n# TYPE (?<type>.*)\n(?<metricName>.*)\\{"
7269
+ "otel_scope_foo=\"bar\",otel_scope_name=\"scope\","
7370
+ "otel_scope_schema_url=\"schemaUrl\",otel_scope_version=\"version\"}(.|\\n)*");
74-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
7571

7672
private final Otel2PrometheusConverter converter =
7773
new Otel2PrometheusConverter(
@@ -322,7 +318,7 @@ void prometheusNameCollisionTest_Issue6277() {
322318

323319
@ParameterizedTest
324320
@MethodSource("labelValueSerializationArgs")
325-
void labelValueSerialization(Attributes attributes) {
321+
void labelValueSerialization(Attributes attributes, String expectedValue) {
326322
MetricData metricData =
327323
createSampleMetricData("sample", "1", MetricDataType.LONG_SUM, attributes, null);
328324

@@ -333,46 +329,43 @@ void labelValueSerialization(Attributes attributes) {
333329
assertThat(metricSnapshot).isPresent();
334330

335331
Labels labels = metricSnapshot.get().getDataPoints().get(0).getLabels();
336-
attributes.forEach(
337-
(key, value) -> {
338-
String labelValue = labels.get(key.getKey());
339-
try {
340-
String expectedValue;
341-
if (key.getType() == AttributeType.STRING) {
342-
expectedValue = (String) value;
343-
} else if (key.getType() == AttributeType.VALUE) {
344-
expectedValue = ((Value<?>) value).asString();
345-
} else {
346-
expectedValue = OBJECT_MAPPER.writeValueAsString(value);
347-
}
348-
assertThat(labelValue).isEqualTo(expectedValue);
349-
} catch (JsonProcessingException e) {
350-
throw new RuntimeException(e);
351-
}
352-
});
332+
String labelValue = labels.get("key");
333+
assertThat(labelValue).isEqualTo(expectedValue);
353334
}
354335

355336
private static Stream<Arguments> labelValueSerializationArgs() {
356337
return Stream.of(
357-
Arguments.of(Attributes.of(stringKey("key"), "stringValue")),
358-
Arguments.of(Attributes.of(booleanKey("key"), true)),
359-
Arguments.of(Attributes.of(longKey("key"), Long.MAX_VALUE)),
360-
Arguments.of(Attributes.of(doubleKey("key"), 0.12345)),
338+
Arguments.of(Attributes.of(stringKey("key"), "stringValue"), "stringValue"),
339+
Arguments.of(Attributes.of(booleanKey("key"), true), "true"),
340+
Arguments.of(Attributes.of(longKey("key"), Long.MAX_VALUE), "9223372036854775807"),
341+
Arguments.of(Attributes.of(doubleKey("key"), 0.12345), "0.12345"),
361342
Arguments.of(
362343
Attributes.of(
363344
stringArrayKey("key"),
364-
Arrays.asList("stringValue1", "\"+\\\\\\+\b+\f+\n+\r+\t+" + (char) 0))),
365-
Arguments.of(Attributes.of(booleanArrayKey("key"), Arrays.asList(true, false))),
345+
Arrays.asList("stringValue1", "\"+\\\\\\+\b+\f+\n+\r+\t+" + (char) 0)),
346+
"[\"stringValue1\",\"\\\"+\\\\\\\\\\\\+\\b+\\f+\\n+\\r+\\t+\\u0000\"]"),
366347
Arguments.of(
367-
Attributes.of(longArrayKey("key"), Arrays.asList(Long.MIN_VALUE, Long.MAX_VALUE))),
348+
Attributes.of(booleanArrayKey("key"), Arrays.asList(true, false)),
349+
"[true,false]"),
350+
Arguments.of(
351+
Attributes.of(longArrayKey("key"), Arrays.asList(Long.MIN_VALUE, Long.MAX_VALUE)),
352+
"[-9223372036854775808,9223372036854775807]"),
368353
Arguments.of(
369354
Attributes.of(
370-
doubleArrayKey("key"), Arrays.asList(Double.MIN_VALUE, Double.MAX_VALUE))),
371-
Arguments.of(Attributes.of(valueKey("key"), Value.of(new byte[] {1, 2, 3}))),
355+
doubleArrayKey("key"), Arrays.asList(Double.MIN_VALUE, Double.MAX_VALUE)),
356+
"[4.9E-324,1.7976931348623157E308]"),
357+
Arguments.of(
358+
Attributes.of(valueKey("key"), Value.of(new byte[] {1, 2, 3})),
359+
"AQID"),
360+
Arguments.of(
361+
Attributes.of(valueKey("key"), Value.of(KeyValue.of("nested", Value.of("value")))),
362+
"[nested=value]"),
363+
Arguments.of(
364+
Attributes.of(valueKey("key"), Value.of(Value.of("string"), Value.of(123L))),
365+
"[string, 123]"),
372366
Arguments.of(
373-
Attributes.of(valueKey("key"), Value.of(KeyValue.of("nested", Value.of("value"))))),
374-
Arguments.of(Attributes.of(valueKey("key"), Value.of(Value.of("string"), Value.of(123L)))),
375-
Arguments.of(Attributes.of(valueKey("key"), Value.empty())));
367+
Attributes.of(valueKey("key"), Value.empty()),
368+
""));
376369
}
377370

378371
static MetricData createSampleMetricData(

exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import io.opentelemetry.api.common.AttributeKey;
1313
import io.opentelemetry.api.common.AttributeType;
1414
import io.opentelemetry.api.common.Attributes;
15-
import io.opentelemetry.api.common.Value;
1615
import io.opentelemetry.api.trace.SpanKind;
1716
import io.opentelemetry.api.trace.StatusCode;
1817
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
@@ -100,7 +99,11 @@ Span generateSpan(SpanData spanData) {
10099

101100
Attributes spanAttributes = spanData.getAttributes();
102101
spanAttributes.forEach(
103-
(key, value) -> spanBuilder.putTag(key.getKey(), valueToString(key, value)));
102+
(key, value) -> {
103+
if (key.getType() != AttributeType.VALUE) {
104+
spanBuilder.putTag(key.getKey(), valueToString(key, value));
105+
}
106+
});
104107
int droppedAttributes = spanData.getTotalAttributeCount() - spanAttributes.size();
105108
if (droppedAttributes > 0) {
106109
spanBuilder.putTag(OTEL_DROPPED_ATTRIBUTES_COUNT, String.valueOf(droppedAttributes));
@@ -225,8 +228,7 @@ private static String valueToString(AttributeKey<?> key, Object attributeValue)
225228
case DOUBLE_ARRAY:
226229
return commaSeparated((List<?>) attributeValue);
227230
case VALUE:
228-
// TODO this should be json representation
229-
return ((Value<?>) attributeValue).asString();
231+
throw new IllegalArgumentException("Unsupported attribute type: VALUE");
230232
}
231233
throw new IllegalStateException("Unknown attribute type: " + type);
232234
}

exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/OtelToZipkinSpanTransformerTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.mockito.Mockito.mock;
2222

2323
import io.opentelemetry.api.common.Attributes;
24-
import io.opentelemetry.api.common.KeyValue;
2524
import io.opentelemetry.api.common.Value;
2625
import io.opentelemetry.api.trace.SpanKind;
2726
import io.opentelemetry.api.trace.StatusCode;
@@ -367,14 +366,11 @@ void generateSpan_WithAttributes() {
367366
.put(doubleArrayKey("doubleArray"), Arrays.asList(32.33d, -98.3d))
368367
.put(longArrayKey("longArray"), Arrays.asList(33L, 999L))
369368
.put(valueKey("bytes"), Value.of(new byte[] {1, 2, 3}))
370-
.put(valueKey("map"), Value.of(KeyValue.of("nested", Value.of("value"))))
371-
.put(valueKey("heterogeneousArray"), Value.of(Value.of("string"), Value.of(123L)))
372-
.put(valueKey("empty"), Value.empty())
373369
.build();
374370
SpanData data =
375371
spanBuilder()
376372
.setAttributes(attributes)
377-
.setTotalAttributeCount(32)
373+
.setTotalAttributeCount(29)
378374
.setTotalRecordedEvents(3)
379375
.setKind(SpanKind.CLIENT)
380376
.build();
@@ -390,10 +386,6 @@ void generateSpan_WithAttributes() {
390386
.putTag("stringArray", "Hello")
391387
.putTag("doubleArray", "32.33,-98.3")
392388
.putTag("longArray", "33,999")
393-
.putTag("bytes", "AQID")
394-
.putTag("map", "[nested=value]")
395-
.putTag("heterogeneousArray", "[string, 123]")
396-
.putTag("empty", "")
397389
.putTag(OtelToZipkinSpanTransformer.OTEL_STATUS_CODE, "OK")
398390
.putTag(OtelToZipkinSpanTransformer.OTEL_DROPPED_ATTRIBUTES_COUNT, "20")
399391
.putTag(OtelToZipkinSpanTransformer.OTEL_DROPPED_EVENTS_COUNT, "1")

sdk/testing/src/main/java/io/opentelemetry/sdk/testing/assertj/LogRecordDataAssert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public <T> LogRecordDataAssert hasBodyField(AttributeKey<T> key, T value) {
345345
key.getKey(),
346346
Value.of(((List<Double>) value).stream().map(Value::of).collect(toList())));
347347
case VALUE:
348-
// TODO?
348+
return hasBodyField(key.getKey(), (Value<?>) value);
349349
}
350350
return this;
351351
}

sdk/testing/src/test/java/io/opentelemetry/sdk/testing/assertj/LogAssertionsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ void logBodyAssertions() {
318318
KeyValue.of(
319319
"fooboola",
320320
Value.of(Value.of(true), Value.of(true), Value.of(true), Value.of(false))),
321-
KeyValue.of("fooany", Value.of("grim"))))
321+
KeyValue.of("fooany", Value.of("grim")),
322+
KeyValue.of("foobytes", Value.of(new byte[] {1, 2, 3}))))
322323
.emit();
323324
List<LogRecordData> logs = exporter.getFinishedLogRecordItems();
324325
assertThat(logs).hasSize(1);
@@ -331,6 +332,7 @@ void logBodyAssertions() {
331332
.hasBodyField("foolonga", 9, 0, 2, 1, 0)
332333
.hasBodyField("foodbla", 9.1, 0.2, 2.3, 1.4, 0.5)
333334
.hasBodyField("fooboola", true, true, true, false)
334-
.hasBodyField("fooany", Value.of("grim"));
335+
.hasBodyField("fooany", Value.of("grim"))
336+
.hasBodyField("foobytes", Value.of(new byte[] {1, 2, 3}));
335337
}
336338
}

0 commit comments

Comments
 (0)