Skip to content

Commit

Permalink
spotless apply
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank11p committed Mar 18, 2024
1 parent 8480f14 commit aa52e86
Show file tree
Hide file tree
Showing 24 changed files with 515 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.opentelemetry.instrumentation.hypertrace.apachehttpasyncclient;

import io.opentelemetry.proto.trace.v1.Span;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -29,8 +30,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;

import io.opentelemetry.proto.trace.v1.Span;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
Expand Down Expand Up @@ -83,7 +82,8 @@ public void getJson()

TEST_WRITER.waitForTraces(1);
// exclude server spans
List<List<Span>> traces = TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER));
List<List<Span>> traces =
TEST_WRITER.waitForSpans(2, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER));
Assertions.assertEquals(1, traces.size());
Assertions.assertEquals(2, traces.get(0).size());
Span clientSpan = traces.get(0).get(1);
Expand All @@ -95,13 +95,14 @@ public void getJson()

Assertions.assertEquals(
"test-value",
TEST_WRITER.getAttributesMap(clientSpan)
.get("http.response.header.test-response-header").getStringValue());
TEST_WRITER
.getAttributesMap(clientSpan)
.get("http.response.header.test-response-header")
.getStringValue());
Assertions.assertEquals(
"bar",
TEST_WRITER.getAttributesMap(clientSpan).get("http.request.header.foo").getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body"));
Assertions.assertNull(TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body"));

Assertions.assertEquals(
GetJsonHandler.RESPONSE_BODY,
Expand Down Expand Up @@ -138,21 +139,23 @@ public void postJsonEntity(HttpEntity entity)

TEST_WRITER.waitForTraces(1);
// exclude server spans
List<List<Span>> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER));
List<List<Span>> traces =
TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER));
Assertions.assertEquals(1, traces.size());
Assertions.assertEquals(1, traces.get(0).size());
Span clientSpan = traces.get(0).get(0);

String requestBody = readInputStream(entity.getContent());
Assertions.assertEquals(
"test-value",
TEST_WRITER.getAttributesMap(clientSpan)
.get("http.response.header.test-response-header").getStringValue());
TEST_WRITER
.getAttributesMap(clientSpan)
.get("http.response.header.test-response-header")
.getStringValue());
Assertions.assertEquals(
requestBody,
TEST_WRITER.getAttributesMap(clientSpan).get("http.request.body").getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(clientSpan).get("http.response.body"));
Assertions.assertNull(TEST_WRITER.getAttributesMap(clientSpan).get("http.response.body"));
}

private static String readInputStream(InputStream inputStream) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.stub.MetadataUtils;
import io.opentelemetry.proto.trace.v1.Span;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;

import io.opentelemetry.proto.trace.v1.Span;
import org.hypertrace.agent.testing.AbstractInstrumenterTest;
import org.hypertrace.example.GreeterGrpc;
import org.hypertrace.example.GreeterGrpc.GreeterBlockingStub;
Expand Down Expand Up @@ -162,14 +161,14 @@ public void serverRequestBlocking() throws TimeoutException, InterruptedExceptio
if (spans.get(0).getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)) {
serverSpan = spans.get(0);
}
Assertions.assertNull(
TEST_WRITER.getAttributesMap(serverSpan).get("rpc.request.body"));
Assertions.assertNull(
TEST_WRITER.getAttributesMap(serverSpan).get("rpc.response.body"));
Assertions.assertNull(TEST_WRITER.getAttributesMap(serverSpan).get("rpc.request.body"));
Assertions.assertNull(TEST_WRITER.getAttributesMap(serverSpan).get("rpc.response.body"));
Assertions.assertEquals(
"true",
TEST_WRITER.getAttributesMap(serverSpan)
.get("rpc.request.metadata.mockblock").getStringValue());
TEST_WRITER
.getAttributesMap(serverSpan)
.get("rpc.request.metadata.mockblock")
.getStringValue());
assertHttp2HeadersForSayHelloMethod(serverSpan);
}

