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

Set the annotation name to the same as the event name if the attributes are empty #16

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 @@ -28,7 +28,6 @@
import io.opentelemetry.semconv.OtelAttributes;
import io.opentelemetry.semconv.ServiceAttributes;
import zipkin2.Endpoint;
import zipkin2.collector.CollectorMetrics;

import static java.util.concurrent.TimeUnit.NANOSECONDS;

Expand All @@ -54,7 +53,7 @@ static List<zipkin2.Span> translate(ExportTraceServiceRequest otelSpans) {
for (ScopeSpans scopeSpans : resourceSpans.getScopeSpansList()) {
InstrumentationScope scope = scopeSpans.getScope();
for (io.opentelemetry.proto.trace.v1.Span span : scopeSpans.getSpansList()) {
spans.add(generateSpan(span, scope, resourceSpans.getResource()));
spans.add(generateSpan(span, scope, resourceSpans.getResource()));
}
}
}
Expand Down Expand Up @@ -118,8 +117,15 @@ private static zipkin2.Span generateSpan(Span spanData, InstrumentationScope sco
for (Event eventData : spanData.getEventsList()) {
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md#events
String name = eventData.getName();
String value = ProtoUtils.kvListToJson(eventData.getAttributesList());
String annotation = "\"" + name + "\":" + value;
List<KeyValue> attributesList = eventData.getAttributesList();
String annotation;
if (attributesList.isEmpty()) {
annotation = name;
}
else {
String value = ProtoUtils.kvListToJson(attributesList);
annotation = "\"" + name + "\":" + value;
}
spanBuilder.addAnnotation(nanoToMills(eventData.getTimeUnixNano()), annotation);
}
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/mapping-to-non-otlp.md#dropped-events-count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ void testServerKindWithEvents() throws Exception {
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md#events
assertThat(span.annotations().get(0).value()).isEqualTo("\"event-1\":{\"foo\":\"bar\",\"i\":" + i + "}");
assertThat(span.annotations().get(0).timestamp()).isEqualTo(toMillis(eventTime1.plusMillis(size)));
assertThat(span.annotations().get(1).value()).isEqualTo("\"event-2\":{}");
assertThat(span.annotations().get(1).value()).isEqualTo("event-2");
assertThat(span.annotations().get(1).timestamp()).isEqualTo(toMillis(eventTime2.plusMillis(size)));
assertThat(span.annotations().get(2).value()).isEqualTo("\"event-3\":{}");
assertThat(span.annotations().get(2).value()).isEqualTo("event-3");
assertThat(span.annotations().get(2).timestamp()).isEqualTo(toMillis(eventTime3.plusMillis(size)));
}
assertThat(metrics.spans()).isEqualTo(size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static Span.Builder zipkinSpanBuilder(Span.Kind kind) {
.duration((1505855799000000L + 465726528L / 1000) - (1505855794000000L + 194009601L / 1000))
.localEndpoint(Endpoint.newBuilder().ip("1.2.3.4").serviceName("tweetiebird").build())
.putTag(NetworkAttributes.NETWORK_LOCAL_ADDRESS.getKey(), "1.2.3.4")
.addAnnotation(1505855799000000L + 433901068L / 1000, "\"RECEIVED\":{}")
.addAnnotation(1505855799000000L + 459486280L / 1000, "\"SENT\":{}");
.addAnnotation(1505855799000000L + 433901068L / 1000, "RECEIVED")
.addAnnotation(1505855799000000L + 459486280L / 1000, "SENT");
}

static ExportTraceServiceRequest.Builder requestBuilder(
Expand Down
Loading