Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add _dd.tracer_host to local root spans #7388

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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 @@ -83,6 +83,8 @@ class TagsAssert {
// If runtime id is actually different here, it might indicate that
// the Config class was loaded on multiple different class loaders.
assert tags[DDTags.RUNTIME_ID_TAG] == Config.get().runtimeId
assertedTags.add(DDTags.TRACER_HOST)
assert tags[DDTags.TRACER_HOST] == Config.get().getHostName()
} else {
assert tags[DDTags.RUNTIME_ID_TAG] == null
}
Expand Down
1 change: 1 addition & 0 deletions dd-trace-api/src/main/java/datadog/trace/api/DDTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DDTags {

/* Tags below are for internal use only. */
static final String INTERNAL_HOST_NAME = "_dd.hostname";
public static final String TRACER_HOST = "_dd.tracer_host";
public static final String RUNTIME_ID_TAG = "runtime-id";
public static final String RUNTIME_VERSION_TAG = "runtime_version";
static final String SERVICE = "service";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package datadog.trace.core.tagprocessor;

import datadog.trace.api.Config;
import datadog.trace.api.DDTags;
import datadog.trace.core.DDSpanContext;
import java.util.Map;

public class RemoteHostnameAdder implements TagsPostProcessor {
private final Config config;

public RemoteHostnameAdder(Config config) {
this.config = config;
}

@Override
public Map<String, Object> processTags(
Map<String, Object> unsafeTags, DDSpanContext spanContext) {
if (spanContext.getSpanId() == spanContext.getRootSpanId()) {
Copy link
Contributor

@dougqh dougqh Aug 7, 2024

Choose a reason for hiding this comment

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

That's a nice solution.
It does mean that this tag isn't usable in a tag sampling rule, but I think that's a reasonable _dd meta tags.

unsafeTags.put(DDTags.TRACER_HOST, config.getHostName());
}
return unsafeTags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

public final class TagsPostProcessorFactory {
private static boolean addBaseService = true;
private static boolean addRemoteHostname = true;

private static class Lazy {
private static TagsPostProcessor create() {
final List<TagsPostProcessor> processors = new ArrayList<>(addBaseService ? 3 : 2);
final List<TagsPostProcessor> processors = new ArrayList<>(4);
processors.add(new PeerServiceCalculator());
if (addBaseService) {
processors.add(new BaseServiceAdder(Config.get().getServiceName()));
}
processors.add(new QueryObfuscator(Config.get().getObfuscationQueryRegexp()));
if (addRemoteHostname) {
processors.add(new RemoteHostnameAdder(Config.get()));
}
return new PostProcessorChain(
processors.toArray(processors.toArray(new TagsPostProcessor[0])));
}
Expand All @@ -35,10 +39,19 @@ public static void withAddBaseService(boolean enabled) {
addBaseService = enabled;
Lazy.instance = Lazy.create();
}
/**
* Mostly used for test purposes.
*
* @param enabled if false, {@link RemoteHostnameAdder} is not put in the chain.
*/
public static void withAddRemoteHostname(boolean enabled) {
addRemoteHostname = enabled;
Lazy.instance = Lazy.create();
}

/** Used for testing purposes. It reset the singleton and restore default options */
public static void reset() {
withAddBaseService(true);
Lazy.instance = Lazy.create();
withAddRemoteHostname(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ abstract class DDCoreSpecification extends DDSpecification {
@Override
void setupSpec() {
TagsPostProcessorFactory.withAddBaseService(false)
TagsPostProcessorFactory.withAddRemoteHostname(false)
}

@Override
Expand Down
Loading