Skip to content

Commit

Permalink
Add test coverage for OpenTelemetry WithSpan annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Jan 7, 2022
1 parent 2de0558 commit eb7c20c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions integration-tests/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<description>Integration tests for Camel Quarkus OpenTelemetry extension</description>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bean</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
Expand Down Expand Up @@ -110,6 +114,19 @@
</activation>
<dependencies>
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bean-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.opentelemetry.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

import io.opentelemetry.extension.annotations.WithSpan;

@ApplicationScoped
@Named("greetingsBean")
public class GreetingsBean {

@WithSpan
public String greet(String name) {
return "Hello " + name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

Expand All @@ -38,4 +39,11 @@ public class OpenTelemetryResource {
public String traceRoute() {
return producerTemplate.requestBody("direct:start", null, String.class);
}

@Path("/greet/{name}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String traceRoute(@PathParam("name") String name) {
return producerTemplate.requestBody("direct:greet", name, String.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public void configure() throws Exception {
from("direct:start")
.setBody().constant("Traced direct:start");

from("direct:greet")
.bean("greetingsBean");

from("timer:filtered?repeatCount=5&delay=-1")
.setBody().constant("Route filtered from tracing");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ public void testTracedCamelRouteInvokedFromJaxRsService() {
assertEquals(spans.get(0).get("parentId"), spans.get(1).get("spanId"));
}

@Test
public void testTracedBean() {
String name = "Camel Quarkus OpenTelemetry";
RestAssured.get("/opentelemetry/greet/" + name)
.then()
.statusCode(200)
.body(equalTo("Hello " + name));

// Verify the span hierarchy is JAX-RS Service -> Direct Endpoint -> Bean Method
List<Map<String, String>> spans = getSpans();
assertEquals(3, spans.size());
assertEquals(spans.get(0).get("parentId"), spans.get(1).get("parentId"));
assertEquals(spans.get(1).get("parentId"), spans.get(2).get("spanId"));
}

private List<Map<String, String>> getSpans() {
return RestAssured.given()
.get("/opentelemetry/exporter/spans")
Expand Down

0 comments on commit eb7c20c

Please sign in to comment.