Skip to content

Commit

Permalink
Export otel.scope.name, otel.scope.version (#4261)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Mar 15, 2022
1 parent 9f870b8 commit ef99593
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -120,11 +122,19 @@ static Span toJaeger(SpanData span) {
.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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void testThriftSpan() {
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);
Expand Down Expand Up @@ -119,7 +119,7 @@ void testThriftSpan_internal() {
// 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ void testExport() throws SenderException, UnknownHostException {
.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);
Expand Down Expand Up @@ -228,8 +231,11 @@ void testExportMultipleResources() throws SenderException, UnknownHostException
.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 =
Expand All @@ -244,8 +250,11 @@ void testExportMultipleResources() throws SenderException, UnknownHostException
.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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -98,11 +102,19 @@ static SpanMarshaler create(SpanData span) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ private static void verifyBatch(Model.Batch batch) throws Exception {
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"))
Expand All @@ -261,6 +267,12 @@ private static void verifyBatch(Model.Batch batch) throws Exception {
.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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void testProtoSpan() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -130,9 +132,13 @@ Span generateSpan(SpanData spanData) {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ void generateSpan_WithInstrumentationLibraryInfo() {
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")
Expand Down

0 comments on commit ef99593

Please sign in to comment.