Skip to content

Commit

Permalink
Fix OpenTelemetry REST client operation names
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Mar 23, 2024
1 parent 0622108 commit f61b02f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;

import java.time.Duration;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import org.apache.http.HttpStatus;
Expand Down Expand Up @@ -53,14 +54,19 @@ public class OpentelemetryReactiveIT {
public void testContextPropagation() {
int pageLimit = 10;
String operationName = "GET /ping/pong";
String[] operations = new String[] { "GET /ping/pong", "GET", "GET /hello" };
String[] operations = new String[] { "GET /ping/pong", "GET /hello", "GET /hello" };

await().atMost(1, TimeUnit.MINUTES).pollInterval(Duration.ofSeconds(1)).untilAsserted(() -> {
whenDoPingPongRequest();
thenRetrieveTraces(pageLimit, "1h", OTEL_PING_SERVICE_NAME, operationName);
thenTriggeredOperationsMustBe(containsInAnyOrder(operations));
thenTraceSpanSizeMustBe(is(3)); // 2 endpoint's + rest client call
verifyStandardSourceCodeAttributesArePresent(operationName);
ArrayList<String> spanKinds = resp.body().path(
"data[0].spans.findAll { it.operationName == '%s' }.tags.flatten().findAll { it.key == 'span.kind' }.value.flatten()",
"GET /hello");
Assertions.assertTrue(spanKinds.contains("client"));
Assertions.assertTrue(spanKinds.contains("server"));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.http.HttpStatus;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -58,14 +60,20 @@ public class OpenTelemetryIT {
public void testContextPropagation() {
int pageLimit = 10;
String operationName = "GET /ping/pong";
String[] operations = new String[] { "GET /ping/pong", "GET", "GET /hello" };
String[] operations = new String[] { "GET /ping/pong", "GET /hello", "GET /hello" };

await().atMost(1, TimeUnit.MINUTES).pollInterval(Duration.ofSeconds(1)).untilAsserted(() -> {
whenDoPingPongRequest();
thenRetrieveTraces(pageLimit, "1h", pingservice.getName(), operationName);
thenTriggeredOperationsMustBe(containsInAnyOrder(operations));
thenTraceSpanSizeMustBe(is(3)); // 2 endpoint's + rest client call
verifyStandardSourceCodeAttributesArePresent(operationName);

ArrayList<String> spanKinds = resp.body().path(
"data[0].spans.findAll { it.operationName == '%s' }.tags.flatten().findAll { it.key == 'span.kind' }.value.flatten()",
"GET /hello");
Assertions.assertTrue(spanKinds.contains("client"));
Assertions.assertTrue(spanKinds.contains("server"));
});
}

Expand Down

0 comments on commit f61b02f

Please sign in to comment.