This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dropwizard instrumentation to opensource
- Loading branch information
Onwukike Ibe
committed
Jul 25, 2016
1 parent
a13a596
commit d6cbf5e
Showing
13 changed files
with
565 additions
and
9 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
jaeger-context/src/main/java/com/uber/jaeger/context/TracingUtils.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
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,55 @@ | ||
apply plugin: 'jacoco' | ||
apply plugin: 'com.github.kt3k.coveralls' | ||
|
||
description = 'Instrumentation library for jaeger-dropwizard' | ||
|
||
dependencies { | ||
compile project(':jaeger-jaxrs2') | ||
|
||
compile group: 'io.dropwizard.metrics', name: 'metrics-core', version: '3.1.0' | ||
compile group: 'io.dropwizard', name: 'dropwizard-hibernate', version: '0.9.1' | ||
|
||
testCompile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: jerseyVersion | ||
testCompile group: 'junit', name: 'junit', version: '4.12' | ||
testCompile group: 'org.mockito', name: 'mockito-all', version: '2.0.2-beta' | ||
} | ||
|
||
jacocoTestReport { | ||
reports { | ||
xml.enabled = true // coveralls plugin depends on xml format report | ||
html.enabled = true | ||
html.destination "${buildDir}/jacocoHtml" | ||
} | ||
|
||
afterEvaluate { | ||
classDirectories = files(classDirectories.files.collect { | ||
fileTree(dir: it, | ||
exclude: [ | ||
'**/*Test*', | ||
]) | ||
}) | ||
} | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java { | ||
srcDir 'src/main/java' | ||
} | ||
} | ||
|
||
test { | ||
java { | ||
srcDir 'src/test/java' | ||
} | ||
} | ||
} | ||
|
||
jar { | ||
from sourceSets.main.output | ||
from sourceSets.test.output | ||
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } | ||
manifest { | ||
attributes('Implementation-jaeger-dropwizard': 'jaeger-dropwizard', 'Implementation-Version': project.version) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
jaeger-dropwizard/src/main/java/com/uber/jaeger/dropwizard/Configuration.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,43 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.uber.jaeger.dropwizard; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Configuration extends com.uber.jaeger.filters.jaxrs2.Configuration { | ||
@JsonCreator | ||
public Configuration(@JsonProperty("serviceName") String serviceName, | ||
@JsonProperty("disable") Boolean disable, | ||
@JsonProperty("sampler") SamplerConfiguration samplerConfig, | ||
@JsonProperty("reporter") ReporterConfiguration reporterConfig) { | ||
super(serviceName, disable, samplerConfig, reporterConfig); | ||
} | ||
|
||
public Configuration setMetricRegistry(MetricRegistry registry) { | ||
super.setStatsFactory(new StatsFactory(registry)); | ||
return this; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
jaeger-dropwizard/src/main/java/com/uber/jaeger/dropwizard/CounterImpl.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,42 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.uber.jaeger.dropwizard; | ||
|
||
import com.codahale.metrics.Meter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.uber.jaeger.metrics.Counter; | ||
|
||
import java.util.Map; | ||
|
||
public class CounterImpl implements Counter { | ||
private final Meter meter; | ||
|
||
CounterImpl(String name, Map<String, String> tags, MetricRegistry registry) { | ||
String metricName = com.uber.jaeger.metrics.Metrics.addTagsToMetricName(name, tags); | ||
meter = registry.meter(metricName); | ||
} | ||
|
||
@Override | ||
public void inc(long delta) { | ||
meter.mark(delta); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
jaeger-dropwizard/src/main/java/com/uber/jaeger/dropwizard/GaugeImpl.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,48 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.uber.jaeger.dropwizard; | ||
|
||
import com.codahale.metrics.Gauge; | ||
import com.codahale.metrics.MetricRegistry; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class GaugeImpl implements com.uber.jaeger.metrics.Gauge { | ||
private final AtomicLong gaugeValue = new AtomicLong(0); | ||
|
||
GaugeImpl(String name, Map<String, String> tags, MetricRegistry registry) { | ||
String metricName = com.uber.jaeger.metrics.Metrics.addTagsToMetricName(name, tags); | ||
registry.register(metricName, new Gauge<Number>() { | ||
|
||
@Override | ||
public Number getValue() { | ||
return gaugeValue.get(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void update(long amount) { | ||
gaugeValue.set(amount); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
jaeger-dropwizard/src/main/java/com/uber/jaeger/dropwizard/JaegerFeature.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,53 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.uber.jaeger.dropwizard; | ||
|
||
import com.uber.jaeger.filters.jaxrs2.TracingUtils; | ||
|
||
import javax.ws.rs.core.Feature; | ||
import javax.ws.rs.core.FeatureContext; | ||
|
||
public class JaegerFeature implements Feature { | ||
private final Configuration jaegerConfig; | ||
|
||
public JaegerFeature(Configuration jaegerConfig) { | ||
this.jaegerConfig = jaegerConfig; | ||
} | ||
|
||
@Override | ||
public boolean configure(FeatureContext featureContext) { | ||
if (featureContext.getConfiguration().isEnabled(this.getClass())) { | ||
return false; | ||
} | ||
|
||
switch (featureContext.getConfiguration().getRuntimeType()) { | ||
case SERVER: | ||
featureContext.register(TracingUtils.serverFilter(jaegerConfig)); | ||
break; | ||
case CLIENT: | ||
featureContext.register(TracingUtils.clientFilter(jaegerConfig)); | ||
break; | ||
} | ||
|
||
return true; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
jaeger-dropwizard/src/main/java/com/uber/jaeger/dropwizard/ReporterConfiguration.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,40 @@ | ||
/* | ||
* Copyright (c) 2016, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.uber.jaeger.dropwizard; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.uber.jaeger.Configuration; | ||
|
||
public class ReporterConfiguration extends Configuration.ReporterConfiguration { | ||
|
||
@JsonCreator | ||
public ReporterConfiguration( | ||
@JsonProperty("logSpans") Boolean logSpans, | ||
@JsonProperty("agentHost") String agentHost, | ||
@JsonProperty("agentPort") Integer agentPort, | ||
@JsonProperty("flushIntervalMs") Integer flushIntervalMs, | ||
@JsonProperty("maxQueueSize") Integer maxQueueSize | ||
) { | ||
super(logSpans, agentHost, agentPort, flushIntervalMs, maxQueueSize); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
jaeger-dropwizard/src/main/java/com/uber/jaeger/dropwizard/SamplerConfiguration.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 (c) 2016, Uber Technologies, Inc | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.uber.jaeger.dropwizard; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.uber.jaeger.Configuration; | ||
|
||
public class SamplerConfiguration extends Configuration.SamplerConfiguration{ | ||
|
||
@JsonCreator | ||
public SamplerConfiguration( | ||
@JsonProperty("type") String type, | ||
@JsonProperty("param") Number param, | ||
@JsonProperty("managerHostPort") String managerHostPort | ||
) { | ||
super(type, param, managerHostPort); | ||
} | ||
} |
Oops, something went wrong.