Skip to content

Commit

Permalink
Add exporter for Brave and Reporter service (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneider committed Dec 9, 2016
1 parent 49ea3de commit 4d87ae1
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 363 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

.classpath
.project
.settings
target
83 changes: 83 additions & 0 deletions brave-exporter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2016 The OpenZipkin Authors
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.zipkin.brave.karaf</groupId>
<artifactId>brave-karaf-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<artifactId>brave-exporter</artifactId>

<properties>
<main.basedir>${project.basedir}/..</main.basedir>
</properties>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-core</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter</groupId>
<artifactId>zipkin-reporter</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter</groupId>
<artifactId>zipkin-sender-urlconnection</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright 2016 The OpenZipkin Authors
*
* 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 io.zipkin.brave.osgi.exporter;

import java.util.Hashtable;
import java.util.Map;

import com.github.kristofa.brave.Brave;
import com.github.kristofa.brave.Sampler;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import zipkin.Span;
import zipkin.reporter.Reporter;

@Component //
( //
immediate = true, //
name = "io.zipkin.brave" //
)
@Designate(ocd = BraveExporter.Config.class)
public class BraveExporter {
@Reference
Reporter<Span> reporter;

private ServiceRegistration<Brave> reg;

@ObjectClassDefinition(name = "Brave")
@interface Config {
String name() default "default";
boolean traceId128Bit() default false;
float rate() default 1;
}

@Activate
public void activate(Config config, BundleContext context, Map<String, String> properties) {
Brave brave = new Brave.Builder(config.name())
.reporter(reporter) //
.traceId128Bit(config.traceId128Bit()) //
.traceSampler(Sampler.create(config.rate()))
.build();
reg = context.registerService(Brave.class, brave, new Hashtable<String, String>(properties));
}

@Deactivate
public void deactive() {
reg.unregister();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright 2016 The OpenZipkin Authors
*
* 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 io.zipkin.brave.osgi.exporter.urlconnect;

import java.util.Hashtable;
import java.util.Map;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.metatype.annotations.Designate;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import zipkin.Span;
import zipkin.reporter.AsyncReporter;
import zipkin.reporter.Reporter;
import zipkin.reporter.urlconnection.URLConnectionSender;

@Component //
( //
immediate = true, //
name = "io.zipkin.reporter.urlconnect", //
configurationPolicy = ConfigurationPolicy.REQUIRE
)
@Designate(ocd = SenderUrlConnectExporter.Config.class)
public class SenderUrlConnectExporter {

@SuppressWarnings("rawtypes")
private ServiceRegistration<Reporter> reg;
private AsyncReporter<Span> reporter;

@ObjectClassDefinition(name = "Zipkin Reporter URLConnect")
@interface Config {
String endpoint() default "http://localhost:9411/api/v1/spans";
boolean compressionEnabled() default true;
int connectTimeout() default 10 * 1000;
int messageMaxBytes() default 5 * 1024 * 1024;
}

@Activate
public void activate(Config config, BundleContext context, Map<String,String> properties) {
URLConnectionSender sender = URLConnectionSender.builder()
.endpoint(config.endpoint()) //
.compressionEnabled(config.compressionEnabled()) //
.connectTimeout(config.connectTimeout())
.messageMaxBytes(config.messageMaxBytes())
.build();
reporter = AsyncReporter.builder(sender).build();
reg = context.registerService(Reporter.class, reporter, new Hashtable<String, String>(properties));
}

@Deactivate
public void deactive() {
reg.unregister();
reporter.close();
}

}
5 changes: 3 additions & 2 deletions brave-features/src/main/resources/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">

<repository>mvn:org.apache.cxf.karaf/apache-cxf/3.1.8/xml/features</repository>

<feature name="brave-core">
<feature>scr</feature>
<bundle dependency="true">mvn:io.zipkin.java/zipkin/${zipkin.version}</bundle>
<bundle dependency="true">mvn:io.zipkin.reporter/zipkin-reporter/${zipkin.reporter.version}</bundle>
<bundle>mvn:io.zipkin.reporter/zipkin-sender-urlconnection/${zipkin.reporter.version}</bundle>
<bundle>mvn:io.zipkin.brave/brave-core/${brave.version}</bundle>
<bundle>mvn:io.zipkin.brave.karaf/brave-exporter/${project.version}</bundle>
</feature>

<feature name="brave-kafka">
Expand All @@ -35,6 +35,7 @@

<feature name="brave-jaxrs2">
<feature>brave-core</feature>
<bundle dependency="true">mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr339-api-2.0.1/2.6.0</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-inject/1_2</bundle>
<bundle dependency="true">mvn:io.zipkin.brave/brave-http/${brave.version}</bundle>
<bundle>mvn:io.zipkin.brave/brave-jaxrs2/${brave.version}</bundle>
Expand Down
31 changes: 0 additions & 31 deletions brave-itests/.classpath

This file was deleted.

1 change: 0 additions & 1 deletion brave-itests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<dependency>
<groupId>io.zipkin.brave</groupId>
<artifactId>brave-core</artifactId>
<version>${brave.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class BraveTest {
List<Object> spans = new ArrayList<>();
List<Span> spans = new ArrayList<Span>();

@Configuration
public static Option[] configuration() throws Exception {
Expand Down
Loading

0 comments on commit 4d87ae1

Please sign in to comment.