-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
10 changed files
with
398 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
util-brave/src/main/java/ws/ament/hammock/brave/BraveTracingFeatureProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
util-brave/src/main/java/ws/ament/hammock/brave/SimpleExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
52 changes: 52 additions & 0 deletions
52
util-brave/src/test/java/ws/ament/hammock/brave/BraveIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
util-brave/src/test/java/ws/ament/hammock/brave/BraveProducers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.