|
9 | 9 | import static org.assertj.core.api.Assertions.assertThat;
|
10 | 10 | import static org.assertj.core.api.Assertions.assertThatCode;
|
11 | 11 |
|
| 12 | +import io.opentelemetry.api.common.AttributeKey; |
12 | 13 | import io.opentelemetry.api.common.Attributes;
|
13 | 14 | import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
|
14 | 15 | import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
|
@@ -137,6 +138,56 @@ void prometheusNameCollisionTest_Issue6277() {
|
137 | 138 | assertThatCode(() -> converter.convert(metricData)).doesNotThrowAnyException();
|
138 | 139 | }
|
139 | 140 |
|
| 141 | + @Test |
| 142 | + void labelValueSerialization_Primitives() { |
| 143 | + Attributes attributes = |
| 144 | + Attributes.builder() |
| 145 | + .put(AttributeKey.stringKey("stringKey"), "stringValue") |
| 146 | + .put(AttributeKey.booleanKey("booleanKey"), true) |
| 147 | + .put(AttributeKey.longKey("longKey"), Long.MAX_VALUE) |
| 148 | + .put(AttributeKey.doubleKey("doubleKey"), 0.12345) |
| 149 | + .build(); |
| 150 | + MetricData metricData = |
| 151 | + createSampleMetricData("sample", "1", MetricDataType.LONG_SUM, attributes, null); |
| 152 | + |
| 153 | + MetricSnapshots snapshots = converter.convert(Collections.singletonList(metricData)); |
| 154 | + |
| 155 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("stringKey")) |
| 156 | + .isEqualTo("stringValue"); |
| 157 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("booleanKey")) |
| 158 | + .isEqualTo("true"); |
| 159 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("longKey")) |
| 160 | + .isEqualTo("9223372036854775807"); |
| 161 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("doubleKey")) |
| 162 | + .isEqualTo("0.12345"); |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + void labelValueSerialization_NonPrimitives() { |
| 167 | + Attributes attributes = |
| 168 | + Attributes.builder() |
| 169 | + .put( |
| 170 | + AttributeKey.stringArrayKey("stringKey"), |
| 171 | + Arrays.asList("stringValue1", "stringValue2")) |
| 172 | + .put(AttributeKey.booleanArrayKey("booleanKey"), Arrays.asList(true, false)) |
| 173 | + .put(AttributeKey.longArrayKey("longKey"), Arrays.asList(12345L, 6789L)) |
| 174 | + .put(AttributeKey.doubleArrayKey("doubleKey"), Arrays.asList(0.12345, 0.6789)) |
| 175 | + .build(); |
| 176 | + MetricData metricData = |
| 177 | + createSampleMetricData("sample", "1", MetricDataType.LONG_SUM, attributes, null); |
| 178 | + |
| 179 | + MetricSnapshots snapshots = converter.convert(Collections.singletonList(metricData)); |
| 180 | + |
| 181 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("stringKey")) |
| 182 | + .isEqualTo("[\"stringValue1\",\"stringValue2\"]"); |
| 183 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("booleanKey")) |
| 184 | + .isEqualTo("[true,false]"); |
| 185 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("longKey")) |
| 186 | + .isEqualTo("[12345,6789]"); |
| 187 | + assertThat(snapshots.get(0).getDataPoints().get(0).getLabels().get("doubleKey")) |
| 188 | + .isEqualTo("[0.12345,0.6789]"); |
| 189 | + } |
| 190 | + |
140 | 191 | private static Stream<Arguments> resourceAttributesAdditionArgs() {
|
141 | 192 | List<Arguments> arguments = new ArrayList<>();
|
142 | 193 |
|
|
0 commit comments