Skip to content

Commit f55ea06

Browse files
committed
WIP
1 parent 4fd66d4 commit f55ea06

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpServerDecorator.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ public Context startSpan(REQUEST_CARRIER carrier, Context parentContext) {
174174
extracted = startInferredProxySpan(parentContext, extracted);
175175
AgentSpan span =
176176
tracer().startSpan(instrumentationName, spanName(), extracted).setMeasured(true);
177+
// Register service-entry span with inferred proxy span (if present) so that premature
178+
// finish calls from child spans (e.g., Spring MVC handler) are deferred until the
179+
// service-entry span finishes (after the response status is known).
180+
registerServiceEntrySpanInInferredProxy(parentContext, span);
177181
// Apply RequestBlockingAction if any
178182
Flow<Void> flow = callIGCallbackRequestHeaders(span, carrier);
179183
if (flow.getAction() instanceof RequestBlockingAction) {
@@ -193,6 +197,14 @@ protected AgentSpanContext startInferredProxySpan(Context context, AgentSpanCont
193197
return span.start(extracted);
194198
}
195199

200+
private void registerServiceEntrySpanInInferredProxy(
201+
Context parentContext, AgentSpan serviceEntrySpan) {
202+
InferredProxySpan inferredProxy = InferredProxySpan.fromContext(parentContext);
203+
if (inferredProxy != null) {
204+
inferredProxy.registerServiceEntrySpan(serviceEntrySpan);
205+
}
206+
}
207+
196208
private final DataStreamsTransactionTracker.TransactionSourceReader
197209
DSM_TRANSACTION_SOURCE_READER =
198210
(source, headerName) -> {

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/TraceMapperV0_4.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public void accept(Metadata metadata) {
7171

7272
TagMap tags = metadata.getTags();
7373

74-
final boolean writeSamplingPriority = firstSpanInTrace || lastSpanInTrace;
74+
// Also write on top-level spans so that inferred proxy spans (which may be in the middle
75+
// of the serialized list due to phased-finish ordering) always carry the sampling decision.
76+
final boolean writeSamplingPriority =
77+
firstSpanInTrace || lastSpanInTrace || metadata.topLevel();
7578
final UTF8BytesString processTags = firstSpanInPayload ? metadata.processTags() : null;
7679
int metaSize =
7780
metadata.getBaggage().size()

dd-trace-core/src/main/java/datadog/trace/common/writer/ddagent/TraceMapperV0_5.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ MetaWriter forSpan(boolean firstInTrace, boolean lastInTrace, boolean firstInPay
202202

203203
@Override
204204
public void accept(Metadata metadata) {
205-
final boolean writeSamplingPriority = firstSpanInTrace || lastSpanInTrace;
205+
// Also write on top-level spans so that inferred proxy spans (which may be in the middle
206+
// of the serialized list due to phased-finish ordering) always carry the sampling decision.
207+
final boolean writeSamplingPriority =
208+
firstSpanInTrace || lastSpanInTrace || metadata.topLevel();
206209
final UTF8BytesString processTags = firstSpanInPayload ? metadata.processTags() : null;
207210

208211
TagMap tags = metadata.getTags();

0 commit comments

Comments
 (0)