Skip to content

Commit

Permalink
Refactored requires post-processing flag (#8104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinZakharov authored Dec 17, 2024
1 parent 772d178 commit 53cf809
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import datadog.trace.api.internal.TraceSegment;
import datadog.trace.api.telemetry.RuleType;
import datadog.trace.api.telemetry.WafMetricCollector;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import datadog.trace.bootstrap.instrumentation.api.URIDataAdapter;
import datadog.trace.util.stacktrace.StackTraceEvent;
Expand Down Expand Up @@ -618,18 +617,10 @@ private NoopFlow onRequestEnded(RequestContext ctx_, IGSpanInfo spanInfo) {
}
}

ctx.close(requiresPostProcessing(spanInfo));
ctx.close(spanInfo.isRequiresPostProcessing());
return NoopFlow.INSTANCE;
}

private boolean requiresPostProcessing(final IGSpanInfo spanInfo) {
if (!(spanInfo instanceof AgentSpan)) {
return true; // be conservative
}
final AgentSpan span = (AgentSpan) spanInfo;
return span.isRequiresPostProcessing();
}

private Flow<Void> onRequestHeadersDone(RequestContext ctx_) {
AppSecRequestContext ctx = ctx_.getData(RequestContextSlot.APPSEC);
if (ctx == null || ctx.isReqDataPublished()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import datadog.trace.common.writer.ddagent.PrioritizationStrategy;
import datadog.trace.core.CoreSpan;
import datadog.trace.core.DDSpan;
import datadog.trace.core.DDSpanContext;
import datadog.trace.core.monitor.HealthMetrics;
import datadog.trace.core.postprocessor.SpanPostProcessor;
import java.util.ArrayList;
Expand Down Expand Up @@ -266,8 +265,7 @@ private void maybeTracePostProcessing(List<DDSpan> trace) {
// Filter spans that need post-processing
List<DDSpan> spansToPostProcess = null;
for (DDSpan span : trace) {
DDSpanContext context = span.context();
if (context != null && context.isRequiresPostProcessing()) {
if (span.isRequiresPostProcessing()) {
if (spansToPostProcess == null) {
spansToPostProcess = new ArrayList<>();
}
Expand Down
5 changes: 5 additions & 0 deletions dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ public boolean isRequiresPostProcessing() {
return context.isRequiresPostProcessing();
}

@Override
public void setRequiresPostProcessing(boolean requiresPostProcessing) {
context.setRequiresPostProcessing(requiresPostProcessing);
}

// to be accessible in Spock spies, which the field wouldn't otherwise be
public long getStartTimeNano() {
return startTimeNano;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public interface IGSpanInfo {
void setRequestBlockingAction(Flow.Action.RequestBlockingAction rba);

Flow.Action.RequestBlockingAction getRequestBlockingAction();

boolean isRequiresPostProcessing();

void setRequiresPostProcessing(boolean requiresPostProcessing);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ public interface AgentSpan extends MutableSpan, IGSpanInfo, ImplicitContextKeyed

void addLink(AgentSpanLink link);

boolean isRequiresPostProcessing();

@Override
default ScopedContext storeInto(ScopedContext context) {
return context.with(ScopedContextKey.SPAN_KEY, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ public boolean isOutbound() {
public boolean isRequiresPostProcessing() {
return false;
}

@Override
public void setRequiresPostProcessing(boolean requiresPostProcessing) {}
}

public static final class NoopAgentScope implements AgentScope {
Expand Down

0 comments on commit 53cf809

Please sign in to comment.