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 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow initialization from env variables and via TracerResolver
- Loading branch information
1 parent
2603cc7
commit 917dff5
Showing
10 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
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
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
109 changes: 109 additions & 0 deletions
109
jaeger-core/src/test/java/com/uber/jaeger/ConfigurationTest.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,109 @@ | ||
/* | ||
* Copyright (c) 2017, 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; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.uber.jaeger.Configuration.ReporterConfiguration; | ||
import com.uber.jaeger.Configuration.SamplerConfiguration; | ||
import com.uber.jaeger.samplers.ConstSampler; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class ConfigurationTest { | ||
|
||
@Before | ||
@After | ||
public void clearProperties() { | ||
// Explicitly clear all properties | ||
System.clearProperty(Configuration.JAEGER_AGENT_HOST); | ||
System.clearProperty(Configuration.JAEGER_AGENT_PORT); | ||
System.clearProperty(Configuration.JAEGER_REPORTER_LOG_SPANS); | ||
System.clearProperty(Configuration.JAEGER_REPORTER_MAX_QUEUE_SIZE); | ||
System.clearProperty(Configuration.JAEGER_REPORTER_FLUSH_INTERVAL); | ||
System.clearProperty(Configuration.JAEGER_SAMPLER_TYPE); | ||
System.clearProperty(Configuration.JAEGER_SAMPLER_PARAM); | ||
System.clearProperty(Configuration.JAEGER_SAMPLER_MANAGER_HOST_PORT); | ||
System.clearProperty(Configuration.JAEGER_SERVICE_NAME); | ||
} | ||
|
||
@Test | ||
public void testFromEnv() { | ||
System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test"); | ||
assertNotNull(Configuration.fromEnv().getTracer()); | ||
} | ||
|
||
@Test | ||
public void testSamplerConst() { | ||
System.setProperty(Configuration.JAEGER_SAMPLER_TYPE, ConstSampler.TYPE); | ||
System.setProperty(Configuration.JAEGER_SAMPLER_PARAM, "1"); | ||
SamplerConfiguration samplerConfig = Configuration.getSamplerConfigurationFromEnv(); | ||
assertEquals(ConstSampler.TYPE, samplerConfig.getType()); | ||
assertEquals(1, samplerConfig.getParam().intValue()); | ||
} | ||
|
||
@Test | ||
public void testSamplerConstInvalidParam() { | ||
System.setProperty(Configuration.JAEGER_SAMPLER_TYPE, ConstSampler.TYPE); | ||
System.setProperty(Configuration.JAEGER_SAMPLER_PARAM, "X"); | ||
SamplerConfiguration samplerConfig = Configuration.getSamplerConfigurationFromEnv(); | ||
assertEquals(ConstSampler.TYPE, samplerConfig.getType()); | ||
assertNull(samplerConfig.getParam()); | ||
} | ||
|
||
@Test | ||
public void testReporterConfiguration() { | ||
System.setProperty(Configuration.JAEGER_REPORTER_LOG_SPANS, "true"); | ||
System.setProperty(Configuration.JAEGER_AGENT_HOST, "MyHost"); | ||
System.setProperty(Configuration.JAEGER_AGENT_PORT, "1234"); | ||
System.setProperty(Configuration.JAEGER_REPORTER_FLUSH_INTERVAL, "500"); | ||
System.setProperty(Configuration.JAEGER_REPORTER_MAX_QUEUE_SIZE, "1000"); | ||
ReporterConfiguration reporterConfig = Configuration.getReporterConfigurationFromEnv(); | ||
assertTrue(reporterConfig.getLogSpans()); | ||
assertEquals("MyHost", reporterConfig.getAgentHost()); | ||
assertEquals(1234, reporterConfig.getAgentPort().intValue()); | ||
assertEquals(500, reporterConfig.getFlushIntervalMs().intValue()); | ||
assertEquals(1000, reporterConfig.getMaxQueueSize().intValue()); | ||
} | ||
|
||
@Test | ||
public void testReporterConfigurationInvalidFlushInterval() { | ||
System.setProperty(Configuration.JAEGER_REPORTER_FLUSH_INTERVAL, "X"); | ||
ReporterConfiguration reporterConfig = Configuration.getReporterConfigurationFromEnv(); | ||
assertNull(reporterConfig.getFlushIntervalMs()); | ||
} | ||
|
||
@Test | ||
public void testReporterConfigurationInvalidLogSpans() { | ||
System.setProperty(Configuration.JAEGER_REPORTER_LOG_SPANS, "X"); | ||
ReporterConfiguration reporterConfig = Configuration.getReporterConfigurationFromEnv(); | ||
assertFalse(reporterConfig.getLogSpans()); | ||
} | ||
|
||
} |
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,23 @@ | ||
# Jaeger Tracer Resolver | ||
|
||
This module provides a Jaeger implementation for the [TracerResolver](https://github.com/opentracing-contrib/java-tracerresolver). This mechanism provides a vendor neutral approach for obtaining a `Tracer` using the JDK | ||
`ServiceLoader`. | ||
|
||
|
||
## Maven Dependency | ||
```xml | ||
<dependency> | ||
<groupId>com.uber.jaeger</groupId> | ||
<artifactId>jaeger-tracerresolver</artifactId> | ||
<version>$jaegerVersion</version> | ||
</dependency> | ||
``` | ||
|
||
## Usage | ||
|
||
```java | ||
Tracer tracer = TracerResolver.resolveTracer(); | ||
``` | ||
|
||
This tracer is configured via environment variables (or system properties). The properties are | ||
described [here](../jaeger-core/README.md). |
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,17 @@ | ||
description = 'TracerResolver implementation for Jaeger Tracer' | ||
|
||
dependencies { | ||
compile project(':jaeger-core') | ||
compile group: 'io.opentracing.contrib', name: 'opentracing-tracerresolver', version: tracerResolverVersion | ||
|
||
testCompile group: 'junit', name: 'junit', version: junitVersion | ||
|
||
signature 'org.codehaus.mojo.signature:java16:1.1@signature' | ||
} | ||
|
||
jar { | ||
from sourceSets.main.output | ||
manifest { | ||
attributes('Implementation-Title': 'jaeger-tracerresolver', 'Implementation-Version': project.version) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
jaeger-tracerresolver/src/main/java/com/uber/jaeger/tracerresolver/JaegerTracerResolver.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,36 @@ | ||
/* | ||
* Copyright (c) 2017, 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.tracerresolver; | ||
|
||
import com.uber.jaeger.Configuration; | ||
|
||
import io.opentracing.contrib.tracerresolver.TracerResolver; | ||
|
||
public class JaegerTracerResolver extends TracerResolver { | ||
|
||
@Override | ||
protected io.opentracing.Tracer resolve() { | ||
return Configuration.fromEnv().getTracer(); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...src/main/resources/META-INF/services/io.opentracing.contrib.tracerresolver.TracerResolver
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 @@ | ||
com.uber.jaeger.tracerresolver.JaegerTracerResolver |
Oops, something went wrong.