GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move base and peer service adder before span is published by amarziali · Pull Request #9408 · DataDog/dd-trace-java

Move base and peer service adder before span is published #9408

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.

Sign up for GitHub

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

Merged
PerfectSlayer merged 3 commits into master from andrea.marziali/move-span-postprocessor-early
Aug 27, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Move base and peer service adder before span is published #9408

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
8358bca
Move base and peer service adder before span is published
amarziali Aug 22, 2025
0c0dd50
Change method signature to fix ugly groovy issues
amarziali Aug 22, 2025
4bc78b1
feat(tracer): Introduce eager span tag processors
PerfectSlayer Aug 26, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

7 changes: 7 additions & 0 deletions 7 dd-trace-core/src/main/java/datadog/trace/core/CoreSpan.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public interface CoreSpan<T extends CoreSpan<T>> {

CharSequence getType();

/**
* Runs early {@link datadog.trace.core.tagprocessor.TagsPostProcessor} like base service and peer
* service computation. Such tags are needed before span serialization so they can’t be processed
* lazily as part of the {@link #processTagsAndBaggage(MetadataConsumer)} API.
*/
void processServiceTags();

void processTagsAndBaggage(MetadataConsumer consumer);

T setSamplingPriority(int samplingPriority, int samplingMechanism);
Expand Down
6 changes: 6 additions & 0 deletions 6 dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,12 @@ void write(final List<DDSpan> trace) {
if (writtenTrace.isEmpty()) {
return;
}

// run early tag postprocessors before publishing to the metrics writer since peer / base
// service are needed
for (DDSpan span : writtenTrace) {
span.processServiceTags();
}
boolean forceKeep = metricsAggregator.publish(writtenTrace);

TraceCollector traceCollector = writtenTrace.get(0).context().getTraceCollector();
Expand Down
7 changes: 6 additions & 1 deletion 7 dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public String getSpanType() {

@Override
public TagMap getTags() {
// This is an imutable copy of the tags
// This is an immutable copy of the tags
return context.getTags();
}

Expand All @@ -703,6 +703,11 @@ public CharSequence getType() {
return context.getSpanType();
}

@Override
public void processServiceTags() {
context.earlyProcessTags(links);
}

@Override
public void processTagsAndBaggage(final MetadataConsumer consumer) {
context.processTagsAndBaggage(consumer, longRunningVersion, links);
Expand Down
8 changes: 7 additions & 1 deletion 8 dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,17 @@ public <T> void setMetaStruct(final String field, final T value) {
}
}

public void earlyProcessTags(List<AgentSpanLink> links) {
synchronized (unsafeTags) {
TagsPostProcessorFactory.eagerProcessor().processTags(unsafeTags, this, links);
}
}

public void processTagsAndBaggage(
final MetadataConsumer consumer, int longRunningVersion, List<AgentSpanLink> links) {
synchronized (unsafeTags) {
// Tags
TagsPostProcessorFactory.instance().processTags(unsafeTags, this, links);
TagsPostProcessorFactory.lazyProcessor().processTags(unsafeTags, this, links);

String linksTag = DDSpanLink.toTag(links);
if (linksTag != null) {
Expand Down
25 changes: 18 additions & 7 deletions 25 dd-trace-core/src/main/java/datadog/trace/core/tagprocessor/TagsPostProcessorFactory.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ public final class TagsPostProcessorFactory {
private static boolean addRemoteHostname = true;

private static class Lazy {
private static TagsPostProcessor create() {
final List<TagsPostProcessor> processors = new ArrayList<>(7);
private static TagsPostProcessor eagerProcessor = createEagerChain();
private static TagsPostProcessor lazyProcessor = createLazyChain();

private static TagsPostProcessor createEagerChain() {
final List<TagsPostProcessor> processors = new ArrayList<>(2);
processors.add(new PeerServiceCalculator());
if (addBaseService) {
processors.add(new BaseServiceAdder(Config.get().getServiceName()));
}
return new PostProcessorChain(processors.toArray(new TagsPostProcessor[0]));
}

private static TagsPostProcessor createLazyChain() {
final List<TagsPostProcessor> processors = new ArrayList<>(7);

processors.add(new QueryObfuscator(Config.get().getObfuscationQueryRegexp()));
if (addRemoteHostname) {
processors.add(new RemoteHostnameAdder(Config.get().getHostNameSupplier()));
Expand All @@ -36,12 +45,14 @@ private static TagsPostProcessor create() {
return new PostProcessorChain(
processors.toArray(processors.toArray(new TagsPostProcessor[0])));
}
}

private static TagsPostProcessor instance = create();
public static TagsPostProcessor eagerProcessor() {
return Lazy.eagerProcessor;
}

public static TagsPostProcessor instance() {
return Lazy.instance;
public static TagsPostProcessor lazyProcessor() {
return Lazy.lazyProcessor;
}

/**
Expand All @@ -51,7 +62,7 @@ public static TagsPostProcessor instance() {
*/
public static void withAddBaseService(boolean enabled) {
addBaseService = enabled;
Lazy.instance = Lazy.create();
Lazy.eagerProcessor = Lazy.createEagerChain();
}

/**
Expand All @@ -61,7 +72,7 @@ public static void withAddBaseService(boolean enabled) {
*/
public static void withAddRemoteHostname(boolean enabled) {
addRemoteHostname = enabled;
Lazy.instance = Lazy.create();
Lazy.lazyProcessor = Lazy.createLazyChain();
}

/** Used for testing purposes. It reset the singleton and restore default options */
Expand Down
3 changes: 3 additions & 0 deletions 3 dd-trace-core/src/test/groovy/datadog/trace/common/metrics/SimpleSpan.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ class SimpleSpan implements CoreSpan<SimpleSpan> {
return type
}

@Override
void processServiceTags() {}

@Override
void processTagsAndBaggage(MetadataConsumer consumer) {}

Expand Down
3 changes: 3 additions & 0 deletions 3 dd-trace-core/src/test/groovy/datadog/trace/common/writer/TraceGenerator.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ class TraceGenerator {
return this.type
}

@Override
void processServiceTags() {}

@Override
void processTagsAndBaggage(MetadataConsumer consumer) {
consumer.accept(metadata)
Expand Down
3 changes: 3 additions & 0 deletions 3 dd-trace-core/src/traceAgentTest/groovy/TraceGenerator.groovy
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ class TraceGenerator {
return type
}

@Override
void processServiceTags() {}

@Override
void processTagsAndBaggage(MetadataConsumer consumer) {
consumer.accept(metadata)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.