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.AttributeKey;
|
||||||
import io.opentelemetry.api.common.AttributeType;
|
import io.opentelemetry.api.common.AttributeType;
|
||||||
import io.opentelemetry.api.common.Attributes;
|
import io.opentelemetry.api.common.Attributes;
|
||||||
import io.opentelemetry.api.trace.SpanKind;
|
|
||||||
import io.opentelemetry.api.trace.StatusCode;
|
import io.opentelemetry.api.trace.StatusCode;
|
||||||
import io.opentelemetry.sdk.common.CompletableResultCode;
|
import io.opentelemetry.sdk.common.CompletableResultCode;
|
||||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||||
|
|
@ -78,9 +77,7 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// don't crash the caller if there was a problem reading nics.
|
// 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);
|
||||||
logger.log(Level.FINE, "error reading nics", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -155,23 +152,18 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Span.Kind toSpanKind(SpanData spanData) {
|
private static Span.Kind toSpanKind(SpanData spanData) {
|
||||||
// This is a hack because the Span API did not have SpanKind.
|
switch (spanData.getKind()) {
|
||||||
if (spanData.getKind() == SpanKind.SERVER) {
|
case SERVER:
|
||||||
return Span.Kind.SERVER;
|
return Span.Kind.SERVER;
|
||||||
|
case CLIENT:
|
||||||
|
return Span.Kind.CLIENT;
|
||||||
|
case PRODUCER:
|
||||||
|
return Span.Kind.PRODUCER;
|
||||||
|
case CONSUMER:
|
||||||
|
return Span.Kind.CONSUMER;
|
||||||
|
case INTERNAL:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a hack because the Span API did not have SpanKind.
|
|
||||||
if (spanData.getKind() == SpanKind.CLIENT || spanData.getName().startsWith("Sent.")) {
|
|
||||||
return Span.Kind.CLIENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (spanData.getKind() == SpanKind.PRODUCER) {
|
|
||||||
return Span.Kind.PRODUCER;
|
|
||||||
}
|
|
||||||
if (spanData.getKind() == SpanKind.CONSUMER) {
|
|
||||||
return Span.Kind.CONSUMER;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,7 +171,7 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
||||||
return NANOSECONDS.toMicros(epochNanos);
|
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();
|
AttributeType type = key.getType();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case STRING:
|
case STRING:
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,23 @@ class ZipkinSpanExporterTest {
|
||||||
assertThat(exporter.generateSpan(data)).isEqualTo(expectedZipkinSpan);
|
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
|
@Test
|
||||||
void generateSpan_WithAttributes() {
|
void generateSpan_WithAttributes() {
|
||||||
Attributes attributes =
|
Attributes attributes =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue