-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reactor-netty client test nested under WithSpan
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...reactor-netty/reactor-netty-1.0/javaagent/src/test/groovy/ReactorNettyWithSpanTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.extension.annotations.WithSpan | ||
import io.opentelemetry.instrumentation.api.internal.ContextPropagationDebug | ||
import io.opentelemetry.instrumentation.test.AgentTestTrait | ||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification | ||
import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestServer | ||
import io.opentelemetry.test.reactor.netty.TracedWithSpan | ||
import reactor.core.publisher.Mono | ||
import reactor.netty.http.client.HttpClient | ||
import reactor.test.StepVerifier | ||
import spock.lang.Shared | ||
|
||
import java.time.Duration | ||
import java.util.concurrent.Callable | ||
|
||
import static io.opentelemetry.api.trace.SpanKind.CLIENT | ||
import static io.opentelemetry.api.trace.SpanKind.INTERNAL | ||
import static io.opentelemetry.api.trace.SpanKind.SERVER | ||
|
||
class ReactorNettyWithSpanTest extends InstrumentationSpecification implements AgentTestTrait { | ||
|
||
@Shared | ||
private HttpClientTestServer server | ||
|
||
def setupSpec() { | ||
server = new HttpClientTestServer(openTelemetry) | ||
server.start() | ||
} | ||
|
||
def cleanupSpec() { | ||
server.stop() | ||
} | ||
|
||
def "test successful nested under WithSpan1"() { | ||
when: | ||
def httpClient = HttpClient.create() | ||
|
||
def httpRequest = Mono.defer({ -> | ||
httpClient.get().uri("http://localhost:${server.httpPort()}/success") | ||
.responseSingle ({ resp, content -> | ||
// Make sure to consume content since that's when we close the span. | ||
content.map { resp } | ||
}) | ||
.map({ r -> r.status().code() }) | ||
}) | ||
|
||
def getResponse = new TracedWithSpan().mono( | ||
// our HTTP server is synchronous, i.e. it returns Mono.just with response | ||
// which is not supported by TracingSubscriber - it does not instrument scalar calls | ||
// so we delay here to fake async http request and let Reactor context instrumentation work | ||
Mono.delay(Duration.ofMillis(1)).then(httpRequest)) | ||
|
||
then: | ||
StepVerifier.create(getResponse) | ||
.expectNext(200) | ||
.expectComplete() | ||
.verify() | ||
|
||
assertTraces(1) { | ||
trace(0, 3) { | ||
span(0) { | ||
name "TracedWithSpan.mono" | ||
kind INTERNAL | ||
hasNoParent() | ||
} | ||
span(1) { | ||
name "HTTP GET" | ||
kind CLIENT | ||
childOf(span(0)) | ||
} | ||
span(2) { | ||
name "test-http-server" | ||
kind SERVER | ||
childOf(span(1)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...netty-1.0/javaagent/src/test/java/io/opentelemetry/test/reactor/netty/TracedWithSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.test.reactor.netty; | ||
|
||
import io.opentelemetry.extension.annotations.WithSpan; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class TracedWithSpan { | ||
|
||
@WithSpan | ||
public <T> Mono<T> mono(Mono<T> mono) { | ||
return mono; | ||
} | ||
} |