Skip to content

Commit

Permalink
Fixes #87
Browse files Browse the repository at this point in the history
Implement an extension that brings in Brave as a CDI extension.

Signed-off-by: John D. Ament <john.d.ament@gmail.com>
  • Loading branch information
johnament committed Apr 23, 2017
1 parent dfbded5 commit 0247a0c
Show file tree
Hide file tree
Showing 10 changed files with 398 additions and 6 deletions.
2 changes: 0 additions & 2 deletions jaxrs-rest-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxrs_2.0_spec</artifactId>
<version>1.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ws.ament.hammock</groupId>
Expand Down
23 changes: 19 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<geronimo-jta_1.2_spec.version>1.0-alpha-1</geronimo-jta_1.2_spec.version>
<cdi-api.version>1.2</cdi-api.version>
<cdi2.version>2.0-PFD</cdi2.version>
<cxf.version>3.1.10</cxf.version>
<cxf.version>3.1.11</cxf.version>
<rest-assured.version>3.0.2</rest-assured.version>
<spark.version>2.5.5</spark.version>
<jboss-logging.version>3.3.1.Final</jboss-logging.version>
Expand All @@ -89,6 +89,9 @@
<log4j.version>2.8.2</log4j.version>
<hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
<javax.el.version>3.0.1-b08</javax.el.version>
<zipkin-brave.version>4.2.0</zipkin-brave.version>
<javax.ws.rs-api.version>2.0</javax.ws.rs-api.version>
<geronimo-jaxrs_2.0_spec.version>1.0-alpha-1</geronimo-jaxrs_2.0_spec.version>
</properties>
<modules>
<module>core</module>
Expand All @@ -108,6 +111,10 @@
<module>rest-resteasy</module>
<module>rest-spark</module>
<module>util-metrics</module>
<module>util-flyway</module>
<module>util-camel</module>
<module>util-beanvalidation</module>
<module>util-brave</module>
<module>security-spi</module>
<module>dist-microprofile</module>
<module>dist-microprofile-cochise</module>
Expand All @@ -117,9 +124,6 @@
<module>jpa-eclipselink</module>
<module>messaging-artemis</module>
<module>messaging-rabbitmq</module>
<module>util-flyway</module>
<module>util-camel</module>
<module>util-beanvalidation</module>
</modules>
<dependencyManagement>
<dependencies>
Expand All @@ -128,6 +132,12 @@
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxrs_2.0_spec</artifactId>
<version>${geronimo-jaxrs_2.0_spec.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
Expand Down Expand Up @@ -518,6 +528,11 @@
<artifactId>javax.el</artifactId>
<version>${javax.el.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-jaxrs2</artifactId>
<version>${zipkin-brave.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
109 changes: 109 additions & 0 deletions util-brave/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 Hammock and its contributors
~
~ Licensed 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>container-aware</artifactId>
<groupId>ws.ament.hammock</groupId>
<version>1.3-SNAPSHOT</version>
<relativePath>../container-aware</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>util-brave</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxrs_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-jaxrs2</artifactId>
</dependency>
<dependency>
<groupId>ws.ament.hammock</groupId>
<artifactId>rest-cxf</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ws.ament.hammock</groupId>
<artifactId>test-arquillian</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>undertow-test</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>ws.ament.hammock</groupId>
<artifactId>web-undertow</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>jetty-test</id>
<dependencies>
<dependency>
<groupId>ws.ament.hammock</groupId>
<artifactId>web-jetty</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>tomcat-test</id>
<dependencies>
<dependency>
<groupId>ws.ament.hammock</groupId>
<artifactId>web-tomcat</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017 Hammock and its contributors
*
* Licensed 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 ws.ament.hammock.brave;

import com.github.kristofa.brave.Brave;
import com.github.kristofa.brave.http.SpanNameProvider;
import com.github.kristofa.brave.jaxrs2.BraveTracingFeature;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

@ApplicationScoped
public class BraveTracingFeatureProvider {
@Produces
@Singleton
public BraveTracingFeature createBraveTracingFeature(Brave brave, SpanNameProvider spanNameProvider) {
return BraveTracingFeature.builder(brave).spanNameProvider(spanNameProvider).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2017 Hammock and its contributors
*
* Licensed 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 ws.ament.hammock.brave;

import com.github.kristofa.brave.jaxrs2.BraveTracingFeature;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Provider;

@ApplicationScoped
@Provider
public class SimpleExtension implements Feature {
@Inject
private BraveTracingFeature braveTracingFeature;
@Override
public boolean configure(FeatureContext featureContext) {
return braveTracingFeature.configure(featureContext);
}
}
24 changes: 24 additions & 0 deletions util-brave/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
~ Copyright 2017 Hammock and its contributors
~
~ Licensed 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.
-->

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2017 Hammock and its contributors
*
* Licensed 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 ws.ament.hammock.brave;

import io.restassured.RestAssured;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(Arquillian.class)
public class BraveIntegrationTest {
@Deployment
public static Archive<?> archive() {
return ShrinkWrap.create(JavaArchive.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addClasses(BraveTracingFeatureProvider.class, BraveProducers.class, SpanReporter.class);
}
@Inject
private SpanReporter spanReporter;

@Test
public void shouldCreateSpan() {
RestAssured.get("/simple");
assertThat(spanReporter.getSpans()).hasSize(1);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2017 Hammock and its contributors
*
* Licensed 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 ws.ament.hammock.brave;

import com.github.kristofa.brave.Brave;
import com.github.kristofa.brave.http.HttpRequest;
import com.github.kristofa.brave.http.SpanNameProvider;
import zipkin.Span;
import zipkin.reporter.Reporter;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

@ApplicationScoped
public class BraveProducers {
@Produces
@Singleton
public Brave createBrave(Reporter<Span> reporter) {
return new Brave.Builder().reporter(reporter).build();
}

@Produces
@Singleton
public SpanNameProvider createSpanNameProvider() {
return new SpanNameProvider() {
@Override
public String spanName(HttpRequest httpRequest) {
return "forty-two";
}
};
}
}
Loading

0 comments on commit 0247a0c

Please sign in to comment.