├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── RELEASE.md ├── .gitignore ├── .settings.xml ├── README.md ├── feign-hystrix-opentracing ├── src │ ├── test │ │ └── java │ │ │ └── feign │ │ │ └── opentracing │ │ │ └── hystrix │ │ │ └── HystrixFeignTracingTest.java │ └── main │ │ └── java │ │ └── feign │ │ └── opentracing │ │ └── hystrix │ │ └── TracingConcurrencyStrategy.java └── pom.xml ├── feign-opentracing ├── src │ ├── test │ │ └── java │ │ │ └── feign │ │ │ └── opentracing │ │ │ ├── HttpHeadersInjectAdapterTest.java │ │ │ └── FeignTracingTest.java │ └── main │ │ └── java │ │ └── feign │ │ └── opentracing │ │ ├── HttpHeadersInjectAdapter.java │ │ ├── FeignSpanDecorator.java │ │ └── TracingClient.java └── pom.xml ├── travis └── publish.sh ├── mvnw.cmd ├── .travis.yml ├── pom.xml ├── mvnw └── LICENSE /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenFeign/feign-opentracing/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # OpenFeign Release Process 2 | 3 | This repo uses semantic versions. Please keep this in mind when choosing version numbers. 4 | 5 | For the up-to-date release process, please refer to the 6 | [release process from the OpenFeign](https://github.com/OpenFeign/feign/blob/master/RELEASE.md). 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | target 15 | 16 | # includes 17 | !.mvn/wrapper/maven-wrapper.jar 18 | 19 | # Eclipse 20 | .project 21 | .classpath 22 | .settings 23 | 24 | -------------------------------------------------------------------------------- /.settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | sonatype 8 | ${env.SONATYPE_USERNAME} 9 | ${env.SONATYPE_PASSWORD} 10 | 11 | 12 | bintray 13 | ${env.BINTRAY_USER} 14 | ${env.BINTRAY_KEY} 15 | 16 | 17 | jfrog-snapshots 18 | ${env.BINTRAY_USER} 19 | ${env.BINTRAY_KEY} 20 | 21 | 22 | github.com 23 | ${env.GH_USER} 24 | ${env.GH_TOKEN} 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status][ci-img]][ci] [![Released Version][maven-img]][maven] 2 | 3 | # OpenTracing Feign Instrumentation 4 | OpenTracing instrumentation for Feign client. This instrumentation creates a client span for each outgoing request. 5 | 6 | ## Configuration & Usage 7 | 8 | ### Feign 9 | ```java 10 | Feign feign = Feign.builder() 11 | .client(new TracingClient(feignCompatibleClient, tracer)) 12 | .build(); 13 | 14 | ``` 15 | 16 | ### HystrixFeign 17 | ```java 18 | TracingConcurrencyStrategy.register(); 19 | ``` 20 | and create feign client like it is described above. 21 | 22 | ## Development 23 | ```shell 24 | ./mvnw clean install 25 | ``` 26 | 27 | ## Release 28 | Follow instructions in [RELEASE](RELEASE.md) 29 | 30 | [ci-img]: https://travis-ci.org/OpenFeign/feign-opentracing.svg?branch=master 31 | [ci]: https://travis-ci.org/OpenFeign/feign-opentracing 32 | [maven-img]: https://img.shields.io/maven-central/v/io.github.openfeign.opentracing/feign-opentracing.svg?maxAge=2592000 33 | [maven]: http://search.maven.org/#search%7Cga%7C1%7Cfeign-opentracing 34 | -------------------------------------------------------------------------------- /feign-hystrix-opentracing/src/test/java/feign/opentracing/hystrix/HystrixFeignTracingTest.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing.hystrix; 2 | 3 | import static java.util.concurrent.TimeUnit.SECONDS; 4 | 5 | import java.io.IOException; 6 | 7 | import com.netflix.hystrix.strategy.HystrixPlugins; 8 | 9 | import feign.Client; 10 | import feign.Feign; 11 | import feign.Retryer; 12 | import feign.hystrix.HystrixFeign; 13 | import feign.opentracing.FeignTracingTest; 14 | import feign.opentracing.TracingClient; 15 | 16 | /** 17 | * @author Pavol Loffay 18 | */ 19 | public class HystrixFeignTracingTest extends FeignTracingTest { 20 | 21 | @Override 22 | public void before() throws IOException { 23 | HystrixPlugins.reset(); 24 | TracingConcurrencyStrategy.register(mockTracer); 25 | super.before(); 26 | } 27 | 28 | @Override 29 | protected Feign getClient() { 30 | return feign = HystrixFeign.builder() 31 | .client(new TracingClient(new Client.Default(null, null), mockTracer)) 32 | .retryer(new Retryer.Default(100, SECONDS.toMillis(1), FeignTracingTest.NUMBER_OF_RETRIES)) 33 | .build(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /feign-opentracing/src/test/java/feign/opentracing/HttpHeadersInjectAdapterTest.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.Arrays; 6 | import java.util.Collection; 7 | import java.util.Collections; 8 | import java.util.HashMap; 9 | import java.util.HashSet; 10 | import java.util.Map; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class HttpHeadersInjectAdapterTest { 15 | 16 | @Test 17 | public void putNewTraceHeaderValueInsideList() { 18 | Map> headers = new HashMap<>(); 19 | headers.put("x-header", Arrays.asList("123:123:123:1")); 20 | HttpHeadersInjectAdapter adapter = new HttpHeadersInjectAdapter(headers); 21 | 22 | adapter.put("x-header", "123:456:456:1"); 23 | 24 | assertEquals(headers.get("x-header"), Arrays.asList("123:123:123:1", "123:456:456:1")); 25 | } 26 | 27 | @Test 28 | public void putNewTraceHeaderValueInsideUnmodifiableList() { 29 | Map> headers = new HashMap<>(); 30 | headers.put("x-header", Collections.unmodifiableList(Arrays.asList("123:123:123:1"))); 31 | HttpHeadersInjectAdapter adapter = new HttpHeadersInjectAdapter(headers); 32 | 33 | adapter.put("x-header", "123:456:456:1"); 34 | 35 | assertEquals(headers.get("x-header"), Arrays.asList("123:123:123:1", "123:456:456:1")); 36 | } 37 | 38 | @Test 39 | public void putNewTraceHeaderValueInsideUnmodifiableSet() { 40 | Map> headers = new HashMap<>(); 41 | headers.put("x-header", Collections.unmodifiableSet(new HashSet<>(Arrays.asList("123:123:123:1")))); 42 | HttpHeadersInjectAdapter adapter = new HttpHeadersInjectAdapter(headers); 43 | 44 | adapter.put("x-header", "123:456:456:1"); 45 | 46 | assertEquals(headers.get("x-header"), new HashSet<>(Arrays.asList("123:123:123:1", "123:456:456:1"))); 47 | } 48 | } -------------------------------------------------------------------------------- /feign-opentracing/src/main/java/feign/opentracing/HttpHeadersInjectAdapter.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.HashSet; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | import io.opentracing.propagation.TextMap; 12 | 13 | /** 14 | * Inject adapter for HTTP headers see {@link io.opentracing.Tracer#inject}. 15 | * 16 | * @author Pavol Loffay 17 | */ 18 | class HttpHeadersInjectAdapter implements TextMap { 19 | 20 | private Map> headers; 21 | 22 | public HttpHeadersInjectAdapter(Map> headers) { 23 | if (headers == null) { 24 | throw new NullPointerException("Headers should not be null!"); 25 | } 26 | 27 | this.headers = headers; 28 | } 29 | 30 | @Override 31 | public void put(String key, String value) { 32 | Collection values = headers.get(key); 33 | if (values == null) { 34 | values = new ArrayList<>(1); 35 | headers.put(key, values); 36 | } 37 | 38 | try { 39 | values.add(value); 40 | } catch (UnsupportedOperationException ex) { 41 | if (values instanceof List) { 42 | // Handle unmodifiable Lists 43 | List list = new ArrayList<>(values); 44 | list.add(value); 45 | headers.put(key, list); 46 | } else if (values instanceof Set) { 47 | // Handle unmodifiable Sets 48 | Set set = new HashSet<>(values); 49 | set.add(value); 50 | headers.put(key, set); 51 | } else { 52 | throw ex; 53 | } 54 | } 55 | } 56 | 57 | @Override 58 | public Iterator> iterator() { 59 | throw new UnsupportedOperationException("This class should be used only with tracer#inject()"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /feign-hystrix-opentracing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | io.github.openfeign.opentracing 6 | feign-opentracing-parent 7 | 0.4.5-SNAPSHOT 8 | 9 | 10 | feign-hystrix-opentracing 11 | 12 | 13 | 14 | io.opentracing 15 | opentracing-api 16 | 17 | 18 | ${project.groupId} 19 | feign-opentracing 20 | ${project.version} 21 | 22 | 23 | io.github.openfeign 24 | feign-hystrix 25 | ${version.io.github.openfeign} 26 | provided 27 | 28 | 29 | 30 | junit 31 | junit 32 | test 33 | 34 | 35 | io.opentracing 36 | opentracing-mock 37 | test 38 | 39 | 40 | com.squareup.okhttp3 41 | mockwebserver 42 | ${version.com.squareup.okhttp3-mockwebserver} 43 | test 44 | 45 | 46 | ${project.groupId} 47 | feign-opentracing 48 | ${project.version} 49 | test-jar 50 | test 51 | 52 | 53 | org.awaitility 54 | awaitility 55 | ${version.org.awaitility-awaitility} 56 | test 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /feign-opentracing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | io.github.openfeign.opentracing 6 | feign-opentracing-parent 7 | 0.4.5-SNAPSHOT 8 | 9 | 10 | feign-opentracing 11 | 12 | 13 | 14 | io.opentracing 15 | opentracing-api 16 | 17 | 18 | io.opentracing 19 | opentracing-util 20 | 21 | 22 | 23 | io.github.openfeign 24 | feign-core 25 | ${version.io.github.openfeign} 26 | provided 27 | 28 | 29 | 30 | junit 31 | junit 32 | test 33 | 34 | 35 | io.opentracing 36 | opentracing-mock 37 | test 38 | 39 | 40 | com.squareup.okhttp3 41 | mockwebserver 42 | ${version.com.squareup.okhttp3-mockwebserver} 43 | test 44 | 45 | 46 | io.github.openfeign 47 | feign-okhttp 48 | ${version.io.github.openfeign} 49 | test 50 | 51 | 52 | org.awaitility 53 | awaitility 54 | ${version.org.awaitility-awaitility} 55 | test 56 | 57 | 58 | 59 | 60 | 61 | 62 | maven-jar-plugin 63 | ${version.maven-jar-plugin} 64 | 65 | 66 | 67 | test-jar 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /feign-opentracing/src/main/java/feign/opentracing/FeignSpanDecorator.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing; 2 | 3 | import io.opentracing.Span; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import feign.Request; 8 | import feign.Response; 9 | import io.opentracing.tag.Tags; 10 | 11 | /** 12 | * Decorate span by adding tags/logs or change operation name. 13 | * 14 | *

