Skip to content

Commit 8fa65e0

Browse files
committed
Clean up. Fix 404 handling.
1 parent cd6af7c commit 8fa65e0

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public abstract class HttpServerDecorator<REQUEST, CONNECTION, RESPONSE, REQUEST
7373

7474
private static final UTF8BytesString DEFAULT_RESOURCE_NAME = UTF8BytesString.create("/");
7575
protected static final UTF8BytesString NOT_FOUND_RESOURCE_NAME = UTF8BytesString.create("404");
76-
private static final boolean SHOULD_SET_404_RESOURCE_NAME =
76+
protected static final boolean SHOULD_SET_404_RESOURCE_NAME =
7777
Config.get().isRuleEnabled("URLAsResourceNameRule")
7878
&& Config.get().isRuleEnabled("Status404Rule")
7979
&& Config.get().isRuleEnabled("Status404Decorator");
@@ -358,7 +358,6 @@ public AgentSpan onResponseStatus(final AgentSpan span, final int status) {
358358
}
359359

360360
if (SHOULD_SET_404_RESOURCE_NAME && status == 404) {
361-
// TODO
362361
span.setResourceName(NOT_FOUND_RESOURCE_NAME, ResourceNamePriorities.HTTP_404);
363362
}
364363
return span;

dd-java-agent/instrumentation/jax-rs-annotations-1/src/main/java/datadog/trace/instrumentation/jaxrs1/JaxRsAnnotationsDecorator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void onJaxRsSpan(
5757
// This check ensures that we only use the route from the first JAX-RS annotated method that
5858
// is executed
5959
if (parent.getLocalRootSpan().getResourceNamePriority()
60-
< ResourceNamePriorities.HTTP_FRAMEWORK_ROUTE) { // TODO
60+
< ResourceNamePriorities.HTTP_FRAMEWORK_ROUTE) {
6161
HTTP_RESOURCE_DECORATOR.withRoute(
6262
parent.getLocalRootSpan(), httpMethodAndRoute.getLeft(), httpMethodAndRoute.getRight());
6363
parent.getLocalRootSpan().setTag(Tags.COMPONENT, "jax-rs");

dd-java-agent/instrumentation/play-2.6/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ repositories {
6464
}
6565
}
6666

67-
addTestSuiteForDir('baseTest', 'baseTest')
68-
addTestSuiteForDir('latestDepTest', 'latestDepTest')
67+
addTestSuite('baseTest')
68+
addTestSuite('latestDepTest')
6969

7070
sourceSets {
7171
main_play27 {

dd-java-agent/instrumentation/play-2.6/src/main/java/datadog/trace/instrumentation/play26/PlayHttpServerDecorator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation;
99
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
1010
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
11+
import datadog.trace.bootstrap.instrumentation.api.ResourceNamePriorities;
1112
import datadog.trace.bootstrap.instrumentation.api.URIDataAdapter;
1213
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
1314
import datadog.trace.bootstrap.instrumentation.decorator.HttpServerDecorator;
@@ -186,4 +187,10 @@ public AgentSpan onError(final AgentSpan span, Throwable throwable) {
186187
}
187188
return super.onError(span, throwable);
188189
}
190+
191+
public void updateOn404Only(final AgentSpan span, final Result result) {
192+
if (SHOULD_SET_404_RESOURCE_NAME && status(result) == 404) {
193+
span.setResourceName(NOT_FOUND_RESOURCE_NAME, ResourceNamePriorities.HTTP_404);
194+
}
195+
}
189196
}

dd-java-agent/instrumentation/play-2.6/src/main/java/datadog/trace/instrumentation/play26/RequestCompleteCallback.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public Object apply(final Try<Result> result) {
2525
if (result.isFailure()) {
2626
DECORATE.onError(span, result.failed().get());
2727
} else {
28+
Result response = result.get();
2829
if (REPORT_HTTP_STATUS) {
29-
DECORATE.onResponse(span, result.get());
30+
DECORATE.onResponse(span, response);
31+
} else {
32+
DECORATE.updateOn404Only(span, response);
3033
}
3134
}
3235
DECORATE.beforeFinish(span);

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/base/HttpServerTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ abstract class HttpServerTest<SERVER> extends WithHttpServer<SERVER> {
191191

192192
String expectedResourceName(ServerEndpoint endpoint, String method, URI address) {
193193
if (endpoint.status == 404 && (changesAll404s() || endpoint.path == "/not-found")) {
194-
return "404" // TODO
194+
return "404"
195195
} else if (endpoint.hasPathParam) {
196196
return "$method ${testPathParam()}"
197197
}

dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,13 @@ public byte getResourceNamePriority() {
429429
public void setResourceName(final CharSequence resourceName, byte priority) {
430430
if (log.isDebugEnabled()) {
431431
log.debug(
432-
"setResourceName `{}`->`{}` with priority {}->{}",
432+
"setResourceName `{}`->`{}` with priority {}->{} for traceId={} spanId={}",
433433
this.resourceName,
434434
resourceName,
435435
resourceNamePriority,
436-
priority);
436+
priority,
437+
traceId,
438+
spanId);
437439
}
438440
if (null == resourceName) {
439441
return;

gradle/java_no_deps.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,20 @@ def isJavaVersionAllowedForProperty(JavaVersion version, String propertyPrefix =
298298
def definedMin = project.hasProperty(minProp)
299299
def definedMax = project.hasProperty(maxProp)
300300
if (definedMin && project.getProperty(minProp).compareTo(version) > 0) {
301+
logger.info("isJavaVersionAllowedForProperty is false b/o minProp=${minProp} is defined and greater than version=${version}")
301302
return false
302303
}
303304
//default to the general min if defined and specific one is was not defined
304305
if (!propertyPrefix.isEmpty() && !definedMin && project.hasProperty('minJavaVersionForTests') && project.getProperty('minJavaVersionForTests').compareTo(version) > 0) {
306+
logger.info("isJavaVersionAllowedForProperty is false b/o minJavaVersionForTests=${project.getProperty('minJavaVersionForTests')} is defined and greater than version=${version}")
305307
return false
306308
}
307309
if (definedMax && project.getProperty(maxProp).compareTo(version) < 0) {
310+
logger.info("isJavaVersionAllowedForProperty is false b/o maxProp=${project.getProperty(maxProp)} is defined and lower than version=${version}")
308311
return false
309312
}
310313
if (!propertyPrefix.isEmpty() && !definedMax && project.hasProperty('maxJavaVersionForTests') && project.getProperty('maxJavaVersionForTests').compareTo(version) < 0) {
314+
logger.info("isJavaVersionAllowedForProperty is false b/o maxJavaVersionForTests=${project.getProperty('maxJavaVersionForTests')} is defined and lower than version=${version}")
311315
return false
312316
}
313317
return true

0 commit comments

Comments
 (0)