Skip to content
Open
Changes from 2 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,12 +11,20 @@
import javax.annotation.Nullable;

public final class InternalTagsAdder extends TagsPostProcessor {
private final UTF8BytesString ddService;
private final UTF8BytesString version;
private final String ddService;
private final TagMap.Entry ddServiceEntry;
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.ddService = ddService;
this.ddServiceEntry =
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
Expand All @@ -28,12 +36,12 @@ public void processTags(

if (!ddService.toString().equalsIgnoreCase(spanContext.getServiceName())) {
// service name != DD_SERVICE
unsafeTags.set(DDTags.BASE_SERVICE, ddService);
unsafeTags.set(ddServiceEntry);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ddService == "", then TagMap.Entry.create returns ddServiceEntry == null, which will lead to an NPE here

Copy link
Copy Markdown
Contributor Author

@dougqh dougqh Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I let AI generate this.
I had also made DDSpan ignore setTag / setMetric null.

But I didn't do the same for TagMap, and I don't think that I want to. I'll go back and check the null handling more carefully.

Copy link
Copy Markdown
Contributor Author

@dougqh dougqh Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm going to just get rid of the ddService member variable altogether. TagMap.Entry caches the result of stringValue, so that will be just as good for the equalsIgnoreCase check.

It still isn't clear to me what the original intention was in the case when ddService is the empty string. If I recall correctly, DDSpan / DDSpanContext treat setting empty string as request to the delete the associated tag.

However, I'm not sure that's the intended semantic here. It is also strange because version does have explicit empty handling.

} 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