Skip to content

Commit 15fe8c6

Browse files
committed
feat(core): Clean up HttpServerDecorator
1 parent 9c904a0 commit 15fe8c6

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,9 @@ public Context extract(REQUEST_CARRIER carrier) {
142142
public Context startSpan(REQUEST_CARRIER carrier, Context context) {
143143
String instrumentationName =
144144
instrumentationNames().length == 0 ? "http-server" : instrumentationNames()[0];
145-
AgentSpanContext.Extracted spanContext = getExtractedSpanContext(context);
145+
AgentSpanContext.Extracted extracted = callIGCallbackStart(context);
146146
AgentSpan span =
147-
tracer()
148-
.startSpan(instrumentationName, spanName(), callIGCallbackStart(spanContext))
149-
.setMeasured(true);
147+
tracer().startSpan(instrumentationName, spanName(), extracted).setMeasured(true);
150148
Flow<Void> flow = callIGCallbackRequestHeaders(span, carrier);
151149
if (flow.getAction() instanceof Flow.Action.RequestBlockingAction) {
152150
span.setRequestBlockingAction((Flow.Action.RequestBlockingAction) flow.getAction());
@@ -158,20 +156,6 @@ public Context startSpan(REQUEST_CARRIER carrier, Context context) {
158156
return context.with(span);
159157
}
160158

161-
// /**
162-
// * Use {@code startSpan(String instrumentationName, REQUEST_CARRIER carrier, Context context)}
163-
// instead.
164-
// */
165-
// @Deprecated
166-
// public Context startSpan(REQUEST_CARRIER carrier, Context context) {
167-
// return startSpan("http-server", carrier, context);
168-
// }
169-
170-
public AgentSpanContext.Extracted getExtractedSpanContext(Context context) {
171-
AgentSpan extractedSpan = AgentSpan.fromContext(context);
172-
return extractedSpan == null ? null : (AgentSpanContext.Extracted) extractedSpan.context();
173-
}
174-
175159
public AgentSpan onRequest(
176160
final AgentSpan span,
177161
final CONNECTION connection,
@@ -180,6 +164,11 @@ public AgentSpan onRequest(
180164
return onRequest(span, connection, request, getExtractedSpanContext(context));
181165
}
182166

167+
public AgentSpanContext.Extracted getExtractedSpanContext(Context context) {
168+
AgentSpan extractedSpan = AgentSpan.fromContext(context);
169+
return extractedSpan == null ? null : (AgentSpanContext.Extracted) extractedSpan.context();
170+
}
171+
183172
public AgentSpan onRequest(
184173
final AgentSpan span,
185174
final CONNECTION connection,
@@ -395,22 +384,23 @@ public AgentSpan onResponse(final AgentSpan span, final RESPONSE response) {
395384
return span;
396385
}
397386

398-
private AgentSpanContext.Extracted callIGCallbackStart(final AgentSpanContext.Extracted context) {
387+
private AgentSpanContext.Extracted callIGCallbackStart(final Context context) {
388+
AgentSpanContext.Extracted extracted = getExtractedSpanContext(context);
399389
AgentTracer.TracerAPI tracer = tracer();
400390
Supplier<Flow<Object>> startedCbAppSec =
401391
tracer.getCallbackProvider(RequestContextSlot.APPSEC).getCallback(EVENTS.requestStarted());
402392
Supplier<Flow<Object>> startedCbIast =
403393
tracer.getCallbackProvider(RequestContextSlot.IAST).getCallback(EVENTS.requestStarted());
404394

405395
if (startedCbAppSec == null && startedCbIast == null) {
406-
return context;
396+
return extracted;
407397
}
408398

409399
TagContext tagContext = null;
410-
if (context == null) {
400+
if (extracted == null) {
411401
tagContext = new TagContext();
412-
} else if (context instanceof TagContext) {
413-
tagContext = (TagContext) context;
402+
} else if (extracted instanceof TagContext) {
403+
tagContext = (TagContext) extracted;
414404
}
415405

416406
if (tagContext != null) {
@@ -423,7 +413,7 @@ private AgentSpanContext.Extracted callIGCallbackStart(final AgentSpanContext.Ex
423413
return tagContext;
424414
}
425415

426-
return context;
416+
return extracted;
427417
}
428418

429419
@Override

0 commit comments

Comments
 (0)