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

Implement TracerFactory #527

Merged
merged 2 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}