Skip to content
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 @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.client;

import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
import static io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.client.PekkoHttpClientSingletons.instrumenter;
import static io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.client.PekkoHttpClientSingletons.setter;
import static net.bytebuddy.matcher.ElementMatchers.named;
Expand Down Expand Up @@ -45,7 +44,7 @@ public static class SingleRequestAdvice {
@ToArgument(value = 0, index = 0, typing = Assigner.Typing.DYNAMIC))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static Object[] methodEnter(@Advice.Argument(value = 0) HttpRequest request) {
Context parentContext = currentContext();
Context parentContext = Context.current();
if (!instrumenter().shouldStart(parentContext, request)) {
return new Object[] {request, null, null};
}
Expand Down Expand Up @@ -90,7 +89,7 @@ public static Future<HttpResponse> methodExit(
responseFuture.onComplete(
new OnCompleteHandler(context, request), thiz.system().dispatcher());

return FutureWrapper.wrap(responseFuture, thiz.system().dispatcher(), currentContext());
return FutureWrapper.wrap(responseFuture, thiz.system().dispatcher(), Context.current());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server;

import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
import static io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.PekkoHttpServerSingletons.instrumenter;

import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -99,7 +98,7 @@ public void onDownstreamFinish(Throwable cause) {
public void onPush() {
HttpRequest request = grab(requestIn);
PekkoTracingRequest tracingRequest = PekkoTracingRequest.EMPTY;
Context parentContext = currentContext();
Context parentContext = Context.current();
if (instrumenter().shouldStart(parentContext, request)) {
Context context = instrumenter().start(parentContext, request);
context = PekkoRouteHolder.init(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route;

import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import org.apache.pekko.http.scaladsl.server.RequestContext;
import org.apache.pekko.http.scaladsl.server.RouteResult;
import scala.Function1;
Expand All @@ -21,7 +20,7 @@ public PekkoRouteWrapper(Function1<RequestContext, Future<RouteResult>> route) {

@Override
public Future<RouteResult> apply(RequestContext ctx) {
Context context = Java8BytecodeBridge.currentContext();
Context context = Context.current();
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(context);
if (routeHolder == null) {
return route.apply(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.tapir;

import io.opentelemetry.context.Context;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server.route.PekkoRouteHolder;
import java.nio.charset.Charset;
import org.apache.pekko.http.scaladsl.model.Uri;
Expand Down Expand Up @@ -47,7 +46,7 @@ public boolean isDefinedAt(Try<RouteResult> tryResult) {

@Override
public Unit apply(Try<RouteResult> tryResult) {
Context context = Java8BytecodeBridge.currentContext();
Context context = Context.current();
PekkoRouteHolder routeHolder = PekkoRouteHolder.get(context);
if (routeHolder != null && tryResult.isSuccess()) {
RouteResult result = tryResult.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import org.apache.pekko.http.scaladsl.server.Route
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.extension.RegisterExtension
import org.junit.jupiter.api.{AfterAll, Test, TestInstance}
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource

import java.net.{URI, URISyntaxException}
import java.util.function.Consumer
Expand Down Expand Up @@ -50,7 +52,6 @@ class PekkoHttpServerRouteTest {
}

@Test def testPathPrefix(): Unit = {
import org.apache.pekko.http.scaladsl.server.Directives._
val route =
pathPrefix("a") {
pathPrefix("b") {
Expand Down Expand Up @@ -88,26 +89,44 @@ class PekkoHttpServerRouteTest {
test(route, "/foo/number-123", "GET /foo/*")
}

@Test def testPipe(): Unit = {
@ParameterizedTest
@CsvSource(
Array(
"/i42, GET /i*",
"/hCAFE, GET /h*"
)
)
def testPipe(requestPath: String, expectedName: String): Unit = {
val route = path("i" ~ IntNumber | "h" ~ HexIntNumber) { _ =>
complete("ok")
}
test(route, "/i42", "GET /i*")
test(route, "/hCAFE", "GET /h*")
test(route, requestPath, expectedName)
}

@Test def testMapExtractor(): Unit = {
@ParameterizedTest
@CsvSource(
Array(
"/colours/red, GET /colours/red",
"/colours/green, GET /colours/green"
)
)
def testMapExtractor(requestPath: String, expectedName: String): Unit = {
val route = path("colours" / Map("red" -> 1, "green" -> 2, "blue" -> 3)) {
_ => complete("ok")
}
test(route, "/colours/red", "GET /colours/red")
test(route, "/colours/green", "GET /colours/green")
test(route, requestPath, expectedName)
}

@Test def testNotMatch(): Unit = {
@ParameterizedTest
@CsvSource(
Array(
"/fooish, GET /foo*",
"/fooish/123, GET /foo*"
)
)
def testNotMatch(requestPath: String, expectedName: String): Unit = {
val route = pathPrefix("foo" ~ not("bar")) { complete("ok") }
test(route, "/fooish", "GET /foo*")
test(route, "/fooish/123", "GET /foo*")
test(route, requestPath, expectedName)
}

@Test def testProvide(): Unit = {
Expand All @@ -121,12 +140,18 @@ class PekkoHttpServerRouteTest {
test(route, "/foo/bar", "GET /foo/bar")
}

@Test def testOptional(): Unit = {
@ParameterizedTest
@CsvSource(
Array(
"/foo/bar/X42/edit, GET /foo/bar/X*/edit",
"/foo/bar/X/edit, GET /foo/bar/X/edit"
)
)
def testOptional(requestPath: String, expectedName: String): Unit = {
val route = path("foo" / "bar" / "X" ~ IntNumber.? / ("edit" | "create")) {
_ => complete("ok")
}
test(route, "/foo/bar/X42/edit", "GET /foo/bar/X*/edit")
test(route, "/foo/bar/X/edit", "GET /foo/bar/X/edit")
test(route, requestPath, expectedName)
}

@Test def testNoMatches(): Unit = {
Expand Down Expand Up @@ -186,14 +211,58 @@ class PekkoHttpServerRouteTest {
test(route, "/test/foo/1", "GET /test/foo/*")
}

@Test def testRouteWithUUID(): Unit = {
val route =
pathPrefix("foo") {
pathPrefix("api") {
pathPrefix("v2") {
pathPrefix("bar") {
path(JavaUUID) { _ =>
complete("ok")
}
}
}
}
}

test(
route,
"/foo/api/v2/bar/5bb7c7d8-0128-4349-86af-fe718f4f8059",
"GET /foo/api/v2/bar/*"
)
}

@Test def testRouteWithSegment(): Unit = {
val route =
pathPrefix("api") {
pathPrefix("v2") {
pathPrefix("orders") {
path(Segment) { _ =>
complete("ok")
}
}
}
}

test(route, "/api/v2/orders/order123", "GET /api/v2/orders/*")
}

@Test def testRouteWithSubSegment(): Unit = {
val route =
pathPrefix("api" / "v2" / "orders" / Segment / "status") { _ =>
complete("ok")
}

test(route, "/api/v2/orders/order123/status", "GET /api/v2/orders/*/status")
}

def test(
route: Route,
path: String,
spanName: String,
expectedStatus: Int = 200,
expectedMsg: String = "ok"
): Unit = {
testing.clearData()
val port = PortUtils.findOpenPort
val address: URI = buildAddress(port)
val binding =
Expand Down
Loading