Skip to content

Commit

Permalink
WIP, merge of palantir#115
Browse files Browse the repository at this point in the history
  • Loading branch information
schlosna committed Oct 11, 2016
1 parent 70d29e8 commit d432f1b
Show file tree
Hide file tree
Showing 46 changed files with 2,568 additions and 340 deletions.
14 changes: 14 additions & 0 deletions brave-tracing/build.gradle
@@ -0,0 +1,14 @@
apply plugin: "org.inferred.processors"
apply from: "${rootDir}/gradle/publish.gradle"

dependencies {
compile project(":tracing-config")
compile "io.zipkin.brave:brave-core"
compile "org.slf4j:slf4j-api"

testCompile "junit:junit"
testCompile "org.hamcrest:hamcrest-all"
testCompile "org.mockito:mockito-core"

processor "org.immutables:value"
}
@@ -0,0 +1,68 @@
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*
* 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 com.palantir.tracing1.brave;

import com.github.kristofa.brave.Brave;
import com.google.common.base.Preconditions;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class BraveTracing {
private static final Logger log = LoggerFactory.getLogger(BraveTracing.class);
private static final ConcurrentMap<String, Brave> REGISTRY = new ConcurrentHashMap<>();
private static final String DEFAULT_CONTEXT = "default";

private BraveTracing() { }

public static Brave setDefault(Brave brave) {
return addContext(DEFAULT_CONTEXT, brave);
}

public static Brave addContext(String contextName, Brave brave) {
Brave previous = REGISTRY.putIfAbsent(contextName, brave);
if (previous != null) {
log.warn("Changing Brave tracer for '{}' context from {} to {}", contextName, previous, brave);
}
return brave;
}

// public static Brave activateContext(String contextName) {
// Brave brave = brave(contextName);
// String previousContext = BRAVE_REF.getAndSet(checkNotNull(contextName, "contextName cannot be null"));
// if (previousContext != null) {
// log.warn("Changing active Brave tracer from context {} to {}", previousContext, contextName);
// }
// return brave;
// }

public static Brave brave(String contextName) {
Brave brave = REGISTRY.get(contextName);
Preconditions.checkState(brave != null, "Brave not initialized for context %s", contextName);
return brave;
}

public static Brave brave() {
return brave(DEFAULT_CONTEXT);
}

public static boolean isInitialized() {
return REGISTRY.get(DEFAULT_CONTEXT) != null;
}

}
5 changes: 5 additions & 0 deletions dropwizard-servers/build.gradle
Expand Up @@ -3,18 +3,23 @@ apply plugin: 'org.inferred.processors'
apply from: "${rootDir}/gradle/publish.gradle"

dependencies {
compile project(":brave-tracing")
compile project(":error-handling")
compile project(":ext:brave-extensions")
compile project(":tracing")
compile project(":tracing-config")

compile "com.fasterxml.jackson.core:jackson-databind"
compile "com.google.code.findbugs:jsr305"
compile "io.dropwizard:dropwizard-core"
compile "io.zipkin.brave:brave-jaxrs2"
compile "io.zipkin.brave:brave-spancollector-http"
compile "io.zipkin.reporter:zipkin-sender-okhttp3"
compile "org.slf4j:slf4j-api"

testCompile project(":ssl-config")

testCompile "com.google.truth:truth"
testCompile "io.dropwizard:dropwizard-testing"
testCompile "junit:junit"
testCompile "org.hamcrest:hamcrest-all"
Expand Down

0 comments on commit d432f1b

Please sign in to comment.