Expand All @@ -180,30 +179,30 @@ private void assertBodiesAndHeaders(Span span, String requestJson, String respon
responseJson, TEST_WRITER.getAttributesMap(span).get("rpc.response.body").getStringValue());
Assertions.assertEquals(
"clientheader",
TEST_WRITER.getAttributesMap(span)
.get("rpc.request.metadata." + CLIENT_STRING_METADATA_KEY.name()).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("rpc.request.metadata." + CLIENT_STRING_METADATA_KEY.name())
.getStringValue());
Assertions.assertEquals(
"serverheader",
TEST_WRITER.getAttributesMap(span)
.get("rpc.response.metadata." + SERVER_STRING_METADATA_KEY.name()).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("rpc.response.metadata." + SERVER_STRING_METADATA_KEY.name())
.getStringValue());
}

private void assertHttp2HeadersForSayHelloMethod(Span span) {
Assertions.assertEquals(
"http",
TEST_WRITER.getAttributesMap(span)
.get("rpc.request.metadata.:scheme").getStringValue());
TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:scheme").getStringValue());
Assertions.assertEquals(
"POST",
TEST_WRITER.getAttributesMap(span)
.get("rpc.request.metadata.:method").getStringValue());
TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:method").getStringValue());
Assertions.assertEquals(
String.format("localhost:%d", SERVER.getPort()),
TEST_WRITER.getAttributesMap(span)
.get("rpc.request.metadata.:authority").getStringValue());
TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:authority").getStringValue());
Assertions.assertEquals(
"/org.hypertrace.example.Greeter/SayHello",
TEST_WRITER.getAttributesMap(span)
.get("rpc.request.metadata.:path").getStringValue());
TEST_WRITER.getAttributesMap(span).get("rpc.request.metadata.:path").getStringValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import static io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_0.server.NettyTestServer.RESPONSE_HEADER_NAME;
import static io.opentelemetry.javaagent.instrumentation.hypertrace.netty.v4_0.server.NettyTestServer.RESPONSE_HEADER_VALUE;

import io.opentelemetry.proto.trace.v1.Span;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import io.opentelemetry.proto.trace.v1.Span;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
Expand Down Expand Up @@ -71,24 +70,27 @@ public void get() throws IOException, TimeoutException, InterruptedException {
}

TEST_WRITER.waitForTraces(1);
List<List<Span>> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
List<List<Span>> traces =
TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
Assertions.assertEquals(1, traces.size());
List<Span> trace = traces.get(0);
Assertions.assertEquals(1, trace.size());
Span span = trace.get(0);

Assertions.assertEquals(
REQUEST_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME)
.getStringValue());
Assertions.assertEquals(
RESPONSE_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span).get("http.request.body"));
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span).get("http.response.body"));
TEST_WRITER
.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME)
.getStringValue());
Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body"));
Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body"));
}

@Test
Expand All @@ -108,20 +110,25 @@ public void postJson() throws IOException, TimeoutException, InterruptedExceptio
}

TEST_WRITER.waitForTraces(1);
List<List<Span>> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
List<List<Span>> traces =
TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
Assertions.assertEquals(1, traces.size());
List<Span> trace = traces.get(0);
Assertions.assertEquals(1, trace.size());
Span span = trace.get(0);

Assertions.assertEquals(
REQUEST_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME)
.getStringValue());
Assertions.assertEquals(
RESPONSE_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME)
.getStringValue());
Buffer requestBodyBuffer = new Buffer();
requestBody.writeTo(requestBodyBuffer);
Assertions.assertEquals(
Expand All @@ -148,21 +155,22 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio
}

TEST_WRITER.waitForTraces(1);
List<List<Span>> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
List<List<Span>> traces =
TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
Assertions.assertEquals(1, traces.size());
List<Span> trace = traces.get(0);
Assertions.assertEquals(1, trace.size());
Span span = trace.get(0);

Assertions.assertEquals(
REQUEST_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME)
.getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME));
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span).get("http.response.body"));
TEST_WRITER.getAttributesMap(span).get("http.response.header." + RESPONSE_HEADER_NAME));
Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.response.body"));

RequestBody requestBody = blockedRequestBody(true, 3000, 75);
Request request2 =
Expand All @@ -178,21 +186,23 @@ public void blocking() throws IOException, TimeoutException, InterruptedExceptio
}

TEST_WRITER.waitForTraces(2);
List<List<Span>> traces2 = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
List<List<Span>> traces2 =
TEST_WRITER.waitForSpans(
2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
Assertions.assertEquals(2, traces2.size());
List<Span> trace2 = traces2.get(1);
Assertions.assertEquals(1, trace2.size());
Span span2 = trace2.get(0);

Assertions.assertEquals(
REQUEST_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span2)
.get("http.request.header." + REQUEST_HEADER_NAME).getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span2)
.get("http.response.header." + RESPONSE_HEADER_NAME));
TEST_WRITER
.getAttributesMap(span2)
.get("http.request.header." + REQUEST_HEADER_NAME)
.getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span2).get("http.response.body"));
TEST_WRITER.getAttributesMap(span2).get("http.response.header." + RESPONSE_HEADER_NAME));
Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.response.body"));
}

@Test
Expand All @@ -212,16 +222,19 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup
}

TEST_WRITER.waitForTraces(1);
List<List<Span>> traces = TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
List<List<Span>> traces =
TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
Assertions.assertEquals(1, traces.size());
List<Span> trace = traces.get(0);
Assertions.assertEquals(1, trace.size());
Span span = trace.get(0);

Assertions.assertEquals(
REQUEST_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME).getStringValue());
TEST_WRITER
.getAttributesMap(span)
.get("http.request.header." + REQUEST_HEADER_NAME)
.getStringValue());
Assertions.assertEquals(
"1st",
TEST_WRITER.getAttributesMap(span).get("http.request.header.first").getStringValue());
Expand All @@ -230,10 +243,11 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup
TEST_WRITER.getAttributesMap(span).get("http.request.header.connection").getStringValue());
Assertions.assertEquals(
RESPONSE_HEADER_VALUE,
TEST_WRITER.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME).getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span).get("http.request.body"));
TEST_WRITER
.getAttributesMap(span)
.get("http.response.header." + RESPONSE_HEADER_NAME)
.getStringValue());
Assertions.assertNull(TEST_WRITER.getAttributesMap(span).get("http.request.body"));
Assertions.assertEquals(
RESPONSE_BODY,
TEST_WRITER.getAttributesMap(span).get("http.response.body").getStringValue());
Expand All @@ -254,30 +268,29 @@ public void connectionKeepAlive() throws IOException, TimeoutException, Interrup
}

TEST_WRITER.waitForTraces(2);
List<List<Span>> traces2 = TEST_WRITER.waitForSpans(2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
List<List<Span>> traces2 =
TEST_WRITER.waitForSpans(
2, span1 -> span1.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT));
Assertions.assertEquals(2, traces2.size());
List<Span> trace2 = traces2.get(1);
Assertions.assertEquals(1, trace2.size());
Span span2 = trace2.get(0);

Assertions.assertEquals(
"REQUEST_HEADER_VALUE",
TEST_WRITER.getAttributesMap(span2)
.get("http.request.header." + REQUEST_HEADER_NAME).getStringValue());
TEST_WRITER
.getAttributesMap(span2)
.get("http.request.header." + REQUEST_HEADER_NAME)
.getStringValue());
Assertions.assertEquals(
"2nd",
TEST_WRITER.getAttributesMap(span2).get("http.request.header.second").getStringValue());
Assertions.assertEquals(
"keep-alive",
TEST_WRITER.getAttributesMap(span2)
.get("http.request.header.connection").getStringValue());
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span2).get("http.request.header.first"));
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span2)
.get("http.response.header." + RESPONSE_HEADER_NAME));
TEST_WRITER.getAttributesMap(span2).get("http.request.header.connection").getStringValue());
Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.request.header.first"));
Assertions.assertNull(
TEST_WRITER.getAttributesMap(span2)
.get("http.response.body"));
TEST_WRITER.getAttributesMap(span2).get("http.response.header." + RESPONSE_HEADER_NAME));
Assertions.assertNull(TEST_WRITER.getAttributesMap(span2).get("http.response.body"));
}
}
Loading

0 comments on commit aa52e86

Please sign in to comment.