Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HttpRouteHolder in camel instrumentation #5242

Merged
Merged
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 @@ -24,9 +24,9 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel.decorators;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.server.ServerSpan;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource;
import io.opentelemetry.javaagent.instrumentation.apachecamel.CamelDirection;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -97,7 +97,7 @@ public void pre(
attributes.put(SemanticAttributes.HTTP_METHOD, getHttpMethod(exchange, endpoint));
}

private static boolean shouldSetPathAsName(CamelDirection camelDirection) {
static boolean shouldSetPathAsName(CamelDirection camelDirection) {
return CamelDirection.INBOUND.equals(camelDirection);
}

Expand All @@ -113,26 +113,21 @@ protected String getPath(Exchange exchange, Endpoint endpoint) {
}
}

private static boolean shouldUpdateServerSpanName(
Span serverSpan, CamelDirection camelDirection) {
return (serverSpan != null && shouldSetPathAsName(camelDirection));
}

private void updateServerSpanName(Span serverSpan, Exchange exchange, Endpoint endpoint) {
String path = getPath(exchange, endpoint);
if (path != null) {
// TODO should update SERVER span name/route using ServerSpanNaming
serverSpan.updateName(path);
}
}

@Override
public void updateServerSpanName(
Context context, Exchange exchange, Endpoint endpoint, CamelDirection camelDirection) {
Span serverSpan = ServerSpan.fromContextOrNull(context);
if (shouldUpdateServerSpanName(serverSpan, camelDirection)) {
updateServerSpanName(serverSpan, exchange, endpoint);
Context context,
Exchange camelExchange,
Endpoint camelEndpoint,
CamelDirection camelDirection) {
if (!shouldSetPathAsName(camelDirection)) {
return;
}
HttpRouteHolder.updateHttpRoute(
context,
HttpRouteSource.CONTROLLER,
(c, exchange, endpoint) -> getPath(exchange, endpoint),
camelExchange,
camelEndpoint);
}

protected String getHttpUrl(Exchange exchange, Endpoint endpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ class RestCamelTest extends AgentInstrumentationSpecification implements RetryOn
"$SemanticAttributes.NET_PEER_PORT" Long
"$SemanticAttributes.HTTP_SERVER_NAME" String
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
// TODO: camel instrumentation does not use ServerSpanNaming to update the route, so the matched route is provided by the servlet instrumentation
"$SemanticAttributes.HTTP_ROUTE" "/*"
"$SemanticAttributes.HTTP_ROUTE" "/api/{module}/unit/{unitId}"
}
}
it.span(3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ class TwoServicesWithDirectClientCamelTest extends AgentInstrumentationSpecifica
"$SemanticAttributes.HTTP_SERVER_NAME" String
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
"$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long
// TODO: camel instrumentation does not use ServerSpanNaming to update the route, so the matched route is provided by the servlet instrumentation
"$SemanticAttributes.HTTP_ROUTE" "/*"
"$SemanticAttributes.HTTP_ROUTE" "/serviceTwo"
}
}
it.span(5) {
Expand Down