Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca committed Jan 4, 2025
1 parent 7c88438 commit 6d6a93f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

public class BarService implements Service {
private final String url;
// private final CountDownLatch latch;
private final InstrumentationExtension testing;

public BarService(String url, InstrumentationExtension testing) {
// this.latch = latch;
this.url = url;
this.testing = testing;
}
Expand All @@ -43,7 +41,6 @@ protected void generateSpan(StartEvent event) {
.then(
response -> {
span.end();
// latch.countDown();
});
} catch (URISyntaxException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@
class InstrumentedHttpClientTest {

@RegisterExtension
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

protected static final RatpackClientTelemetry clientTelemetry =
@RegisterExtension
private static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();

private static final RatpackClientTelemetry clientTelemetry =
RatpackClientTelemetry.create(testing.getOpenTelemetry());

protected static final RatpackServerTelemetry serverTelemetry =
private static final RatpackServerTelemetry serverTelemetry =
RatpackServerTelemetry.create(testing.getOpenTelemetry());

@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();

@Test
void testPropagateTraceWithHttpCalls() throws Exception {
EmbeddedApp otherApp =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

public class RatpackApp {

private RatpackApp() {}

public static void main(String... args) throws Exception {
RatpackServer.start(
server ->
Expand All @@ -33,4 +31,6 @@ public static void main(String... args) throws Exception {
.get(ctx.get(URI.class))
.then(response -> ctx.render("hi-bar")))));
}

private RatpackApp() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class RatpackServerApplicationTest {
@RegisterExtension
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

private static RatpackFunctionalTest app;

Expand All @@ -38,9 +38,8 @@ static void setup() throws Exception {
}

@Test
void testAddSpanOnHandlers() throws Exception {
app.test(
httpClient -> assertThat(httpClient.get("foo").getBody().getText()).isEqualTo("hi-foo"));
void testAddSpanOnHandlers() {
assertThat(app.getHttpClient().get("foo").getBody().getText()).isEqualTo("hi-foo");

testing.waitAndAssertTraces(
trace ->
Expand All @@ -62,9 +61,8 @@ void testAddSpanOnHandlers() throws Exception {
}

@Test
void testPropagateTraceToHttpCalls() throws Exception {
app.test(
httpClient -> assertThat(httpClient.get("bar").getBody().getText()).isEqualTo("hi-bar"));
void testPropagateTraceToHttpCalls() {
assertThat(app.getHttpClient().get("bar").getBody().getText()).isEqualTo("hi-bar");

testing.waitAndAssertTraces(
trace ->
Expand Down Expand Up @@ -97,12 +95,9 @@ void testPropagateTraceToHttpCalls() throws Exception {
}

@Test
void testIgnoreHandlersBeforeOpenTelemetryServerHandler() throws Exception {
app.test(
httpClient -> {
assertThat(httpClient.get("ignore").getBody().getText()).isEqualTo("ignored");
assertThat(testing.spans().stream().filter(span -> "GET /ignore".equals(span.getName())))
.isEmpty();
});
void testIgnoreHandlersBeforeOpenTelemetryServerHandler() {
assertThat(app.getHttpClient().get("ignore").getBody().getText()).isEqualTo("ignored");
assertThat(testing.spans().stream().filter(span -> "GET /ignore".equals(span.getName())))
.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@

class RatpackServerTest {
@RegisterExtension
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
private static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();

static Registry registry;
static RatpackServerTelemetry telemetry =
private static final RatpackServerTelemetry telemetry =
RatpackServerTelemetry.builder(testing.getOpenTelemetry()).build();

private static Registry registry;

@BeforeAll
static void setUp() throws Exception {
registry = Registry.of(telemetry::configureRegistry);
Expand All @@ -52,28 +53,25 @@ void testAddSpanOnHandlers() throws Exception {
spec.handlers(chain -> chain.get("foo", ctx -> ctx.render("hi-foo")));
});

app.test(
httpClient -> {
assertThat(httpClient.get("foo").getBody().getText()).isEqualTo("hi-foo");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /foo")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/foo"),
equalTo(URL_PATH, "/foo"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L))));
});
assertThat(app.getHttpClient().get("foo").getBody().getText()).isEqualTo("hi-foo");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /foo")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/foo"),
equalTo(URL_PATH, "/foo"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L))));
}

@Test
Expand All @@ -100,33 +98,30 @@ void testPropagateTraceWithInstrumentedAsyncOperations() throws Exception {
}));
});

app.test(
httpClient -> {
assertThat(httpClient.get("foo").getBody().getText()).isEqualTo("hi-foo");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /foo")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/foo"),
equalTo(URL_PATH, "/foo"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
span.hasName("a-span")
.hasParent(trace.getSpan(0))
.hasAttributes(Attributes.empty())
.hasTotalRecordedEvents(1)));
});
assertThat(app.getHttpClient().get("foo").getBody().getText()).isEqualTo("hi-foo");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /foo")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/foo"),
equalTo(URL_PATH, "/foo"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
span.hasName("a-span")
.hasParent(trace.getSpan(0))
.hasAttributes(Attributes.empty())
.hasTotalRecordedEvents(1)));
}

@Test
Expand Down Expand Up @@ -168,54 +163,51 @@ void testPropagateTraceWithInstrumentedAsyncConcurrentOperations() throws Except
});
});

app.test(
httpClient -> {
assertThat(httpClient.get("foo").getBody().getText()).isEqualTo("hi-foo");
assertThat(httpClient.get("bar").getBody().getText()).isEqualTo("hi-bar");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /foo")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/foo"),
equalTo(URL_PATH, "/foo"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
span.hasName("a-span")
.hasParent(trace.getSpan(0))
.hasAttributes(Attributes.empty())
.hasTotalRecordedEvents(1)),
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /bar")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/bar"),
equalTo(URL_PATH, "/bar"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
span.hasName("another-span")
.hasParent(trace.getSpan(0))
.hasAttributes(Attributes.empty())
.hasTotalRecordedEvents(1)));
});
assertThat(app.getHttpClient().get("foo").getBody().getText()).isEqualTo("hi-foo");
assertThat(app.getHttpClient().get("bar").getBody().getText()).isEqualTo("hi-bar");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /foo")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/foo"),
equalTo(URL_PATH, "/foo"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
span.hasName("a-span")
.hasParent(trace.getSpan(0))
.hasAttributes(Attributes.empty())
.hasTotalRecordedEvents(1)),
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET /bar")
.hasNoParent()
.hasKind(SpanKind.SERVER)
.hasAttributesSatisfyingExactly(
equalTo(HTTP_ROUTE, "/bar"),
equalTo(URL_PATH, "/bar"),
equalTo(URL_SCHEME, "http"),
equalTo(SERVER_PORT, app.getServer().getBindPort()),
equalTo(SERVER_ADDRESS, "localhost"),
equalTo(NETWORK_PROTOCOL_VERSION, "1.1"),
equalTo(URL_QUERY, ""),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
span.hasName("another-span")
.hasParent(trace.getSpan(0))
.hasAttributes(Attributes.empty())
.hasTotalRecordedEvents(1)));
}
}

0 comments on commit 6d6a93f

Please sign in to comment.