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 @@ -10,15 +10,33 @@
public final class RemoteHostnameAdder extends TagsPostProcessor {
private final Supplier<String> hostnameSupplier;

private TagMap.Entry cachedHostEntry = null;

public RemoteHostnameAdder(Supplier<String> hostnameSupplier) {
this.hostnameSupplier = hostnameSupplier;
}

@Override
public void processTags(
TagMap unsafeTags, DDSpanContext spanContext, List<AgentSpanLink> spanLinks) {
if (spanContext.getSpanId() == spanContext.getRootSpanId()) {
unsafeTags.put(DDTags.TRACER_HOST, hostnameSupplier.get());
if (spanContext.getSpanId() != spanContext.getRootSpanId()) {
return;
}

String hostname = hostnameSupplier.get();
if (hostname == null) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is subtle change in behavior from before.
TagMap.put would have failed with an exception when given null.

I've decided to just ignore hostnameSupplier.get returning null instead.

return;
}

TagMap.Entry cachedHostEntry = this.cachedHostEntry;

if (cachedHostEntry != null && cachedHostEntry.objectValue().equals(hostname)) {
unsafeTags.set(cachedHostEntry);
return;
}

TagMap.Entry newEntry = TagMap.Entry.create(DDTags.TRACER_HOST, hostname);
unsafeTags.set(newEntry);
this.cachedHostEntry = newEntry;
}
}
Loading