Skip to content

Commit

Permalink
Add brave module
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Jul 1, 2019
1 parent f225c07 commit 5a79d60
Show file tree
Hide file tree
Showing 25 changed files with 1,726 additions and 306 deletions.
6 changes: 6 additions & 0 deletions brave/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies {
testCompile project(':thrift')

compile project(':zipkin')
compile 'io.zipkin.brave:brave-instrumentation-http'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2019 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://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 com.linecorp.armeria.client.brave;

import static com.linecorp.armeria.common.brave.RequestContextCurrentTraceContext.ensureScopeUsesRequestContext;

import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.linecorp.armeria.client.Client;
import com.linecorp.armeria.client.tracing.HttpTracingClient;
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.brave.RequestContextCurrentTraceContext;

import brave.Tracing;
import brave.http.HttpTracing;

/**
* Decorates a {@link Client} to trace outbound {@link HttpRequest}s using
* <a href="https://github.com/openzipkin/brave">Brave</a>.
*
* <p>This decorator puts trace data into HTTP headers. The specifications of header names and its values
* correspond to <a href="http://zipkin.io/">Zipkin</a>.
*/
public final class BraveClient extends HttpTracingClient {

private static final Logger logger = LoggerFactory.getLogger(BraveClient.class);

/**
* Creates a new tracing {@link Client} decorator using the specified {@link Tracing} instance.
*/
public static Function<Client<HttpRequest, HttpResponse>, BraveClient> newDecorator(
HttpTracing httpTracing) {
try {
ensureScopeUsesRequestContext(httpTracing.tracing());
} catch (IllegalStateException e) {
logger.warn("{} - it is appropriate to ignore this warning if this client is not being used " +
"inside an Armeria server (e.g., this is a normal spring-mvc tomcat server).",
e.getMessage());
}
return delegate -> new BraveClient(delegate, httpTracing);
}

/**
* Creates a new instance.
*/
private BraveClient(Client<HttpRequest, HttpResponse> delegate, HttpTracing httpTracing) {
super(delegate, httpTracing.tracing(), httpTracing.serverName(),
RequestContextCurrentTraceContext::copy);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2019 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://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.
*/

/**
* Distributed tracing clients based on <a href="https://github.com/openzipkin/brave">Brave</a>,
* a Java tracing library compatible with <a href="http://zipkin.io/">Zipkin</a>.
*/
@NonNullByDefault
package com.linecorp.armeria.client.brave;

import com.linecorp.armeria.common.util.NonNullByDefault;

0 comments on commit 5a79d60

Please sign in to comment.