diff --git a/instrumentation/kamon-armeria/src/test/scala/kamon/instrumentation/armeria/server/ArmeriaHttpServerTracingSpec.scala b/instrumentation/kamon-armeria/src/test/scala/kamon/instrumentation/armeria/server/ArmeriaHttpServerTracingSpec.scala index 6cfb10340..2308cbbdb 100644 --- a/instrumentation/kamon-armeria/src/test/scala/kamon/instrumentation/armeria/server/ArmeriaHttpServerTracingSpec.scala +++ b/instrumentation/kamon-armeria/src/test/scala/kamon/instrumentation/armeria/server/ArmeriaHttpServerTracingSpec.scala @@ -47,32 +47,16 @@ class ArmeriaHttpServerTracingSpec extends WordSpec val webClient = newWebClient(protocol,port) - s"The Armeria $protocol server" should { - - "create a server Span when receiving requests" in { - val target = s"$protocol://$interface:$port/$usersEndpoint" - val expected = "/users" - - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, usersEndpoint)) - webClient.execute(request) - - eventually(timeout(3 seconds)) { - val span = testSpanReporter().nextSpan().value - span.operationName shouldBe expected - span.tags.get(plain("http.url")) shouldBe target - span.metricTags.get(plain("component")) shouldBe "armeria.http.server" - span.metricTags.get(plain("http.method")) shouldBe "GET" - span.metricTags.get(plainLong("http.status_code")) shouldBe 200L - } - } + s"The Armeria $protocol server" when { - "set operation name with unhandled" when { - "request path doesn't exists" in { - val target = s"$protocol://$interface:$port/$pathNotFoundEndpoint" - val expected = "unhandled" + "Non blocking route" should { - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, pathNotFoundEndpoint)) - webClient.execute(request) + "create a server Span when receiving requests" in { + val target = s"$protocol://$interface:$port/$usersEndpoint" + val expected = "/users" + + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, usersEndpoint)) + webClient.execute(request) eventually(timeout(3 seconds)) { val span = testSpanReporter().nextSpan().value @@ -80,81 +64,80 @@ class ArmeriaHttpServerTracingSpec extends WordSpec span.tags.get(plain("http.url")) shouldBe target span.metricTags.get(plain("component")) shouldBe "armeria.http.server" span.metricTags.get(plain("http.method")) shouldBe "GET" - span.metricTags.get(plainBoolean("error")) shouldBe false - span.metricTags.get(plainLong("http.status_code")) shouldBe 404 + span.metricTags.get(plainLong("http.status_code")) shouldBe 200L } } - } - "set operation name with path + http method" when { - "resource doesn't exist" in { - val target = s"$protocol://$interface:$port/$usersEndpoint/not-found" - val expected = "/users/{}" + "set operation name with unhandled" when { + "request path doesn't exists" in { + val target = s"$protocol://$interface:$port/$pathNotFoundEndpoint" + val expected = "unhandled" + + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, pathNotFoundEndpoint)) + webClient.execute(request) + + eventually(timeout(3 seconds)) { + val span = testSpanReporter().nextSpan().value + span.operationName shouldBe expected + span.tags.get(plain("http.url")) shouldBe target + span.metricTags.get(plain("component")) shouldBe "armeria.http.server" + span.metricTags.get(plain("http.method")) shouldBe "GET" + span.metricTags.get(plainBoolean("error")) shouldBe false + span.metricTags.get(plainLong("http.status_code")) shouldBe 404 + } + } + } - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/not-found")) - webClient.execute(request) + "set operation name with path + http method" when { + "resource doesn't exist" in { + val target = s"$protocol://$interface:$port/$usersEndpoint/not-found" + val expected = "/users/{}" + + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/not-found")) + webClient.execute(request) + + eventually(timeout(3 seconds)) { + val span = testSpanReporter().nextSpan().value + span.operationName shouldBe expected + span.tags.get(plain("http.url")) shouldBe target + span.metricTags.get(plain("component")) shouldBe "armeria.http.server" + span.metricTags.get(plain("http.method")) shouldBe "GET" + span.metricTags.get(plainBoolean("error")) shouldBe false + span.metricTags.get(plainLong("http.status_code")) shouldBe 404 + } + } + } + + "not include path variables names" in { + val expected = "/users/{}/accounts/{}" + + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, userAccountEndpoint)) + webClient.execute(request) eventually(timeout(3 seconds)) { val span = testSpanReporter().nextSpan().value span.operationName shouldBe expected - span.tags.get(plain("http.url")) shouldBe target - span.metricTags.get(plain("component")) shouldBe "armeria.http.server" - span.metricTags.get(plain("http.method")) shouldBe "GET" - span.metricTags.get(plainBoolean("error")) shouldBe false - span.metricTags.get(plainLong("http.status_code")) shouldBe 404 } } - } - - "not include path variables names" in { - val expected = "/users/{}/accounts/{}" - - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, userAccountEndpoint)) - webClient.execute(request) - eventually(timeout(3 seconds)) { - val span = testSpanReporter().nextSpan().value - span.operationName shouldBe expected - } - } + "not fail when request url contains special regexp chars" in { + val expected = "/users/{}/accounts/{}" - "not fail when request url contains special regexp chars" in { - val expected = "/users/{}/accounts/{}" + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$userAccountEndpoint**")) + val response = webClient.execute(request).aggregate().get() - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$userAccountEndpoint**")) - val response = webClient.execute(request).aggregate().get() - - eventually(timeout(3 seconds)) { - val span = testSpanReporter().nextSpan().value - span.operationName shouldBe expected - response.status().code() shouldBe 200 - } - } - - "mark spans as failed when request fails" in { - val target = s"$protocol://$interface:$port/$usersEndpoint/error" - val expected = "/users/{}" - - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/error")) - webClient.execute(request) - - eventually(timeout(3 seconds)) { - val span = testSpanReporter().nextSpan().value - span.operationName shouldBe expected - span.tags.get(plain("http.url")) shouldBe target - span.metricTags.get(plain("component")) shouldBe "armeria.http.server" - span.metricTags.get(plain("http.method")) shouldBe "GET" - span.metricTags.get(plainBoolean("error")) shouldBe true - span.metricTags.get(plainLong("http.status_code")) shouldBe 500 + eventually(timeout(3 seconds)) { + val span = testSpanReporter().nextSpan().value + span.operationName shouldBe expected + response.status().code() shouldBe 200 + } } - } - "return a redirect status code" when { - "a request to /docs is redirected to /docs/" in { - val target = s"$protocol://$interface:$port/$docsEndpoint" - val expected = s"/docs" + "mark spans as failed when request fails" in { + val target = s"$protocol://$interface:$port/$usersEndpoint/error" + val expected = "/users/{}" - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, docsEndpoint)) + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$usersEndpoint/error")) webClient.execute(request) eventually(timeout(3 seconds)) { @@ -163,17 +146,57 @@ class ArmeriaHttpServerTracingSpec extends WordSpec span.tags.get(plain("http.url")) shouldBe target span.metricTags.get(plain("component")) shouldBe "armeria.http.server" span.metricTags.get(plain("http.method")) shouldBe "GET" - span.metricTags.get(plainLong("http.status_code")) shouldBe 307L + span.metricTags.get(plainBoolean("error")) shouldBe true + span.metricTags.get(plainLong("http.status_code")) shouldBe 500 + } + } + + "return a redirect status code" when { + "a request to /docs is redirected to /docs/" in { + val target = s"$protocol://$interface:$port/$docsEndpoint" + val expected = s"/docs" + + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, docsEndpoint)) + webClient.execute(request) + + eventually(timeout(3 seconds)) { + val span = testSpanReporter().nextSpan().value + span.operationName shouldBe expected + span.tags.get(plain("http.url")) shouldBe target + span.metricTags.get(plain("component")) shouldBe "armeria.http.server" + span.metricTags.get(plain("http.method")) shouldBe "GET" + span.metricTags.get(plainLong("http.status_code")) shouldBe 307L + } + } + } + + "return a ok status code " when { + "a request to /docs/ is done" in { + val target = s"$protocol://$interface:$port/$docsEndpoint/" + val expected = s"/docs" + + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$docsEndpoint/")) + webClient.execute(request) + + eventually(timeout(3 seconds)) { + val span = testSpanReporter().nextSpan().value + span.operationName shouldBe expected + span.tags.get(plain("http.url")) shouldBe target + span.metricTags.get(plain("component")) shouldBe "armeria.http.server" + span.metricTags.get(plain("http.method")) shouldBe "GET" + span.metricTags.get(plainLong("http.status_code")) shouldBe 200L + } } } } - "return a ok status code " when { - "a request to /docs/ is done" in { - val target = s"$protocol://$interface:$port/$docsEndpoint/" - val expected = s"/docs" + "Blocking route" should { + + "create a server Span when receiving requests" in { + val target = s"$protocol://$interface:$port/$usersBlockingEndpoint" + val expected = "/users-blocking" - val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, s"$docsEndpoint/")) + val request = HttpRequest.of(RequestHeaders.of(HttpMethod.GET, usersBlockingEndpoint)) webClient.execute(request) eventually(timeout(3 seconds)) {