Use HttpRouteHolder in spark instrumentation (#5241)
This commit is contained in:
parent
9ff7b92841
commit
817b3d2671
|
@ -10,10 +10,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||||
|
|
||||||
import io.opentelemetry.api.trace.Span;
|
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
||||||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
||||||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
|
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
import net.bytebuddy.description.type.TypeDescription;
|
import net.bytebuddy.description.type.TypeDescription;
|
||||||
import net.bytebuddy.matcher.ElementMatcher;
|
import net.bytebuddy.matcher.ElementMatcher;
|
||||||
|
@ -40,12 +38,7 @@ public class RoutesInstrumentation implements TypeInstrumentation {
|
||||||
|
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void routeMatchEnricher(@Advice.Return RouteMatch routeMatch) {
|
public static void routeMatchEnricher(@Advice.Return RouteMatch routeMatch) {
|
||||||
|
SparkRouteUpdater.updateHttpRoute(routeMatch);
|
||||||
Span span = Java8BytecodeBridge.currentSpan();
|
|
||||||
if (span != null && routeMatch != null) {
|
|
||||||
// TODO should update SERVER span name/route using ServerSpanNaming
|
|
||||||
span.updateName(routeMatch.getMatchUri());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.sparkjava;
|
||||||
|
|
||||||
|
import io.opentelemetry.context.Context;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder;
|
||||||
|
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import spark.routematch.RouteMatch;
|
||||||
|
|
||||||
|
public final class SparkRouteUpdater {
|
||||||
|
|
||||||
|
public static void updateHttpRoute(@Nullable RouteMatch routeMatch) {
|
||||||
|
if (routeMatch != null) {
|
||||||
|
Context context = Context.current();
|
||||||
|
HttpRouteHolder.updateHttpRoute(
|
||||||
|
context, HttpRouteSource.CONTROLLER, (c, r) -> r.getMatchUri(), routeMatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private SparkRouteUpdater() {}
|
||||||
|
}
|
|
@ -3,8 +3,6 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
|
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||||
|
@ -13,6 +11,7 @@ import spark.Spark
|
||||||
import spock.lang.Shared
|
import spock.lang.Shared
|
||||||
|
|
||||||
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
||||||
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP
|
||||||
|
|
||||||
class SparkJavaBasedTest extends AgentInstrumentationSpecification {
|
class SparkJavaBasedTest extends AgentInstrumentationSpecification {
|
||||||
|
|
||||||
|
@ -48,6 +47,7 @@ class SparkJavaBasedTest extends AgentInstrumentationSpecification {
|
||||||
kind SERVER
|
kind SERVER
|
||||||
hasNoParent()
|
hasNoParent()
|
||||||
attributes {
|
attributes {
|
||||||
|
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
||||||
"$SemanticAttributes.NET_PEER_IP" "127.0.0.1"
|
"$SemanticAttributes.NET_PEER_IP" "127.0.0.1"
|
||||||
"$SemanticAttributes.NET_PEER_PORT" Long
|
"$SemanticAttributes.NET_PEER_PORT" Long
|
||||||
"$SemanticAttributes.HTTP_SCHEME" "http"
|
"$SemanticAttributes.HTTP_SCHEME" "http"
|
||||||
|
@ -58,7 +58,7 @@ class SparkJavaBasedTest extends AgentInstrumentationSpecification {
|
||||||
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
"$SemanticAttributes.HTTP_FLAVOR" "1.1"
|
||||||
"$SemanticAttributes.HTTP_USER_AGENT" String
|
"$SemanticAttributes.HTTP_USER_AGENT" String
|
||||||
"$SemanticAttributes.HTTP_SERVER_NAME" String
|
"$SemanticAttributes.HTTP_SERVER_NAME" String
|
||||||
"$SemanticAttributes.NET_TRANSPORT" IP_TCP
|
"$SemanticAttributes.HTTP_ROUTE" "/param/:param"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue