Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: bump opentelemetryJavaagent from 1.32.0 to 2.0.0 #96

Merged
merged 10 commits into from
Feb 12, 2024
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ opentelemetrySdk = "1.34.1"
opentelemetryProto = "1.1.0-alpha"

# otel agent, those two should be updated together
opentelemetryJavaagent = "1.32.0"
opentelemetryJavaagentAlpha = "1.32.0-alpha"
opentelemetryJavaagent = "2.0.0"
opentelemetryJavaagentAlpha = "2.0.0-alpha"

# otel semconv java generated bindings, needs to be kept in sync with version in otel agent
opentelemetrySemconv = "1.21.0-alpha"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ public void healthcheck() throws InterruptedException {
List<ExportTraceServiceRequest> traces = waitForTraces();
List<Span> spans = getSpans(traces).toList();
assertThat(spans)
.hasSize(2)
.hasSize(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant change from the otel 2.0.0 changelog:

Controller spans are now disabled by default. You can enable them using OTEL_INSTRUMENTATION_COMMON_EXPERIMENTAL_CONTROLLER_TELEMETRY_ENABLED=true or -Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I should probably have read the release notes in more detail !

Here I'll leave it in the most simple form as we just need to assert that we have at least one span, and there is no need to verify that the controller span is created.

.extracting("name", "kind")
.containsOnly(
tuple("GET /health", Span.SpanKind.SPAN_KIND_SERVER),
tuple("HealthController.healthcheck", Span.SpanKind.SPAN_KIND_INTERNAL));
.containsOnly(tuple("GET /health", Span.SpanKind.SPAN_KIND_SERVER));

spans.forEach(
span -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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.resource.v1.Resource;
import io.opentelemetry.proto.trace.v1.ResourceSpans;
import io.opentelemetry.proto.trace.v1.Span;
import java.io.IOException;
Expand Down Expand Up @@ -118,6 +119,8 @@ protected static GenericContainer<?> startTarget(
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
// batch span processor: very short delay for testing
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
// use grpc endpoint as default is now http/protobuf with agent 2.x
.withEnv("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc")
SylvainJuge marked this conversation as resolved.
Show resolved Hide resolved
.withEnv("OTEL_PROPAGATORS", "tracecontext,baggage")
.withEnv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://backend:8080");

Expand Down Expand Up @@ -233,10 +236,19 @@ protected static String getUrl(GenericContainer<?> target, String path, int port

protected static void checkTracesResources(
ResourceAttributesCheck check, List<ExportTraceServiceRequest> traces) {
traces.stream()
.flatMap(t -> t.getResourceSpansList().stream())
.map(ResourceSpans::getResource)
.forEach(resource -> check.verify(assertThat(getAttributes(resource.getAttributesList()))));

assertThat(traces).describedAs("at least one exported trace expected").isNotEmpty();

List<Resource> resources =
traces.stream()
.flatMap(t -> t.getResourceSpansList().stream())
.map(ResourceSpans::getResource)
.collect(Collectors.toList());

assertThat(resources).describedAs("traces resources must not be empty").isNotEmpty();

resources.forEach(
resource -> check.verify(assertThat(getAttributes(resource.getAttributesList()))));
}

protected interface ResourceAttributesCheck {
Expand Down Expand Up @@ -308,13 +320,13 @@ private String waitForContent() {
long previousSize = 0;
long deadline = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(30);
String content = "[]";
while (System.currentTimeMillis() < deadline) {

Request request =
new Request.Builder()
.url(String.format("http://localhost:%d/get-traces", backend.getMappedPort(8080)))
.build();
Request request =
new Request.Builder()
.url(String.format("http://localhost:%d/get-traces", backend.getMappedPort(8080)))
.build();

while (System.currentTimeMillis() < deadline) {
try (ResponseBody body = client.newCall(request).execute().body()) {
content = body.string();
} catch (IOException e) {
Expand Down
Loading