Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,35 @@
import javax.annotation.Nullable;

public final class InternalTagsAdder extends TagsPostProcessor {
private final UTF8BytesString ddService;
private final UTF8BytesString version;
private final TagMap.Entry baseServiceEntry;
private final TagMap.Entry versionEntry;

public InternalTagsAdder(@Nullable final String ddService, @Nullable final String version) {
this.ddService = ddService != null ? UTF8BytesString.create(ddService) : null;
this.version = version != null && !version.isEmpty() ? UTF8BytesString.create(version) : null;
this.baseServiceEntry =
ddService != null
? TagMap.Entry.create(DDTags.BASE_SERVICE, UTF8BytesString.create(ddService))
: null;
this.versionEntry =
version != null && !version.isEmpty()
? TagMap.Entry.create(VERSION, UTF8BytesString.create(version))
: null;
}

@Override
public void processTags(
TagMap unsafeTags, DDSpanContext spanContext, List<AgentSpanLink> spanLinks) {
if (spanContext == null || ddService == null) {
if (spanContext == null || baseServiceEntry == null) {
return;
}

if (!ddService.toString().equalsIgnoreCase(spanContext.getServiceName())) {
if (!baseServiceEntry.stringValue().equalsIgnoreCase(spanContext.getServiceName())) {
// service name != DD_SERVICE
unsafeTags.set(DDTags.BASE_SERVICE, ddService);
unsafeTags.set(baseServiceEntry);
} else {
// as per config consistency, the version tag is added across tracers only if
// the service name is DD_SERVICE and version tag is not manually set
if (version != null && !unsafeTags.containsKey(VERSION)) {
unsafeTags.set(VERSION, version);
if (versionEntry != null && !unsafeTags.containsKey(VERSION)) {
unsafeTags.set(versionEntry);
}
}
}
Expand Down
Loading