Do not finish span or throw any exceptions! 15 | * 16 | * @author Pavol Loffay 17 | */ 18 | public interface FeignSpanDecorator { 19 | 20 | /** 21 | * Decorate span before {@link feign.Client#execute(Request, Request.Options)} is called on the delegating client. 22 | * 23 | * @param request request 24 | * @param options request options 25 | * @param span client span 26 | */ 27 | void onRequest(Request request, Request.Options options, Span span); 28 | 29 | /** 30 | * Decorate span after {@link feign.Client#execute(Request, Request.Options)} is called on the delegating client. 31 | * 32 | * @param response response 33 | * @param options request options 34 | * @param span client span 35 | */ 36 | void onResponse(Response response, Request.Options options, Span span); 37 | 38 | /** 39 | * Decorate span if exception is thrown during {@link feign.Client#execute(Request, Request.Options)}. 40 | * 41 | * @param exception exception 42 | * @param request request 43 | * @param span client span 44 | */ 45 | void onError(Exception exception, Request request, Span span); 46 | 47 | 48 | /** 49 | * This decorator adds set of standard tags to the span. 50 | */ 51 | class StandardTags implements FeignSpanDecorator { 52 | 53 | @Override 54 | public void onRequest(Request request, Request.Options options, Span span) { 55 | Tags.COMPONENT.set(span, "feign"); 56 | Tags.HTTP_URL.set(span, request.url()); 57 | Tags.HTTP_METHOD.set(span, request.method()); 58 | } 59 | 60 | @Override 61 | public void onResponse(Response response, Request.Options options, Span span) { 62 | Tags.HTTP_STATUS.set(span, response.status()); 63 | } 64 | 65 | @Override 66 | public void onError(Exception exception, Request request, Span span) { 67 | Tags.ERROR.set(span, Boolean.TRUE); 68 | span.log(errorLogs(exception)); 69 | } 70 | 71 | 72 | public static Map errorLogs(Exception ex) { 73 | Map errorLogs = new HashMap<>(2); 74 | errorLogs.put("event", Tags.ERROR.getKey()); 75 | errorLogs.put("error.object", ex); 76 | 77 | return errorLogs; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /feign-opentracing/src/main/java/feign/opentracing/TracingClient.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing; 2 | 3 | import io.opentracing.Scope; 4 | import io.opentracing.Span; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.logging.Level; 13 | import java.util.logging.Logger; 14 | 15 | import feign.Client; 16 | import feign.Request; 17 | import feign.Response; 18 | import io.opentracing.SpanContext; 19 | import io.opentracing.Tracer; 20 | import io.opentracing.propagation.Format; 21 | import io.opentracing.tag.Tags; 22 | 23 | /** 24 | * OpenTracing Feign integration. This client wraps actual client implementation and creates tracing data for 25 | * outgoing requests. 26 | * 27 | * @author Pavol Loffay 28 | */ 29 | public class TracingClient implements Client { 30 | private static final Logger log = Logger.getLogger(TracingClient.class.getName()); 31 | 32 | private Tracer tracer; 33 | private List spanDecorators; 34 | 35 | private Client delegate; 36 | 37 | /** 38 | * @param delegate delegating client 39 | * @param tracer tracer 40 | */ 41 | public TracingClient(Client delegate, Tracer tracer) { 42 | this(delegate, tracer, Collections.singletonList(new FeignSpanDecorator.StandardTags())); 43 | } 44 | 45 | /** 46 | * @param delegate delegating client 47 | * @param tracer tracer 48 | * @param spanDecorators span decorators 49 | */ 50 | public TracingClient(Client delegate, Tracer tracer, List spanDecorators) { 51 | this.delegate = delegate; 52 | this.tracer = tracer; 53 | this.spanDecorators = new ArrayList<>(spanDecorators); 54 | } 55 | 56 | @Override 57 | public Response execute(Request request, Request.Options options) throws IOException { 58 | Span span = tracer.buildSpan(request.method()) 59 | .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT) 60 | .start(); 61 | 62 | for (FeignSpanDecorator spanDecorator: spanDecorators) { 63 | try { 64 | spanDecorator.onRequest(request, options, span); 65 | } catch (Exception ex) { 66 | log.log(Level.SEVERE, "Exception during decorating span", ex); 67 | } 68 | } 69 | 70 | request = inject(span.context(), request); 71 | 72 | try (Scope scope = tracer.activateSpan(span)) { 73 | Response response = delegate.execute(request, options); 74 | for (FeignSpanDecorator spanDecorator : spanDecorators) { 75 | try { 76 | spanDecorator.onResponse(response, options, span); 77 | } catch (Exception ex) { 78 | log.log(Level.SEVERE, "Exception during decorating span", ex); 79 | } 80 | } 81 | return response; 82 | } catch (Exception ex) { 83 | for (FeignSpanDecorator spanDecorator: spanDecorators) { 84 | try { 85 | spanDecorator.onError(ex, request, span); 86 | } catch (Exception exDecorator) { 87 | log.log(Level.SEVERE, "Exception during decorating span", exDecorator); 88 | } 89 | } 90 | 91 | throw ex; 92 | } finally { 93 | span.finish(); 94 | } 95 | } 96 | 97 | private Request inject(SpanContext spanContext, Request request) { 98 | Map> headersWithTracingContext = new HashMap<>(request.headers()); 99 | tracer.inject(spanContext, Format.Builtin.HTTP_HEADERS, new HttpHeadersInjectAdapter(headersWithTracingContext)); 100 | return Request.create(request.httpMethod(), request.url(), headersWithTracingContext,request.body(), 101 | request.charset(), request.requestTemplate()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /feign-hystrix-opentracing/src/main/java/feign/opentracing/hystrix/TracingConcurrencyStrategy.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing.hystrix; 2 | 3 | import io.opentracing.Scope; 4 | import io.opentracing.ScopeManager; 5 | import io.opentracing.Span; 6 | import java.util.concurrent.Callable; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | import com.netflix.hystrix.strategy.HystrixPlugins; 11 | import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; 12 | import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier; 13 | import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook; 14 | import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher; 15 | import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy; 16 | 17 | import io.opentracing.Tracer; 18 | 19 | /** 20 | * @author Pavol Loffay 21 | */ 22 | public class TracingConcurrencyStrategy extends HystrixConcurrencyStrategy { 23 | private static Logger log = Logger.getLogger(TracingConcurrencyStrategy.class.getName()); 24 | 25 | private HystrixConcurrencyStrategy delegateStrategy; 26 | private Tracer tracer; 27 | 28 | public static TracingConcurrencyStrategy register(Tracer tracer) { 29 | return new TracingConcurrencyStrategy(tracer); 30 | } 31 | 32 | private TracingConcurrencyStrategy(Tracer tracer) { 33 | this.tracer = tracer; 34 | try { 35 | this.delegateStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); 36 | if (this.delegateStrategy instanceof TracingConcurrencyStrategy) { 37 | return; 38 | } 39 | 40 | HystrixCommandExecutionHook commandExecutionHook = 41 | HystrixPlugins.getInstance().getCommandExecutionHook(); 42 | HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); 43 | HystrixMetricsPublisher metricsPublisher = 44 | HystrixPlugins.getInstance().getMetricsPublisher(); 45 | HystrixPropertiesStrategy propertiesStrategy = 46 | HystrixPlugins.getInstance().getPropertiesStrategy(); 47 | 48 | HystrixPlugins.reset(); 49 | HystrixPlugins.getInstance().registerConcurrencyStrategy(this); 50 | HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); 51 | HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); 52 | HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); 53 | HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); 54 | } catch (Exception ex) { 55 | log.log(Level.SEVERE, "Failed to register " + TracingConcurrencyStrategy.class + 56 | ", to HystrixPlugins", ex); 57 | } 58 | } 59 | 60 | @Override 61 | public Callable wrapCallable(Callable callable) { 62 | if (callable instanceof OpenTracingHystrixCallable) { 63 | return callable; 64 | } 65 | 66 | Callable delegateCallable = this.delegateStrategy == null ? callable : 67 | this.delegateStrategy.wrapCallable(callable); 68 | 69 | if (delegateCallable instanceof OpenTracingHystrixCallable) { 70 | return delegateCallable; 71 | } 72 | 73 | if (tracer.scopeManager().activeSpan() == null) { 74 | return delegateCallable; 75 | } 76 | 77 | return new OpenTracingHystrixCallable<>(delegateCallable, tracer.scopeManager(), tracer.activeSpan()); 78 | } 79 | 80 | private static class OpenTracingHystrixCallable implements Callable { 81 | private final Callable delegateCallable; 82 | private ScopeManager scopeManager; 83 | private Span span; 84 | 85 | public OpenTracingHystrixCallable(Callable delegate, ScopeManager scopeManager, Span span) { 86 | if (span == null || delegate == null || scopeManager == null) { 87 | throw new NullPointerException(); 88 | } 89 | this.delegateCallable = delegate; 90 | this.scopeManager = scopeManager; 91 | this.span = span; 92 | } 93 | 94 | @Override 95 | public S call() throws Exception { 96 | try (Scope scope = scopeManager.activate(span)) { 97 | return delegateCallable.call(); 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /travis/publish.sh: -------------------------------------------------------------------------------- 1 | set -euo pipefail 2 | set -x 3 | 4 | build_started_by_tag() { 5 | if [ "${TRAVIS_TAG}" == "" ]; then 6 | echo "[Publishing] This build was not started by a tag, publishing snapshot" 7 | return 1 8 | else 9 | echo "[Publishing] This build was started by the tag ${TRAVIS_TAG}, publishing release" 10 | return 0 11 | fi 12 | } 13 | 14 | is_pull_request() { 15 | if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then 16 | echo "[Not Publishing] This is a Pull Request" 17 | return 0 18 | else 19 | echo "[Publishing] This is not a Pull Request" 20 | return 1 21 | fi 22 | } 23 | 24 | is_travis_branch_master_or_release() { 25 | if [[ "${TRAVIS_BRANCH}" == "master" || "${TRAVIS_BRANCH}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 26 | echo "[Publishing] Travis branch is ${TRAVIS_BRANCH}" 27 | return 0 28 | else 29 | echo "[Not Publishing] Travis branch is not master or v0.0.0" 30 | return 1 31 | fi 32 | } 33 | 34 | check_travis_branch_equals_travis_tag() { 35 | #Weird comparison comparing branch to tag because when you 'git push --tags' 36 | #the branch somehow becomes the tag value 37 | #github issue: https://github.com/travis-ci/travis-ci/issues/1675 38 | if [ "${TRAVIS_BRANCH}" != "${TRAVIS_TAG}" ]; then 39 | echo "Travis branch does not equal Travis tag, which it should, bailing out." 40 | echo " github issue: https://github.com/travis-ci/travis-ci/issues/1675" 41 | exit 1 42 | else 43 | echo "[Publishing] Branch (${TRAVIS_BRANCH}) same as Tag (${TRAVIS_TAG})" 44 | fi 45 | } 46 | 47 | check_release_tag() { 48 | tag="${TRAVIS_TAG}" 49 | if [[ "$tag" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(\-RC[[:digit:]]+)?$ ]]; then 50 | echo "Build started by version tag $tag. During the release process tags like this" 51 | echo "are created by the 'release' Maven plugin. Nothing to do here." 52 | exit 0 53 | elif [[ ! "$tag" =~ ^release-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(\-RC[[:digit:]]+)?$ ]]; then 54 | echo "You must specify a tag of the format 'release-0.0.0' or 'release-0.0.0-RC0' to release this project." 55 | echo "The provided tag ${tag} doesn't match that. Aborting." 56 | exit 1 57 | fi 58 | } 59 | 60 | is_release_commit() { 61 | project_version=$(./mvnw help:evaluate -N -Dexpression=project.version|sed -n '/^[0-9]/p') 62 | if [[ "$project_version" =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(\-RC[[:digit:]]+)?$ ]]; then 63 | echo "Build started by release commit $project_version. Will synchronize to maven central." 64 | return 0 65 | else 66 | return 1 67 | fi 68 | } 69 | 70 | release_version() { 71 | echo "${TRAVIS_TAG}" | sed 's/^release-//' 72 | } 73 | 74 | safe_checkout_remote_branch() { 75 | # We need to be on a branch for release:perform to be able to create commits, 76 | # and we want that branch to be master or v0.0.0 (for RCs). which has been checked before. 77 | # But we also want to make sure that we build and release exactly the tagged version, 78 | # so we verify that the remote branch is where our tag is. 79 | checkoutBranch=master 80 | if [[ "${TRAVIS_BRANCH}" =~ ^release-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+\-RC[[:digit:]]+$ ]]; then 81 | checkoutBranch=v`release_version | sed 's/-RC[[:digit:]]\+//'` 82 | fi 83 | git checkout -B "${checkoutBranch}" 84 | git fetch origin "${checkoutBranch}":origin/"${checkoutBranch}" 85 | commit_local="$(git show --pretty='format:%H' ${checkoutBranch})" 86 | commit_remote="$(git show --pretty='format:%H' origin/${checkoutBranch})" 87 | if [ "$commit_local" != "$commit_remote" ]; then 88 | echo "${checkoutBranch} on remote 'origin' has commits since the version under release, aborting" 89 | exit 1 90 | fi 91 | } 92 | 93 | #---------------------- 94 | # MAIN 95 | #---------------------- 96 | 97 | if ! is_pull_request && build_started_by_tag; then 98 | check_travis_branch_equals_travis_tag 99 | check_release_tag 100 | fi 101 | 102 | ./mvnw install -nsu 103 | 104 | # If we are on a pull request, our only job is to run tests, which happened above via ./mvnw install 105 | if is_pull_request; then 106 | true 107 | # If we are on master, we will deploy the latest snapshot or release version 108 | # - If a release commit fails to deploy for a transient reason, delete the broken version from bintray and click rebuild 109 | elif is_travis_branch_master_or_release; then 110 | ./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -DskipTests deploy 111 | 112 | # If the deployment succeeded, sync it to Maven Central. Note: this needs to be done once per project, not module, hence -N 113 | if is_release_commit; then 114 | ./mvnw --batch-mode -s ./.settings.xml -nsu -N io.zipkin.centralsync-maven-plugin:centralsync-maven-plugin:sync 115 | fi 116 | 117 | # If we are on a release tag, the following will update any version references and push a version tag for deployment. 118 | elif build_started_by_tag; then 119 | safe_checkout_remote_branch 120 | ./mvnw --batch-mode -s ./.settings.xml -Prelease -nsu -DreleaseVersion="$(release_version)" -Darguments="-DskipTests" release:prepare 121 | fi 122 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | # avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %* 125 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 126 | if ERRORLEVEL 1 goto error 127 | goto end 128 | 129 | :error 130 | set ERROR_CODE=1 131 | 132 | :end 133 | @endlocal & set ERROR_CODE=%ERROR_CODE% 134 | 135 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 136 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 137 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 138 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 139 | :skipRcPost 140 | 141 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 142 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 143 | 144 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 145 | 146 | exit /B %ERROR_CODE% 147 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | 4 | language: java 5 | jdk: 6 | - oraclejdk8 7 | 8 | cache: 9 | directories: 10 | - $HOME/.m2/repository 11 | 12 | before_install: 13 | # allocate commits to CI, not the owner of the deploy key 14 | - git config user.name "GH_USER" 15 | - git config user.email "$GH_USER_EMAIL" 16 | # setup https authentication credentials, used by ./mvnw release:prepare 17 | - git config credential.helper "store --file=.git/credentials" 18 | - echo "https://$GH_TOKEN:@github.com" > .git/credentials 19 | 20 | install: 21 | # Override default travis to use the maven wrapper 22 | - ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true -B -V 23 | 24 | script: 25 | - ./travis/publish.sh 26 | 27 | branches: 28 | except: 29 | - /^[0-9]/ 30 | 31 | env: 32 | global: 33 | # Ex. travis encrypt -r org/repo GH_USER=your_github_account 34 | - secure: "BWqYjgklcW9HCxZuJsNUrnJwFq94PCvH6cTS0IF0Rod//ZWAMyfoO62JtUkWmWcvGU8riZVOv5E8U68p2g9J9daSK/9LVp1HzOtYCBO2doPyII5uVziESkJUspUZ63ha+EAEoUPye+UhtSgjE3XNTsDUIVNud3O88p+PGqkRHpsGxAW/ZcEN72n3haxBuggOQyqBJRw2UUvKQYuD2WmA/iE8opacP+ErG5A5AU5NCyLO4+uKmiH0I4tnbpZ8r4lPgQrITlvw+fAfIexJ/dhBlP8pzZzOh/MTl+4llJn1I0cGQFbcHiZxY5hslHzz/msZGNz54b2r2vvZEsp/PYUP4PdHFc62Ql1D9gyXSn4YAegKL4RcsXP7ddurry4mdu9xDSb6WCvUkJ2E0IvsGC85EFEp66wpjaUImFP1IXHSVBZnlovYkoo8dbk3idl50zWSWABdobBWQYCSOpSK6cRlugI2YFwGvU7jnwBSWVj1s3ArKTJgTCP7OvjxARTrtuQyoFXaHhq8A5m1Qni7FoSyQBPdBT7Fg+nWWdIALERL075wpO4fw9Vz4XFe+pbsHotWIVjcmZGXhL9sUMklNgZIN4LBrFihN+cn4XIaNV2+TLkRxTJEYuG2Q2PuLMVMLD40+Mc1q18Rz07QGFoDKkCh0P1Gsf+W+rfkMThFWOVm8Nw=" 35 | # Ex. travis encrypt -r org/repo GH_USER_EMAIL=for_github@domain.com 36 | - secure: "dYvLHsUFg5JKsTfMG8ERYyXxCx7oX2ale0El4UMPSYCkioh/J69O313QneWklFhLZmH6jHQ+Hiv1pZbSAphL6nJ4kvdboQ5oJoqwNhWaf31PH80VcXpLNN6kgGzLN9wO2bV3Vpf53aNcXIDkdBQr3xKKAxyNePZj2djlu7YnAHpjQGAD7u6FmabU8lI0T0B8w77HGxyKuPQfsxAZP4BwKq8Rpm2+tsyaS/OLiKxHHg/PpmRd+u/EyXUXy3ur02AmxsNJwwHzowxFpVzm5QrDK1Qe+hdwXMNgvOyT6sym8j2MXA6Pswa2O5zBJj7DDCdvKuIOyhbmwZrK/uK4dP+O/RZ294axl9DV+eMtKb0/3aRV83N39YjVlFdf+3B7TIQbz2LQvsXfhZoH6CDjXIv2jybB0PYzVy9SlziT2TEVTUpd+yMmsTKfV3bZfaMsY0X+Jk5nmOBcQc1drhO+iP71+22PCLijhuDTyVlG0snFpYQUgVwtpstjrEpG3NpRAIDr69dECQraSG1QwE/NokVTZlJdB1HDrn7PY6Ysm0lvrM06Hq0OHL7Kf26C0L7fMuBOHhyEEtlCKXZq/HPMXuMSznJZSR2sI06mLTWOiff/JLzuPp/ZFLzCZcSYF0v0c2XIScuxGJm45XTFDXwZJ0CM5nL4qxbm/nQwsqFJUyXFUGQ=" 37 | # Ex. travis encrypt -r org/repo GH_TOKEN=XXX-https://github.com/settings/tokens-XXX 38 | - secure: "SXteTtX4r7l/npPs0eyjXecjXlFMzORU1RprW1o5B3/06lYH5kcPYnkJYKRRIs+DXXGFiAYLtnje4+YRmhCOsZxdiDOM0r+N3h3L2C5Zcj0MpDCc+Cz1NeGPyus9KSh0jm8GBncPkUHsD2ncUbU1i1CFEonbHKYhmcl27GVpwNmS4TYVLeC7kWhf2QT4jJZosPK1/hE0YMOsUXLqB6PMbymP+/CR72l/a81KpttiIPBh6e7S6ZH4o4K1IAf8GHDUQRGt5G2ZZhEVYAdHq5g0wu0VIVKxd6bkUVs6pQIMk24GCOHNH1iJBUOTCtlWwUKkA3I/rpnHV/zLv06JXRbSfGLR/eS3tOQ2bJCJryiDjDCpBsUGS18IGJUgh5zRlhujEpssnKK1RODnryIrEcUfTNrquP+38dTBupn1BqBU7QTtENBonftxWokat4TVO6y4voMXdpW1PChEPmHRAlV7dkF20fuLaSXLFSYhbj6x5JWntrKCTf6r3Fjrr4n7t+6nsRHX/zgkoPm/PKTgGQvUoTOgmW/IXo+k+w7Kf2mKcdt51zptldYjIPLB4T5reAYLvgfTYOLwSgwlHnWjhyBCA+y2oAU20+8JLF2m8oEOsZeaOxPrXsLho843eAMPvln9U5klbPWhbGqDQg+739kiSjEjGB446M2rQKWwv7CEK9I=" 39 | # Ex. travis encrypt -r org/repo SONATYPE_USERNAME=your_sonatype_account 40 | - secure: "VPqFchDRZFTMoEjsxvLSHczpqwOdxeixIdh0N/cUwDzNNTLU9Jal+hWhhwRglnhxGdxN+gV7dEmF0f+zLa2BUoB+JsDE2XI+7Lsq5A+Xh3rm4zT+gxg8vhuud+U2rmGIUU/iOxYY4zzTLeo0jtXNErrSeCU/KkqRbXrCeVVgU3Om6EZrr9dVE52jCLJ5PQ3IppudkpmFJao3EadX1O5EvnBXz9bZW0LNic7zcEEJ12QeWLjwGtD91eZqffZMbbzDPpqwSInhnxF25CDv0KU1wHBovxrIkCCparDs3W+X6Xw7ajMhUyfj52UguplZd7A7+UW2CyPQKNmyK7iMnExse/82UHcmMVXWTG5LiIxsajj5VfGeUh2IEWwSnDNM/bHjnX5DW/upoJQKwhoQ4eY6Yv20EyuZYNc3XZSw6mDRij6HhtQ0T5wulO1JRhgHsr+m4Ao9Zv+MqDIxg5g1CM9FblxsyPyh9zTXYaCNTGaBQD6p/vrD/zso3xPgejD5x0aPMu96E6fabkSF5i1cp6S8h3ciKbMWH7pizmly62PWXbwQoQ/nBhGYlnKOceo7HdC1R/pFQqJUJROK2h+DsSvXLClH2e+dnooq4Ur73EFaswuglXJ8hZgEqyZYXnV92fM7M8+8v7JLFFgaKK7TDMGjyv07xWL7ssM7xyPLECuWCTk=" 41 | # Ex. travis encrypt -r org/repo SONATYPE_PASSWORD=your_sonatype_password 42 | - secure: "OJHApw0zCEQMBpkkEZstGYWsX8+ZA8fcYea6PZuByn18OAbUmvJcKPwWnTeKO5y98g6+7PYN9MKtHEwZz3Z3q2AOcJ5OuzHNTCqCVFvIv6+EbHOJ4A5zdjPa/8l6zV7uaKJ80oRBGAO7hjfyqXzzHJuvtj7JGaFWmkaY9cQUzZ0hIqS1mqSjNGmdl5GvDHc38MiVKrDoIwsK8fosGdqdQYXNX0kDGxOVSawM/w9QhMmHWrnOsRnb987sx4hxlBK3K0zmUHn1ApsY8dAfKjQ/fv5tJG1LhtAGZi1ng3Zt30+JMLz9fCzWMpsvmyA2NPdNyInlXOe47pxGNBH4ZM4wdxgAAiXGNtQYLpLo5H/tMd0R9EqPIwcHmR/R74SUmXuvt6gzawnr9gUNcHDBv6OXMx4jNe52G7aQ4hr5+2wb8Yc2MLZ8AeOeWpboymhA1AI3LF+Ji+Es3dEL/zDDhxdHr1r/hg8pTCfAQAXdR6vTUVmwtGorMOHvNpTDbkUmbl0cEPmvo41J3Pp9QmIYJhby2M1AmlqZ8U8QdMFt4UXrT0ldNMZp7tj0qZq0gw7FJQ3zye5z6HntrvePDbwZ9HRkB/jafbvEYIMgU+eQigGt3/TUXKDfKKS0FjOVvv7XqICN4OzdHm1uTAHQb0GKcllFrpQilTEfWxh4cwzKUyJYNrE=" 43 | # Ex. travis encrypt -r org/repo BINTRAY_USER=your_github_account 44 | - secure: "Mi03E9s+eriyRkWRqQHUbYuvJVNfRxxsnqkijLzL7OqEX/Rx++Vc1uzVGlop3278VFZSYh4fNGRBm0o9tZhlcdYG0bqs+s4K5WwRpWe2u41PeycveenhLsyi/WxeCr7xI7cYxrRaqhKbEzDnbdteENpspwc90tv4cwx7BWcnE5kmzRPq7J7MY9gCpDbN1UrJNnoZpP3SRUy8buY8bH2k8+HBllDXwCYNcnUViNDPGJ5dbEareWzXPvhL/w/1UqJK0M5U3NYiD5PccBUo/vC/Ss3ljrUiiuOB6DhF7nw5g8/pBd+yLu5VlSSqy+ge7N016sn0Fh9XUPNTuumb2/Oj1yP9zM0wwqU6Wq0t9uUDpaioUj4NCE+IGWzhjeZ0a5LQWeiAzFcPTeuuCoB8wuCmaXWXK1Z/k1EwUUMloXsVflakPOzB9YeQbz3o9Ab1KiSpStrtcLmTvMEDNlqiqcfHSFO4ZCLv4NAgzy11Q1bybWEty7vz81YOtFiF9K4erZCdM1s9OWbYut1HLsFSiaK660F+3K82UzrDbVjq31PFKZpwokk1eHQaHiH5/vli0WgjrDvWzMMvcoYRUwFHObEWxfO8jN8hfFjWlFx8Rd7P/2pBvg39St6rx+hhwraNedGlC/kEh61FxH1e6K2eZmMLhYLLZKDBBs4Y7+EWnGe1sMw=" 45 | # Ex. travis encrypt -r org/repo BINTRAY_KEY=xxx-https://bintray.com/profile/edit-xxx 46 | - secure: "cpALtu+9sYZugW5k/oQZEmkU65S1wvibKSfSMspm0F8GXQnh9/1RcwrbFm7Wsfq40BGoX2Loat75HelHcVWfju42kuryBRdki7Qkt3594xRPBjLw8pxChrRRLCQ4Ov4S1X8Y0d7fc1nuDAt3/vjHU9iTH/HDJP9IJ16h9CCs1xnKPj9rp0sezkOB+7Xvy0f7pBe868Jmr8ALmiPfw/tprq7RG7TIHlq0UCfHEjMwB6Jko4VkjtF67V5dOVYeAsMYUahRa62AuVsNahatJORdPFo13KtY9V17KbjNYB5JNyUNbWbe8yKb6l0uNdDaVBantTz9MrMqt4BT56E88cK4PusOJaNS0tB6jat6cEZmRWdywlfq5m6618FLBQCpaVNNlrKlH43xWBJVyhqL01v3Z2mjs0t1dLP5DGph90s253gEiLH4G6z7MWVXFh2TsYQJPf68glYa/iq/C9ywTt242iFS2mgfKo1f28ciqQTwCrxsus1WsUD1UI0jqatqEVQWMHTfbl/8qkNxTK6bZfGm7J7M02Ub+dWpYc+Rhpx7iX+5HnJ7kiQUJiR0rOQ3dkKz3tQqaI0pnn6Co/yUL0ewW5hwhZNsk7aGJXoAb2XFsn6P6wG7aJj8Vn2VGqd2VQbFt3juVF8/LQp/fyCTLVE0TMQBGWonWL7T0F5sI85dh70=" 47 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | io.github.openfeign.opentracing 6 | feign-opentracing-parent 7 | 0.4.5-SNAPSHOT 8 | pom 9 | 10 | ${project.groupId}:${project.artifactId} 11 | OpenTracing OpenFeign integration 12 | https://github.com/OpenFeign/feign-opentracing 13 | 14 | 15 | https://github.com/OpenFeign/feign-opentracing 16 | scm:git:https://github.com/OpenFeign/feign-opentracing.git 17 | scm:git:https://github.com/OpenFeign/feign-opentracing.git 18 | HEAD 19 | 20 | 21 | 22 | 23 | The Apache Software License, Version 2.0 24 | http://www.apache.org/licenses/LICENSE-2.0.txt 25 | repo 26 | 27 | 28 | 29 | 30 | 31 | pavolloffay 32 | Pavol Loffay 33 | ploffay@redhat.com 34 | 35 | 36 | 37 | 38 | feign-opentracing 39 | feign-hystrix-opentracing 40 | 41 | 42 | 43 | 1.8 44 | 1.8 45 | UTF-8 46 | 47 | 3.0.0 48 | 3.6.0 49 | 10.12 50 | 0.33.0 51 | 4.13.1 52 | 53 | 54 | 2.8.2 55 | 2.5.3 56 | 3.0.1 57 | 2.10.4 58 | 3.0.2 59 | 0.3.4 60 | 0.1.0 61 | 62 | 63 | 64 | 65 | 66 | io.opentracing 67 | opentracing-api 68 | ${version.io.opentracing} 69 | 70 | 71 | io.opentracing 72 | opentracing-util 73 | ${version.io.opentracing} 74 | 75 | 76 | io.opentracing 77 | opentracing-mock 78 | ${version.io.opentracing} 79 | 80 | 81 | 82 | junit 83 | junit 84 | ${version.junit} 85 | 86 | 87 | 88 | 89 | 90 | 91 | bintray 92 | https://api.bintray.com/maven/openfeign/maven/feign-opentracing/;publish=1 93 | 94 | 95 | jfrog-snapshots 96 | http://oss.jfrog.org/artifactory/oss-snapshot-local 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | io.takari 106 | maven 107 | ${version.io.takari-maven} 108 | 109 | 110 | 111 | 112 | 113 | 114 | maven-release-plugin 115 | ${version.maven-release-plugin} 116 | 117 | false 118 | release 119 | true 120 | @{project.version} 121 | 122 | 123 | 124 | io.zipkin.centralsync-maven-plugin 125 | centralsync-maven-plugin 126 | ${version.io.zikin.centralsync-maven-plugin} 127 | 128 | openfeign 129 | maven 130 | feign-opentracing 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | release 139 | 140 | 141 | 142 | 143 | maven-source-plugin 144 | ${version.maven-source-plugin} 145 | 146 | 147 | attach-sources 148 | 149 | jar 150 | 151 | 152 | 153 | 154 | 155 | 156 | maven-javadoc-plugin 157 | ${version.maven-javadoc-plugin} 158 | 159 | false 160 | 161 | 162 | 163 | attach-javadocs 164 | 165 | jar 166 | 167 | package 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /feign-opentracing/src/test/java/feign/opentracing/FeignTracingTest.java: -------------------------------------------------------------------------------- 1 | package feign.opentracing; 2 | 3 | import static java.util.concurrent.TimeUnit.SECONDS; 4 | 5 | import io.opentracing.Scope; 6 | import io.opentracing.Span; 7 | import io.opentracing.util.ThreadLocalScopeManager; 8 | import java.io.IOException; 9 | import java.util.Collections; 10 | import java.util.List; 11 | import java.util.concurrent.Callable; 12 | 13 | import org.awaitility.Awaitility; 14 | import org.hamcrest.core.IsEqual; 15 | import org.junit.After; 16 | import org.junit.Assert; 17 | import org.junit.Before; 18 | import org.junit.Test; 19 | 20 | import feign.Feign; 21 | import feign.Headers; 22 | import feign.RequestLine; 23 | import feign.Retryer; 24 | import feign.Target; 25 | import feign.okhttp.OkHttpClient; 26 | import io.opentracing.mock.MockSpan; 27 | import io.opentracing.mock.MockTracer; 28 | import io.opentracing.tag.Tags; 29 | import okhttp3.mockwebserver.MockResponse; 30 | import okhttp3.mockwebserver.MockWebServer; 31 | import okhttp3.mockwebserver.RecordedRequest; 32 | 33 | /** 34 | * @author Pavol Loffay 35 | */ 36 | public class FeignTracingTest { 37 | 38 | protected static final int NUMBER_OF_RETRIES = 2; 39 | 40 | protected MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), MockTracer.Propagator.TEXT_MAP); 41 | protected MockWebServer mockWebServer = new MockWebServer(); 42 | protected Feign feign = getClient(); 43 | 44 | protected Feign getClient() { 45 | return Feign.builder() 46 | .client(new TracingClient(new OkHttpClient(), mockTracer, 47 | Collections.singletonList(new FeignSpanDecorator.StandardTags()))) 48 | .retryer(new Retryer.Default(100, SECONDS.toMillis(1), NUMBER_OF_RETRIES)) 49 | .build(); 50 | } 51 | 52 | @Before 53 | public void before() throws IOException { 54 | mockTracer.reset(); 55 | mockWebServer.start(); 56 | } 57 | 58 | @After 59 | public void after() throws IOException { 60 | mockWebServer.close(); 61 | } 62 | 63 | protected interface StringEntityRequest { 64 | @RequestLine("GET") 65 | @Headers("Content-Type: application/json") 66 | String get(); 67 | } 68 | 69 | @Test 70 | public void testStandardTags() { 71 | { 72 | mockWebServer.enqueue(new MockResponse() 73 | .setResponseCode(202)); 74 | 75 | StringEntityRequest 76 | entity = feign.newInstance(new Target.HardCodedTarget(StringEntityRequest.class, 77 | mockWebServer.url("/foo").toString())); 78 | entity.get(); 79 | } 80 | 81 | List mockSpans = mockTracer.finishedSpans(); 82 | Assert.assertEquals(1, mockSpans.size()); 83 | 84 | MockSpan mockSpan = mockSpans.get(0); 85 | Assert.assertEquals(5, mockSpan.tags().size()); 86 | Assert.assertNotNull(mockSpan.tags().get(Tags.COMPONENT.getKey())); 87 | Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey())); 88 | Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey())); 89 | Assert.assertEquals("http://localhost:" + mockWebServer.getPort() + "/foo", 90 | mockSpan.tags().get(Tags.HTTP_URL.getKey())); 91 | Assert.assertEquals(202, mockSpan.tags().get(Tags.HTTP_STATUS.getKey())); 92 | Assert.assertEquals(0, mockSpan.logEntries().size()); 93 | } 94 | 95 | @Test 96 | public void testInject() throws InterruptedException { 97 | { 98 | mockWebServer.enqueue(new MockResponse() 99 | .setResponseCode(200)); 100 | 101 | StringEntityRequest 102 | entity = feign.newInstance(new Target.HardCodedTarget(StringEntityRequest.class, 103 | mockWebServer.url("/foo").toString())); 104 | entity.get(); 105 | } 106 | 107 | List mockSpans = mockTracer.finishedSpans(); 108 | Assert.assertEquals(1, mockSpans.size()); 109 | 110 | RecordedRequest recordedRequest = mockWebServer.takeRequest(); 111 | Assert.assertEquals(mockSpans.get(0).context().spanId(), 112 | Long.parseLong(recordedRequest.getHeader("spanId"))); 113 | Assert.assertEquals(mockSpans.get(0).context().traceId(), 114 | Long.parseLong(recordedRequest.getHeader("traceId"))); 115 | } 116 | 117 | @Test 118 | public void testParentSpanFromSpanManager() throws InterruptedException { 119 | { 120 | Span span = mockTracer.buildSpan("parent") 121 | .start(); 122 | 123 | mockWebServer.enqueue(new MockResponse() 124 | .setResponseCode(200)); 125 | 126 | try (Scope scope = mockTracer.activateSpan(span)) { 127 | StringEntityRequest 128 | entity = feign.newInstance( 129 | new Target.HardCodedTarget(StringEntityRequest.class, 130 | mockWebServer.url("/foo").toString())); 131 | entity.get(); 132 | } finally { 133 | span.finish(); 134 | } 135 | } 136 | Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2)); 137 | 138 | List mockSpans = mockTracer.finishedSpans(); 139 | Assert.assertEquals(2, mockSpans.size()); 140 | Assert.assertEquals(mockSpans.get(1).context().traceId(), mockSpans.get(0).context().traceId()); 141 | Assert.assertEquals(mockSpans.get(1).context().spanId(), mockSpans.get(0).parentId()); 142 | } 143 | 144 | @Test 145 | public void testUnknownHostException() { 146 | { 147 | StringEntityRequest entity = 148 | feign.newInstance(new Target.HardCodedTarget(StringEntityRequest.class, 149 | "http://www.abcfoobar.bar/baz")); 150 | try { 151 | entity.get(); 152 | } catch (Exception ex) { 153 | //ok 154 | } 155 | } 156 | 157 | List mockSpans = mockTracer.finishedSpans(); 158 | // there are two spans due to retry mechanism 159 | Assert.assertEquals(2, mockSpans.size()); 160 | assertErrorSpan(mockSpans.get(0), "http://www.abcfoobar.bar/baz"); 161 | assertErrorSpan(mockSpans.get(1), "http://www.abcfoobar.bar/baz"); 162 | } 163 | 164 | public static void assertErrorSpan(MockSpan mockSpan, String url) { 165 | Assert.assertEquals(5, mockSpan.tags().size()); 166 | Assert.assertNotNull(mockSpan.tags().get(Tags.COMPONENT.getKey())); 167 | Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey())); 168 | Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey())); 169 | Assert.assertEquals(url, mockSpan.tags().get(Tags.HTTP_URL.getKey())); 170 | Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey())); 171 | 172 | Assert.assertEquals(1, mockSpan.logEntries().size()); 173 | Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event")); 174 | Assert.assertNotNull(mockSpan.logEntries().get(0).fields().get("error.object")); 175 | } 176 | 177 | private Callable reportedSpansSize() { 178 | return new Callable() { 179 | @Override 180 | public Integer call() throws Exception { 181 | return mockTracer.finishedSpans().size(); 182 | } 183 | }; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # 58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 | # for the new JDKs provided by Oracle. 60 | # 61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then 62 | # 63 | # Apple JDKs 64 | # 65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 | fi 67 | 68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then 69 | # 70 | # Apple JDKs 71 | # 72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 | fi 74 | 75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then 76 | # 77 | # Oracle JDKs 78 | # 79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 | fi 81 | 82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then 83 | # 84 | # Apple JDKs 85 | # 86 | export JAVA_HOME=`/usr/libexec/java_home` 87 | fi 88 | ;; 89 | esac 90 | 91 | if [ -z "$JAVA_HOME" ] ; then 92 | if [ -r /etc/gentoo-release ] ; then 93 | JAVA_HOME=`java-config --jre-home` 94 | fi 95 | fi 96 | 97 | if [ -z "$M2_HOME" ] ; then 98 | ## resolve links - $0 may be a link to maven's home 99 | PRG="$0" 100 | 101 | # need this for relative symlinks 102 | while [ -h "$PRG" ] ; do 103 | ls=`ls -ld "$PRG"` 104 | link=`expr "$ls" : '.*-> \(.*\)$'` 105 | if expr "$link" : '/.*' > /dev/null; then 106 | PRG="$link" 107 | else 108 | PRG="`dirname "$PRG"`/$link" 109 | fi 110 | done 111 | 112 | saveddir=`pwd` 113 | 114 | M2_HOME=`dirname "$PRG"`/.. 115 | 116 | # make it fully qualified 117 | M2_HOME=`cd "$M2_HOME" && pwd` 118 | 119 | cd "$saveddir" 120 | # echo Using m2 at $M2_HOME 121 | fi 122 | 123 | # For Cygwin, ensure paths are in UNIX format before anything is touched 124 | if $cygwin ; then 125 | [ -n "$M2_HOME" ] && 126 | M2_HOME=`cygpath --unix "$M2_HOME"` 127 | [ -n "$JAVA_HOME" ] && 128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 129 | [ -n "$CLASSPATH" ] && 130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 131 | fi 132 | 133 | # For Migwn, ensure paths are in UNIX format before anything is touched 134 | if $mingw ; then 135 | [ -n "$M2_HOME" ] && 136 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 137 | [ -n "$JAVA_HOME" ] && 138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 139 | # TODO classpath? 140 | fi 141 | 142 | if [ -z "$JAVA_HOME" ]; then 143 | javaExecutable="`which javac`" 144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 145 | # readlink(1) is not available as standard on Solaris 10. 146 | readLink=`which readlink` 147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 148 | if $darwin ; then 149 | javaHome="`dirname \"$javaExecutable\"`" 150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 151 | else 152 | javaExecutable="`readlink -f \"$javaExecutable\"`" 153 | fi 154 | javaHome="`dirname \"$javaExecutable\"`" 155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 156 | JAVA_HOME="$javaHome" 157 | export JAVA_HOME 158 | fi 159 | fi 160 | fi 161 | 162 | if [ -z "$JAVACMD" ] ; then 163 | if [ -n "$JAVA_HOME" ] ; then 164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 165 | # IBM's JDK on AIX uses strange locations for the executables 166 | JAVACMD="$JAVA_HOME/jre/sh/java" 167 | else 168 | JAVACMD="$JAVA_HOME/bin/java" 169 | fi 170 | else 171 | JAVACMD="`which java`" 172 | fi 173 | fi 174 | 175 | if [ ! -x "$JAVACMD" ] ; then 176 | echo "Error: JAVA_HOME is not defined correctly." >&2 177 | echo " We cannot execute $JAVACMD" >&2 178 | exit 1 179 | fi 180 | 181 | if [ -z "$JAVA_HOME" ] ; then 182 | echo "Warning: JAVA_HOME environment variable is not set." 183 | fi 184 | 185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 186 | 187 | # traverses directory structure from process work directory to filesystem root 188 | # first directory with .mvn subdirectory is considered project base directory 189 | find_maven_basedir() { 190 | local basedir=$(pwd) 191 | local wdir=$(pwd) 192 | while [ "$wdir" != '/' ] ; do 193 | if [ -d "$wdir"/.mvn ] ; then 194 | basedir=$wdir 195 | break 196 | fi 197 | wdir=$(cd "$wdir/.."; pwd) 198 | done 199 | echo "${basedir}" 200 | } 201 | 202 | # concatenates all lines of a file 203 | concat_lines() { 204 | if [ -f "$1" ]; then 205 | echo "$(tr -s '\n' ' ' < "$1")" 206 | fi 207 | } 208 | 209 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} 210 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 211 | 212 | # For Cygwin, switch paths to Windows format before running java 213 | if $cygwin; then 214 | [ -n "$M2_HOME" ] && 215 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 216 | [ -n "$JAVA_HOME" ] && 217 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 218 | [ -n "$CLASSPATH" ] && 219 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 220 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 221 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 222 | fi 223 | 224 | # Provide a "standardized" way to retrieve the CLI args that will 225 | # work with both Windows and non-Windows executions. 226 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 227 | export MAVEN_CMD_LINE_ARGS 228 | 229 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 230 | 231 | # avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@ 232 | exec "$JAVACMD" \ 233 | $MAVEN_OPTS \ 234 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 235 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 236 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 237 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------