Skip to content

Commit

Permalink
Use maven groupId:artifactId as the sdk name
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Dec 20, 2024
1 parent 4f213b8 commit 4d29690
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ private OtlpProtoV1Encoder(Builder builder) {
.errorTag(builder.errorTag)
.resourceAttributes(builder.resourceAttributes)
.instrumentationScope(builder.instrumentationScope)
// Use the fully-qualified class name as the SDK name following the spec
// https://opentelemetry.io/docs/specs/semconv/attributes-registry/telemetry/#telemetry-sdk-name
.telemetrySdkName(this.getClass().getName())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ final class SpanTranslator {
// Defined value in https://opentelemetry.io/docs/specs/semconv/attributes-registry/telemetry/#telemetry-sdk-language
static final String TELEMETRY_SDK_LANGUAGE = "java";

// Same version as the default instrumentation name
static final String TELEMETRY_SDK_NAME = BraveScope.NAME;

// Same version as the default instrumentation scope
static final String TELEMETRY_SDK_VERSION = BraveScope.VERSION;

Expand Down Expand Up @@ -78,8 +81,6 @@ final class SpanTranslator {

final InstrumentationScope instrumentationScope;

final String telemetrySdkName;

static final class Builder {
private TagMapper tagMapper;

Expand Down Expand Up @@ -108,11 +109,6 @@ Builder instrumentationScope(InstrumentationScope instrumentationScope) {
return this;
}

Builder telemetrySdkName(String telemetrySdkName) {
this.telemetrySdkName = telemetrySdkName;
return this;
}

SpanTranslator build() {
return new SpanTranslator(this);
}
Expand All @@ -126,7 +122,6 @@ static Builder newBuilder() {
this.tagMapper = builder.tagMapper;
this.resourceAttributes = builder.resourceAttributes;
this.instrumentationScope = builder.instrumentationScope;
this.telemetrySdkName = builder.telemetrySdkName;
}

TracesData translate(MutableSpan braveSpan) {
Expand Down Expand Up @@ -168,7 +163,7 @@ private Span.Builder builderForSingleSpan(MutableSpan span, ResourceSpans.Builde
resourceAttributes.forEach((k, v) -> resourceBuilder.addAttributes(stringAttribute(k, v)));
// Set Telemetry SDK resource attributes https://opentelemetry.io/docs/specs/semconv/attributes-registry/telemetry/
resourceBuilder.addAttributes(stringAttribute(SemanticConventionsAttributes.TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_LANGUAGE))
.addAttributes(stringAttribute(SemanticConventionsAttributes.TELEMETRY_SDK_NAME, this.telemetrySdkName))
.addAttributes(stringAttribute(SemanticConventionsAttributes.TELEMETRY_SDK_NAME, TELEMETRY_SDK_NAME))
.addAttributes(stringAttribute(SemanticConventionsAttributes.TELEMETRY_SDK_VERSION, TELEMETRY_SDK_VERSION));

maybeAddStringAttribute(spanBuilder, SemanticConventionsAttributes.NETWORK_LOCAL_ADDRESS, span.localIp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void testEncoder(Encoding encoding, BytesEncoder<MutableSpan> encoder, String en
.addAttributes(stringAttribute("other", "A"))
.setStatus(Status.newBuilder().setCode(Status.StatusCode.STATUS_CODE_OK).build());
resourceBuilder.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION));
} else {
scopeSpanBuilder.setScope(InstrumentationScope.newBuilder().build() /* empty */);
Expand Down Expand Up @@ -255,7 +255,7 @@ void testEncoderWithException(Encoding encoding, BytesEncoder<MutableSpan> encod
.setStatus(Status.newBuilder().setCode(Status.StatusCode.STATUS_CODE_ERROR).build());
resourceBuilder
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION));
} else {
scopeSpanBuilder.setScope(InstrumentationScope.newBuilder().build() /* empty */);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void generateSpan_remoteParent() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -102,7 +102,7 @@ void generateSpan_resourceAttributes() {
.addAttributes(stringAttribute("os.arch", "amd64"))
.addAttributes(stringAttribute("hostname", "localhost"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -146,7 +146,7 @@ void generateSpan_resourceAttributes_with_serviceName() {
.addAttributes(stringAttribute("os.arch", "amd64"))
.addAttributes(stringAttribute("hostname", "localhost"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -182,7 +182,7 @@ void generateSpan_subMicroDurations() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)).build())
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -216,7 +216,7 @@ void generateSpan_ServerKind() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -250,7 +250,7 @@ void generateSpan_ClientKind() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -284,7 +284,7 @@ void generateSpan_DefaultKind() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -318,7 +318,7 @@ void generateSpan_ConsumeKind() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -352,7 +352,7 @@ void generateSpan_ProducerKind() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "tweetiebird"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -387,7 +387,7 @@ void generateSpan_ResourceServiceNameMapping() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", "super-zipkin-service"))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -422,7 +422,7 @@ void generateSpan_defaultResourceServiceName() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -463,7 +463,7 @@ void generateSpan_RemoteEndpointMapping(Kind spanKind) {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -503,7 +503,7 @@ void generateSpan_RemoteEndpointMappingWhenKindIsNotClientOrProducer(Kind spanKi
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -542,7 +542,7 @@ void generateSpan_RemoteEndpointMappingWhenServiceNameIsMissing(Kind spanKind) {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -580,7 +580,7 @@ void generateSpan_RemoteEndpointMappingWhenPortIsMissing(Kind spanKind) {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -617,7 +617,7 @@ void generateSpan_RemoteEndpointMappingWhenIpAndPortAreMissing(Kind spanKind) {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -657,7 +657,7 @@ void generateSpan_WithAttributes() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -696,7 +696,7 @@ void generateSpan_WithInstrumentationLibraryInfo() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down Expand Up @@ -729,7 +729,7 @@ void generateSpan_AlreadyHasHttpStatusInfo() {
.setResource(io.opentelemetry.proto.resource.v1.Resource.newBuilder()
.addAttributes(stringAttribute("service.name", SpanTranslator.DEFAULT_SERVICE_NAME))
.addAttributes(stringAttribute("telemetry.sdk.language", "java"))
.addAttributes(stringAttribute("telemetry.sdk.name", OtlpProtoV1Encoder.class.getName()))
.addAttributes(stringAttribute("telemetry.sdk.name", BraveScope.NAME))
.addAttributes(stringAttribute("telemetry.sdk.version", BraveScope.VERSION)))
.addScopeSpans(ScopeSpans.newBuilder()
.setScope(InstrumentationScope.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class SpanTranslatorTest {
.errorTag(Tags.ERROR)
.resourceAttributes(Collections.emptyMap())
.instrumentationScope(BraveScope.instrumentationScope())
.telemetrySdkName(this.getClass().getName())
.build();

/**
Expand Down Expand Up @@ -118,7 +117,6 @@ void custom_implementationScope() {
.errorTag(Tags.ERROR)
.resourceAttributes(Collections.emptyMap())
.instrumentationScope(new zipkin2.reporter.otel.brave.InstrumentationScope("com.example.app", "3.3.5"))
.telemetrySdkName(this.getClass().getName())
.build();

TracesData tracesData = translator.translate(braveSpan);
Expand Down

0 comments on commit 4d29690

Please sign in to comment.