Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datadog.trace.bootstrap.ClassHierarchyIterable;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.InternalSpanTypes;
import datadog.trace.bootstrap.instrumentation.api.ResourceNamePriorities;
import datadog.trace.bootstrap.instrumentation.api.Tags;
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
import datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator;
Expand Down Expand Up @@ -68,10 +69,18 @@ public void onJakartaRsSpan(
} else {
span.setResourceName(DECORATE.spanNameForMethod(target, method));

if (parent == parent.getLocalRootSpan()) {
if (parent.getLocalRootSpan().getResourceNamePriority()
< ResourceNamePriorities.HTTP_FRAMEWORK_ROUTE) {
parent.setTag(Tags.COMPONENT, "jakarta-rs");

// current handler is a filter
if (!httpMethodAndRoute.hasLeft()
&& (!httpMethodAndRoute.hasRight() || httpMethodAndRoute.getRight().length() == 0)) {
return;
}

HTTP_RESOURCE_DECORATOR.withRoute(
parent, httpMethodAndRoute.getLeft(), httpMethodAndRoute.getRight());
parent.getLocalRootSpan(), httpMethodAndRoute.getLeft(), httpMethodAndRoute.getRight());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public void handle(final RoutingContext routingContext) {
if (spanStarter) {
if (span == null) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
parentSpan = parentSpan.getLocalRootSpan();
}
routingContext.put(PARENT_SPAN_CONTEXT_KEY, parentSpan);

span = startSpan(INSTRUMENTATION_NAME);
Expand Down Expand Up @@ -69,6 +72,8 @@ private void setRoute(RoutingContext routingContext) {
return;
}

final AgentSpan routeSpan = parentSpan;

final String method = routingContext.request().rawMethod();
String mountPoint = routingContext.mountPoint();
String path = routingContext.currentRoute().getPath();
Expand All @@ -81,9 +86,9 @@ private void setRoute(RoutingContext routingContext) {
}
path = mountPoint + path;
}
if (method != null && path != null && shouldUpdateRoute(routingContext, parentSpan, path)) {
if (method != null && path != null && shouldUpdateRoute(routingContext, routeSpan, path)) {
routingContext.put(ROUTE_CONTEXT_KEY, path);
HTTP_RESOURCE_DECORATOR.withRoute(parentSpan, method, path, true);
HTTP_RESOURCE_DECORATOR.withRoute(routeSpan, method, path, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public void handle(final RoutingContext routingContext) {
if (spanStarter) {
if (span == null) {
AgentSpan parentSpan = activeSpan();
if (parentSpan != null) {
parentSpan = parentSpan.getLocalRootSpan();
}
routingContext.put(PARENT_SPAN_CONTEXT_KEY, parentSpan);

span = startSpan(INSTRUMENTATION_NAME);
Expand Down Expand Up @@ -66,6 +69,8 @@ private void setRoute(RoutingContext routingContext) {
return;
}

final AgentSpan routeSpan = parentSpan;

final String method = routingContext.request().method().name();
final String mountPoint = routingContext.mountPoint();

Expand All @@ -82,9 +87,9 @@ private void setRoute(RoutingContext routingContext) {
: mountPoint;
path = noBackslashhMountPoint + path;
}
if (method != null && path != null && shouldUpdateRoute(routingContext, parentSpan, path)) {
if (method != null && path != null && shouldUpdateRoute(routingContext, routeSpan, path)) {
routingContext.put(ROUTE_CONTEXT_KEY, path);
HTTP_RESOURCE_DECORATOR.withRoute(parentSpan, method, path, true);
HTTP_RESOURCE_DECORATOR.withRoute(routeSpan, method, path, true);
}
}

Expand Down
Loading