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

OTel baggage propagation test #35063

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import io.opentelemetry.api.baggage.Baggage;
import io.opentelemetry.context.Scope;

@Path("")
@Produces(MediaType.APPLICATION_JSON)
public class SimpleResource {
Expand All @@ -22,6 +25,10 @@ public interface SimpleClient {
@Path("/")
@GET
TraceData slashPath();

@Path("/from-baggage")
@GET
TraceData fromBaggagePath();
}

@Inject
Expand All @@ -31,6 +38,9 @@ public interface SimpleClient {
@RestClient
SimpleClient simpleClient;

@Inject
Baggage baggage;

@GET
public TraceData noPath() {
TraceData data = new TraceData();
Expand All @@ -50,6 +60,25 @@ public TraceData slashPathClient() {
return simpleClient.slashPath();
}

@GET
@Path("/slashpath-baggage")
public TraceData slashPathBaggageClient() {
try (Scope scope = baggage.toBuilder()
.put("baggage-key", "baggage-value")
.build()
.makeCurrent()) {
return simpleClient.fromBaggagePath();
}
}

@GET
@Path("/from-baggage")
public TraceData fromBaggageValue() {
TraceData data = new TraceData();
data.message = baggage.getEntryValue("baggage-key");
return data;
}

@GET
@Path("/direct")
public TraceData directTrace() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,43 @@ void testSlashClientPath() {
assertEquals(clientServer.get("parentSpanId"), client.get("spanId"));
}

@Test
void testBaggagePath() {
given()
.contentType("application/json")
.when().get("/slashpath-baggage")
.then()
.statusCode(200)
.body("message", equalTo("baggage-value"));

await().atMost(5, SECONDS).until(() -> getSpans().size() == 3);
List<Map<String, Object>> spans = getSpans();
assertEquals(3, spans.size());
assertEquals(1, spans.stream().map(map -> map.get("traceId")).collect(toSet()).size());

Map<String, Object> server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000");
assertEquals(SERVER.toString(), server.get("kind"));
verifyResource(server);
assertEquals("GET /slashpath-baggage", server.get("name"));
assertEquals(SpanId.getInvalid(), server.get("parent_spanId"));
assertEquals(TraceId.getInvalid(), server.get("parent_traceId"));
assertFalse((Boolean) server.get("parent_valid"));
assertFalse((Boolean) server.get("parent_remote"));

Map<String, Object> client = getSpanByKindAndParentId(spans, CLIENT, server.get("spanId"));
assertEquals(CLIENT.toString(), client.get("kind"));
assertEquals("GET", client.get("name"));
assertEquals("http://localhost:8081/from-baggage", client.get("attr_http.url"));
assertEquals("200", client.get("attr_http.status_code"));
assertEquals(client.get("parentSpanId"), server.get("spanId"));

Map<String, Object> clientServer = getSpanByKindAndParentId(spans, SERVER, client.get("spanId"));
assertEquals(SERVER.toString(), clientServer.get("kind"));
verifyResource(clientServer);
assertEquals("GET /from-baggage", clientServer.get("name"));
assertEquals(clientServer.get("parentSpanId"), client.get("spanId"));
}

@Test
void testChainedResourceTracing() {
given()
Expand Down