Minor cleanups to zipkin exporter. (#2836)
* Minor cleanups to zipkin exporter. * Another tiny cleanup
This commit is contained in:
parent
5d7f221058
commit
31a6da0bf5
|
|
@ -11,7 +11,6 @@ import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
|||
import io.opentelemetry.api.common.AttributeKey;
|
||||
import io.opentelemetry.api.common.AttributeType;
|
||||
import io.opentelemetry.api.common.Attributes;
|
||||
import io.opentelemetry.api.trace.SpanKind;
|
||||
import io.opentelemetry.api.trace.StatusCode;
|
||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
|
|
@ -78,10 +77,8 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
// don't crash the caller if there was a problem reading nics.
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.log(Level.FINE, "error reading nics", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -155,23 +152,18 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
|||
|
||||
@Nullable
|
||||
private static Span.Kind toSpanKind(SpanData spanData) {
|
||||
// This is a hack because the Span API did not have SpanKind.
|
||||
if (spanData.getKind() == SpanKind.SERVER) {
|
||||
switch (spanData.getKind()) {
|
||||
case SERVER:
|
||||
return Span.Kind.SERVER;
|
||||
}
|
||||
|
||||
// This is a hack because the Span API did not have SpanKind.
|
||||
if (spanData.getKind() == SpanKind.CLIENT || spanData.getName().startsWith("Sent.")) {
|
||||
case CLIENT:
|
||||
return Span.Kind.CLIENT;
|
||||
}
|
||||
|
||||
if (spanData.getKind() == SpanKind.PRODUCER) {
|
||||
case PRODUCER:
|
||||
return Span.Kind.PRODUCER;
|
||||
}
|
||||
if (spanData.getKind() == SpanKind.CONSUMER) {
|
||||
case CONSUMER:
|
||||
return Span.Kind.CONSUMER;
|
||||
case INTERNAL:
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -179,7 +171,7 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
|||
return NANOSECONDS.toMicros(epochNanos);
|
||||
}
|
||||
|
||||
private static <T> String valueToString(AttributeKey<?> key, Object attributeValue) {
|
||||
private static String valueToString(AttributeKey<?> key, Object attributeValue) {
|
||||
AttributeType type = key.getType();
|
||||
switch (type) {
|
||||
case STRING:
|
||||
|
|
|
|||
|
|
@ -169,6 +169,23 @@ class ZipkinSpanExporterTest {
|
|||
assertThat(exporter.generateSpan(data)).isEqualTo(expectedZipkinSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateSpan_defaultResourceServiceName() {
|
||||
SpanData data = buildStandardSpan().setResource(Resource.getEmpty()).build();
|
||||
|
||||
Endpoint expectedEndpoint =
|
||||
Endpoint.newBuilder()
|
||||
.serviceName(Resource.getDefault().getAttributes().get(ResourceAttributes.SERVICE_NAME))
|
||||
.ip(exporter.getLocalAddressForTest())
|
||||
.build();
|
||||
Span expectedZipkinSpan =
|
||||
buildZipkinSpan(Span.Kind.SERVER).toBuilder()
|
||||
.localEndpoint(expectedEndpoint)
|
||||
.putTag(ZipkinSpanExporter.OTEL_STATUS_CODE, "OK")
|
||||
.build();
|
||||
assertThat(exporter.generateSpan(data)).isEqualTo(expectedZipkinSpan);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateSpan_WithAttributes() {
|
||||
Attributes attributes =
|
||||
|
|
|
|||
Loading…
Reference in New Issue