8000 Set the http.route also in the play span · DataDog/dd-trace-java@5097a43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5097a43

Browse files
Set the http.route also in the play span
1 parent e5e0581 commit 5097a43
< 8000 /div>

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

dd-java-agent/instrumentation/play-2.3/src/main/java/datadog/trace/instrumentation/play23/PlayHttpServerDecorator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class PlayHttpServerDecorator
2323
public static final CharSequence PLAY_REQUEST = UTF8BytesString.create("play.request");
2424
public static final CharSequence PLAY_ACTION = UTF8BytesString.create("play-action");
2525
public static final PlayHttpServerDecorator DECORATE = new PlayHttpServerDecorator();
26+
private static final boolean API_SECURITY_ENABLED = Config.get().isApiSecurityEnabled();
2627

2728
@Override
2829
protected String[] instrumentationNames() {
@@ -87,15 +88,20 @@ public AgentSpan onRequest(
8788
final Option pathOption = request.tags().get(Routes.ROUTE_PATTERN());
8889
if (!pathOption.isEmpty()) {
8990
final String path = (String) pathOption.get();
90-
HTTP_RESOURCE_DECORATOR.withRoute(spanForHttpRoute(span), request.method(), path);
91+
handleRoute(span, request.method(), path);
9192
}
9293
}
9394
return span;
9495
}
9596

96-
private AgentSpan spanForHttpRoute(final AgentSpan span) {
97-
final AgentSpan rootSpan = span.getLocalRootSpan();
98-
return rootSpan == null ? span : rootSpan;
97+
private void handleRoute(final AgentSpan span, final String method, final String route) {
98+
HTTP_RESOURCE_DECORATOR.withRoute(span, method, route);
99+
if (API_SECURITY_ENABLED) {
100+
final AgentSpan root = span.getLocalRootSpan();
101+
if (root != null) {
102+
HTTP_RESOURCE_DECORATOR.withRoute(root, method, route);
103+
}
104+
}
99105
}
100106

101107
@Override

dd-java-agent/instrumentation/play-2.4/src/main/java/datadog/trace/instrumentation/play24/PlayHttpServerDecorator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class PlayHttpServerDecorator
2323
public static final CharSequence PLAY_REQUEST = UTF8BytesString.create("play.request");
2424
public static final CharSequence PLAY_ACTION = UTF8BytesString.create("play-action");
2525
public static final PlayHttpServerDecorator DECORATE = new PlayHttpServerDecorator();
26+
private static final boolean API_SECURITY_ENABLED = Config.get().isApiSecurityEnabled();
2627

2728
@Override
2829
protected String[] instrumentationNames() {
@@ -87,15 +88,20 @@ public AgentSpan onRequest(
8788
final Option pathOption = request.tags().get("ROUTE_PATTERN");
8889
if (!pathOption.isEmpty()) {
8990
final String path = (String) pathOption.get();
90-
HTTP_RESOURCE_DECORATOR.withRoute(spanForHttpRoute(span), request.method(), path);
91+
handleRoute(span, request.method(), path);
9192
}
9293
}
9394
return span;
9495
}
9596

96-
private AgentSpan spanForHttpRoute(final AgentSpan span) {
97-
final AgentSpan rootSpan = span.getLocalRootSpan();
98-
return rootSpan == null ? span : rootSpan;
97+
private void handleRoute(final AgentSpan span, final String method, final String route) {
98+
HTTP_RESOURCE_DECORATOR.withRoute(span, method, route);
99+
if (API_SECURITY_ENABLED) {
100+
final AgentSpan root = span.getLocalRootSpan();
101+
if (root != null) {
102+
HTTP_RESOURCE_DECORATOR.withRoute(root, method, route);
103+
}
104+
}
99105
}
100106

101107
@Override

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class PlayHttpServerDecorator
3232
public static final CharSequence PLAY_REQUEST = UTF8BytesString.create("play.request");
3333
public static final CharSequence PLAY_ACTION = UTF8BytesString.create("play-action");
3434
public static final PlayHttpServerDecorator DECORATE = new PlayHttpServerDecorator();
35+
private static final boolean API_SECURITY_ENABLED = Config.get().isApiSecurityEnabled();
3536

3637
private static final MethodHandle TYPED_KEY_GET_UNDERLYING;
3738

@@ -141,15 +142,20 @@ public AgentSpan onRequest(
141142
CharSequence path =
142143
PATH_CACHE.computeIfAbsent(
143144
defOption.get().path(), p -> addMissingSlash(p, request.path()));
144-
HTTP_RESOURCE_DECORATOR.withRoute(spanForHttpRoute(span), request.method(), path, true);
145+
handleRoute(span, request.method(), path);
145146
}
146147
}
147148
return span;
148149
}
149150

150-
private AgentSpan spanForHttpRoute(final AgentSpan span) {
151-
final AgentSpan rootSpan = span.getLocalRootSpan();
152-
return rootSpan == null ? span : rootSpan;
151+
private void handleRoute(final AgentSpan span, final String method, final CharSequence route) {
152+
HTTP_RESOURCE_DECORATOR.withRoute(span, method, route, true);
153+
if (API_SECURITY_ENABLED) {
154+
final AgentSpan root = span.getLocalRootSpan();
155+
if (root != null) {
156+
HTTP_RESOURCE_DECORATOR.withRoute(root, method, route, true);
157+
}
158+
}
153159
}
154160

155161
/*

0 commit comments

Comments
 (0)
0