Skip to content

Commit

Permalink
Add test to verify trace propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalinaspolo committed Dec 29, 2021
1 parent 5a6dd6f commit 9e5f84a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public HttpClient instrument(HttpClient httpClient) throws Exception {
Context otelCtx = instrumenter.start(parentOtelCtx, requestSpec);
Span span = Span.fromContext(otelCtx);
String path = requestSpec.getUri().getPath();
// span.updateName(path);
span.updateName("HTTP " + requestSpec.getMethod().getName());
span.updateName(path);
// span.updateName("HTTP " + requestSpec.getMethod().getName()); // TODO use path instead of [HTTP method]
span.setAttribute(SemanticAttributes.HTTP_ROUTE, path);
Execution.current()
.add(new OpenTelemetryExecInitializer.ContextHolder(otelCtx, requestSpec));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class InstrumentedHttpClientTest extends Specification {
def "propagate trace with http calls"() {
expect:
def otherApp = EmbeddedApp.of { spec ->
spec.registry(
Guice.registry { bindings ->
ratpackTracing.configureServerRegistry(bindings)
}
)
spec.handlers {
it.get("bar") { ctx -> ctx.render("foo") }
}
Expand Down Expand Up @@ -78,9 +83,11 @@ class InstrumentedHttpClientTest extends Specification {

new PollingConditions().eventually {
def spanData = spanExporter.finishedSpanItems.find { it.name == "/foo" }
def spanClientData = spanExporter.finishedSpanItems.find { it.name == "/bar" }
def spanClientData = spanExporter.finishedSpanItems.find { it.name == "/bar" && it.kind == SpanKind.CLIENT }
def spanDataApi = spanExporter.finishedSpanItems.find { it.name == "/bar" && it.kind == SpanKind.SERVER }

spanData.traceId == spanClientData.traceId
spanData.traceId == spanDataApi.traceId

spanData.kind == SpanKind.SERVER
spanClientData.kind == SpanKind.CLIENT
Expand All @@ -94,6 +101,12 @@ class InstrumentedHttpClientTest extends Specification {
attributes[SemanticAttributes.HTTP_TARGET] == "/foo"
attributes[SemanticAttributes.HTTP_METHOD] == "GET"
attributes[SemanticAttributes.HTTP_STATUS_CODE] == 200L

def attsApi = spanDataApi.attributes.asMap()
attsApi[SemanticAttributes.HTTP_ROUTE] == "/bar"
attsApi[SemanticAttributes.HTTP_TARGET] == "/bar"
attsApi[SemanticAttributes.HTTP_METHOD] == "GET"
attsApi[SemanticAttributes.HTTP_STATUS_CODE] == 200L
}
}

Expand Down

0 comments on commit 9e5f84a

Please sign in to comment.