Export otel.scope.name, otel.scope.version (#4261)
This commit is contained in:
parent
9f870b8988
commit
ef99593d4f
|
@ -44,6 +44,8 @@ final class Adapter {
|
|||
static final String KEY_SPAN_KIND = "span.kind";
|
||||
static final String KEY_SPAN_STATUS_MESSAGE = "otel.status_message";
|
||||
static final String KEY_SPAN_STATUS_CODE = "otel.status_code";
|
||||
static final String KEY_INSTRUMENTATION_SCOPE_NAME = "otel.scope.name";
|
||||
static final String KEY_INSTRUMENTATION_SCOPE_VERSION = "otel.scope.version";
|
||||
static final String KEY_INSTRUMENTATION_LIBRARY_NAME = "otel.library.name";
|
||||
static final String KEY_INSTRUMENTATION_LIBRARY_VERSION = "otel.library.version";
|
||||
|
||||
|
@ -120,11 +122,19 @@ final class Adapter {
|
|||
.setVStr(span.getStatus().getStatusCode().name()));
|
||||
}
|
||||
|
||||
tags.add(
|
||||
new Tag(KEY_INSTRUMENTATION_SCOPE_NAME, TagType.STRING)
|
||||
.setVStr(span.getInstrumentationScopeInfo().getName()));
|
||||
// Include instrumentation library name for backwards compatibility
|
||||
tags.add(
|
||||
new Tag(KEY_INSTRUMENTATION_LIBRARY_NAME, TagType.STRING)
|
||||
.setVStr(span.getInstrumentationScopeInfo().getName()));
|
||||
|
||||
if (span.getInstrumentationScopeInfo().getVersion() != null) {
|
||||
tags.add(
|
||||
new Tag(KEY_INSTRUMENTATION_SCOPE_VERSION, TagType.STRING)
|
||||
.setVStr(span.getInstrumentationScopeInfo().getVersion()));
|
||||
// Include instrumentation library name for backwards compatibility
|
||||
tags.add(
|
||||
new Tag(KEY_INSTRUMENTATION_LIBRARY_VERSION, TagType.STRING)
|
||||
.setVStr(span.getInstrumentationScopeInfo().getVersion()));
|
||||
|
|
|
@ -85,7 +85,7 @@ class AdapterTest {
|
|||
assertThat(jaegerSpan.getStartTime()).isEqualTo(MILLISECONDS.toMicros(startMs));
|
||||
assertThat(jaegerSpan.getDuration()).isEqualTo(MILLISECONDS.toMicros(duration));
|
||||
|
||||
assertThat(jaegerSpan.getTagsSize()).isEqualTo(7);
|
||||
assertThat(jaegerSpan.getTagsSize()).isEqualTo(8);
|
||||
assertThat(getValue(jaegerSpan.getTags(), Adapter.KEY_SPAN_KIND).getVStr()).isEqualTo("server");
|
||||
assertThat(getValue(jaegerSpan.getTags(), Adapter.KEY_SPAN_STATUS_CODE).getVLong())
|
||||
.isEqualTo(0);
|
||||
|
@ -119,7 +119,7 @@ class AdapterTest {
|
|||
// test
|
||||
io.jaegertracing.thriftjava.Span jaegerSpan = Adapter.toJaeger(span);
|
||||
|
||||
assertThat(jaegerSpan.getTagsSize()).isEqualTo(4);
|
||||
assertThat(jaegerSpan.getTagsSize()).isEqualTo(5);
|
||||
assertThat(getValue(jaegerSpan.getTags(), Adapter.KEY_SPAN_KIND)).isNull();
|
||||
}
|
||||
|
||||
|
|
|
@ -129,8 +129,11 @@ class JaegerThriftSpanExporterTest {
|
|||
.setLogs(Collections.emptyList());
|
||||
expectedSpan.addToTags(new Tag("span.kind", TagType.STRING).setVStr("consumer"));
|
||||
expectedSpan.addToTags(new Tag("otel.status_code", TagType.STRING).setVStr("OK"));
|
||||
expectedSpan.addToTags(
|
||||
new Tag("otel.scope.name", TagType.STRING).setVStr("io.opentelemetry.auto"));
|
||||
expectedSpan.addToTags(
|
||||
new Tag("otel.library.name", TagType.STRING).setVStr("io.opentelemetry.auto"));
|
||||
expectedSpan.addToTags(new Tag("otel.scope.version", TagType.STRING).setVStr("1.0.0"));
|
||||
expectedSpan.addToTags(new Tag("otel.library.version", TagType.STRING).setVStr("1.0.0"));
|
||||
|
||||
List<Span> expectedSpans = Collections.singletonList(expectedSpan);
|
||||
|
@ -228,8 +231,11 @@ class JaegerThriftSpanExporterTest {
|
|||
.setLogs(Collections.emptyList());
|
||||
expectedSpan1.addToTags(new Tag("span.kind", TagType.STRING).setVStr("consumer"));
|
||||
expectedSpan1.addToTags(new Tag("otel.status_code", TagType.STRING).setVStr("OK"));
|
||||
expectedSpan1.addToTags(
|
||||
new Tag("otel.scope.name", TagType.STRING).setVStr("io.opentelemetry.auto"));
|
||||
expectedSpan1.addToTags(
|
||||
new Tag("otel.library.name", TagType.STRING).setVStr("io.opentelemetry.auto"));
|
||||
expectedSpan1.addToTags(new Tag("otel.scope.version", TagType.STRING).setVStr("1.0.0"));
|
||||
expectedSpan1.addToTags(new Tag("otel.library.version", TagType.STRING).setVStr("1.0.0"));
|
||||
|
||||
Span expectedSpan2 =
|
||||
|
@ -244,8 +250,11 @@ class JaegerThriftSpanExporterTest {
|
|||
.setLogs(Collections.emptyList());
|
||||
expectedSpan2.addToTags(new Tag("span.kind", TagType.STRING).setVStr("consumer"));
|
||||
expectedSpan2.addToTags(new Tag("otel.status_code", TagType.STRING).setVStr("OK"));
|
||||
expectedSpan2.addToTags(
|
||||
new Tag("otel.scope.name", TagType.STRING).setVStr("io.opentelemetry.auto"));
|
||||
expectedSpan2.addToTags(
|
||||
new Tag("otel.library.name", TagType.STRING).setVStr("io.opentelemetry.auto"));
|
||||
expectedSpan2.addToTags(new Tag("otel.scope.version", TagType.STRING).setVStr("1.0.0"));
|
||||
expectedSpan2.addToTags(new Tag("otel.library.version", TagType.STRING).setVStr("1.0.0"));
|
||||
|
||||
verify(thriftSender).send(expectedProcess2, Collections.singletonList(expectedSpan2));
|
||||
|
|
|
@ -32,6 +32,10 @@ final class SpanMarshaler extends MarshalerWithSize {
|
|||
AttributeKey.stringKey("otel.status_description");
|
||||
private static final AttributeKey<String> KEY_SPAN_STATUS_CODE =
|
||||
AttributeKey.stringKey("otel.status_code");
|
||||
private static final AttributeKey<String> KEY_INSTRUMENTATION_SCOPE_NAME =
|
||||
AttributeKey.stringKey("otel.scope.name");
|
||||
private static final AttributeKey<String> KEY_INSTRUMENTATION_SCOPE_VERSION =
|
||||
AttributeKey.stringKey("otel.scope.version");
|
||||
private static final AttributeKey<String> KEY_INSTRUMENTATION_LIBRARY_NAME =
|
||||
AttributeKey.stringKey("otel.library.name");
|
||||
private static final AttributeKey<String> KEY_INSTRUMENTATION_LIBRARY_VERSION =
|
||||
|
@ -98,11 +102,19 @@ final class SpanMarshaler extends MarshalerWithSize {
|
|||
KeyValueMarshaler.create(KEY_SPAN_STATUS_CODE, span.getStatus().getStatusCode().name()));
|
||||
}
|
||||
|
||||
tags.add(
|
||||
KeyValueMarshaler.create(
|
||||
KEY_INSTRUMENTATION_SCOPE_NAME, span.getInstrumentationScopeInfo().getName()));
|
||||
// Include instrumentation library name for backwards compatibility
|
||||
tags.add(
|
||||
KeyValueMarshaler.create(
|
||||
KEY_INSTRUMENTATION_LIBRARY_NAME, span.getInstrumentationScopeInfo().getName()));
|
||||
|
||||
if (span.getInstrumentationScopeInfo().getVersion() != null) {
|
||||
tags.add(
|
||||
KeyValueMarshaler.create(
|
||||
KEY_INSTRUMENTATION_SCOPE_VERSION, span.getInstrumentationScopeInfo().getVersion()));
|
||||
// Include instrumentation library name for backwards compatibility
|
||||
tags.add(
|
||||
KeyValueMarshaler.create(
|
||||
KEY_INSTRUMENTATION_LIBRARY_VERSION,
|
||||
|
|
|
@ -249,6 +249,12 @@ class JaegerGrpcSpanExporterTest {
|
|||
assertThat(TraceId.fromBytes(batch.getSpans(0).getTraceId().toByteArray())).isEqualTo(TRACE_ID);
|
||||
assertThat(batch.getProcess().getTagsCount()).isEqualTo(5);
|
||||
|
||||
assertThat(
|
||||
getSpanTagValue(batch.getSpans(0), "otel.scope.name")
|
||||
.orElseThrow(() -> new AssertionError("otel.scope.name not found"))
|
||||
.getVStr())
|
||||
.isEqualTo("io.opentelemetry.auto");
|
||||
|
||||
assertThat(
|
||||
getSpanTagValue(batch.getSpans(0), "otel.library.name")
|
||||
.orElseThrow(() -> new AssertionError("otel.library.name not found"))
|
||||
|
@ -261,6 +267,12 @@ class JaegerGrpcSpanExporterTest {
|
|||
.getVStr())
|
||||
.isEqualTo("1.0.0");
|
||||
|
||||
assertThat(
|
||||
getSpanTagValue(batch.getSpans(0), "otel.scope.version")
|
||||
.orElseThrow(() -> new AssertionError("otel.scope.version not found"))
|
||||
.getVStr())
|
||||
.isEqualTo("1.0.0");
|
||||
|
||||
assertThat(
|
||||
getTagValue(batch.getProcess().getTagsList(), "ip")
|
||||
.orElseThrow(() -> new AssertionError("ip not found"))
|
||||
|
|
|
@ -92,7 +92,7 @@ class PostSpansRequestMarshalerTest {
|
|||
assertThat(jaegerSpan.getStartTime()).isEqualTo(Timestamps.fromMillis(startMs));
|
||||
assertThat(jaegerSpan.getDuration()).isEqualTo(Durations.fromMillis(duration));
|
||||
|
||||
assertThat(jaegerSpan.getTagsCount()).isEqualTo(6);
|
||||
assertThat(jaegerSpan.getTagsCount()).isEqualTo(7);
|
||||
Model.KeyValue keyValue = getValue(jaegerSpan.getTagsList(), KEY_SPAN_KIND);
|
||||
assertThat(keyValue).isNotNull();
|
||||
assertThat(keyValue.getVStr()).isEqualTo("server");
|
||||
|
|
|
@ -52,6 +52,8 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
|||
static final String OTEL_STATUS_CODE = "otel.status_code";
|
||||
static final AttributeKey<String> STATUS_ERROR = stringKey("error");
|
||||
|
||||
static final String KEY_INSTRUMENTATION_SCOPE_NAME = "otel.scope.name";
|
||||
static final String KEY_INSTRUMENTATION_SCOPE_VERSION = "otel.scope.version";
|
||||
static final String KEY_INSTRUMENTATION_LIBRARY_NAME = "otel.library.name";
|
||||
static final String KEY_INSTRUMENTATION_LIBRARY_VERSION = "otel.library.version";
|
||||
|
||||
|
@ -130,9 +132,13 @@ public final class ZipkinSpanExporter implements SpanExporter {
|
|||
InstrumentationScopeInfo instrumentationScopeInfo = spanData.getInstrumentationScopeInfo();
|
||||
|
||||
if (!instrumentationScopeInfo.getName().isEmpty()) {
|
||||
spanBuilder.putTag(KEY_INSTRUMENTATION_SCOPE_NAME, instrumentationScopeInfo.getName());
|
||||
// Include instrumentation library name for backwards compatibility
|
||||
spanBuilder.putTag(KEY_INSTRUMENTATION_LIBRARY_NAME, instrumentationScopeInfo.getName());
|
||||
}
|
||||
if (instrumentationScopeInfo.getVersion() != null) {
|
||||
spanBuilder.putTag(KEY_INSTRUMENTATION_SCOPE_VERSION, instrumentationScopeInfo.getVersion());
|
||||
// Include instrumentation library name for backwards compatibility
|
||||
spanBuilder.putTag(
|
||||
KEY_INSTRUMENTATION_LIBRARY_VERSION, instrumentationScopeInfo.getVersion());
|
||||
}
|
||||
|
|
|
@ -239,6 +239,8 @@ class ZipkinSpanExporterTest {
|
|||
assertThat(exporter.generateSpan(data))
|
||||
.isEqualTo(
|
||||
buildZipkinSpan(Span.Kind.CLIENT).toBuilder()
|
||||
.putTag("otel.scope.name", "io.opentelemetry.auto")
|
||||
.putTag("otel.scope.version", "1.0.0")
|
||||
.putTag("otel.library.name", "io.opentelemetry.auto")
|
||||
.putTag("otel.library.version", "1.0.0")
|
||||
.putTag(ZipkinSpanExporter.OTEL_STATUS_CODE, "OK")
|
||||
|
|
Loading…
Reference in New Issue