Skip to content

Commit

Permalink
Add a smoke test case to check whether the http.route attribute is …
Browse files Browse the repository at this point in the history
…in a server span with Play framework

Signed-off-by: moznion <[email protected]>
  • Loading branch information
moznion committed Feb 13, 2023
1 parent dbc69e4 commit 5151da5
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
package io.opentelemetry.smoketest

import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest
import io.opentelemetry.proto.common.v1.AnyValue
import io.opentelemetry.proto.common.v1.KeyValue
import io.opentelemetry.proto.trace.v1.Span
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import spock.lang.IgnoreIf

import java.time.Duration
import java.util.stream.Collectors

import static io.opentelemetry.smoketest.TestContainerManager.useWindowsContainers

Expand Down Expand Up @@ -36,6 +41,9 @@ class PlaySmokeTest extends SmokeTest {
//Both play and akka-http support produce spans with the same name.
//One internal, one SERVER
countSpansByName(traces, '/welcome') == 2
def httpRouteAttributes = extractRouteAttributesFrom(traces)
httpRouteAttributes.size() == 1
httpRouteAttributes.get(0).value.stringValue == "/welcome"

cleanup:
stopTarget()
Expand All @@ -45,4 +53,15 @@ class PlaySmokeTest extends SmokeTest {
// https://github.com/playframework/playframework/pull/10819
jdk << [8, 11, 15]
}

static List<KeyValue> extractRouteAttributesFrom(Collection<ExportTraceServiceRequest> traces) {
traces.stream()
.flatMap(trace -> trace.getResourceSpansList().stream())
.flatMap(resourceSpan -> resourceSpan.getScopeSpansList().stream())
.flatMap(scopeSpan -> scopeSpan.getSpansList().stream())
.filter(span -> span.getKind() == Span.SpanKind.SPAN_KIND_SERVER)
.flatMap(span -> span.attributesList.stream())
.filter(attribute -> attribute.getKey() == SemanticAttributes.HTTP_ROUTE.key)
.collect(Collectors.toList())
}
}

0 comments on commit 5151da5

Please sign in to comment.