Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the last attribute into tags and count the number of dropped attributes, when attributes with a duplicate key are set #17

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ static List<zipkin2.Span> translate(ExportTraceServiceRequest otelSpans) {
private static zipkin2.Span generateSpan(Span spanData, InstrumentationScope scope, Resource resource) {
long startTimestamp = nanoToMills(spanData.getStartTimeUnixNano());
long endTimestamp = nanoToMills(spanData.getEndTimeUnixNano());
Map<String, AnyValue> attributesMap = spanData.getAttributesList().stream().collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue));
Map<String, AnyValue> attributesMap = spanData.getAttributesList()
.stream()
.collect(Collectors.toMap(KeyValue::getKey, KeyValue::getValue, (a, b) -> b /* The latter wins */));
zipkin2.Span.Builder spanBuilder = zipkin2.Span.newBuilder();
byte[] traceIdBytes = spanData.getTraceId().toByteArray();
long high = bytesToLong(traceIdBytes, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,24 @@ void translate_WithRpcUnsetStatus() {
assertThat(SpanTranslator.translate(data))
.containsExactly(expectedSpan);
}


@Test
void translate_WithDuplicateKeys() {
ExportTraceServiceRequest data = requestBuilderWithSpanCustomizer(span -> span
.setKind(SpanKind.SPAN_KIND_SERVER)
.addAttributes(stringAttribute("foo", "bar1"))
.addAttributes(stringAttribute("foo", "bar2"))
.setStatus(Status.newBuilder().setCode(Status.StatusCode.STATUS_CODE_UNSET).build()))
.build();

Span expectedSpan =
zipkinSpanBuilder(Span.Kind.SERVER)
.putTag("foo", "bar2")
.putTag(SpanTranslator.OTEL_DROPPED_ATTRIBUTES_COUNT, "1")
.build();

assertThat(SpanTranslator.translate(data))
.containsExactly(expectedSpan);
}
}
Loading