Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Implement TracerFactory (#527)
Browse files Browse the repository at this point in the history
* Implement TracerFactory

Signed-off-by: Juraci Paixão Kröhling <[email protected]>

* Changed return object from JaegerTracerFactory#getTracer

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored Aug 31, 2018
1 parent 8d325b9 commit 8e9492f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext.apacheThriftVersion = getProperty('apacheThriftVersion','0.11.0')
ext.jerseyVersion = getProperty('jerseyVersion','2.22.2')
ext.slf4jVersion = getProperty('slf4jVersion','1.7.25')
ext.gsonVersion = getProperty('gsonVersion','2.8.2')
ext.tracerResolverVersion = getProperty('tracerResolverVersion','0.1.4')
ext.tracerResolverVersion = getProperty('tracerResolverVersion','0.1.5')
ext.micrometerVersion = getProperty('micrometerVersion','1.0.0')
ext.okhttpVersion = getProperty('okhttpVersion','3.9.0')

Expand Down
5 changes: 2 additions & 3 deletions jaeger-tracerresolver/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# 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`.

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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018, The Jaeger Authors
*
* 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 io.jaegertracing.tracerresolver.internal;

import io.jaegertracing.Configuration;
import io.jaegertracing.internal.JaegerTracer;
import io.opentracing.contrib.tracerresolver.TracerFactory;

public class JaegerTracerFactory implements TracerFactory {
@Override
public JaegerTracer getTracer() {
return Configuration.fromEnv().getTracer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@

package io.jaegertracing.tracerresolver.internal;

import io.jaegertracing.Configuration;
import io.jaegertracing.internal.JaegerTracer;
import io.opentracing.contrib.tracerresolver.TracerResolver;

public class JaegerTracerResolver extends TracerResolver {

@Override
protected JaegerTracer resolve() {
return Configuration.fromEnv().getTracer();
return new JaegerTracerFactory().getTracer();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.jaegertracing.tracerresolver.internal.JaegerTracerFactory
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import io.jaegertracing.Configuration;
import io.jaegertracing.internal.JaegerTracer;
import io.opentracing.Tracer;
import io.opentracing.contrib.tracerresolver.TracerFactory;
import io.opentracing.contrib.tracerresolver.TracerResolver;
import java.util.ServiceLoader;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -48,4 +50,23 @@ public void testResolveTracerDefault() {
assertTrue(tracer instanceof JaegerTracer);
}

@Test
public void canFindTracerFactory() {
System.setProperty(Configuration.JAEGER_SERVICE_NAME, "canFindTracerFactory");
Tracer tracer = ServiceLoader.load(TracerFactory.class).iterator().next().getTracer();
assertNotNull(tracer);
assertTrue(tracer instanceof JaegerTracer);
}

@Test
public void canFindTracerResolver() {
System.setProperty(Configuration.JAEGER_SERVICE_NAME, "canFindTracerResolver");
TracerResolver tracerResolver = ServiceLoader.load(TracerResolver.class).iterator().next();
assertNotNull(tracerResolver);
assertTrue(tracerResolver instanceof JaegerTracerResolver);

JaegerTracer tracer = ((JaegerTracerResolver) tracerResolver).resolve();
assertNotNull(tracer);
}

}

0 comments on commit 8e9492f

Please sign in to comment.