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

Commit

Permalink
Move internal classes to their own package
Browse files Browse the repository at this point in the history
Resolves jaegertracing#396

Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling committed May 28, 2018
1 parent 3ffaf9d commit 2595cf1
Show file tree
Hide file tree
Showing 130 changed files with 789 additions and 674 deletions.
10 changes: 5 additions & 5 deletions jaeger-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ This module provides core tracing functionality for custom instrumentation.

### Production

Tracer can be created via `io.jaegertracing.Tracer.Builder` or `io.jaegertracing.Configuration`.
Tracer can be created via `io.jaegertracing.JaegerTracerBuilder` or `io.jaegertracing.Configuration`.
For production it is recommended to use both classes with default values.

`Tracer.Builder` example:
`JaegerTracerBuilder` example:

```java
Tracer tracer = new Tracer.Builder("myServiceName")
Tracer tracer = new JaegerTracerBuilder("myServiceName")
.build()
```

Expand All @@ -45,7 +45,7 @@ like "X-B3-TraceId".
Example configuration:
```java
b3Codec = new B3TextMapCodec();
tracer = new Tracer.Builder(serviceName)
tracer = new JaegerTracerBuilder(serviceName)
.registerInjector(Format.Builtin.HTTP_HEADERS, b3Codec)
.registerExtractor(Format.Builtin.HTTP_HEADERS, b3Codec)
...
Expand Down Expand Up @@ -123,7 +123,7 @@ spans in memory:
```java
Reporter reporter = new InMemoryReporter();
Sampler sampler = new ConstSampler(true);
Tracer tracer = new Tracer.Builder(serviceName)
Tracer tracer = new JaegerTracerBuilder(serviceName)
.withReporter(reporter)
.withSampler(sampler)
.build();
Expand Down
78 changes: 39 additions & 39 deletions jaeger-core/src/main/java/io/jaegertracing/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@

package io.jaegertracing;

import io.jaegertracing.metrics.Metrics;
import io.jaegertracing.metrics.MetricsFactory;
import io.jaegertracing.metrics.NoopMetricsFactory;
import io.jaegertracing.propagation.B3TextMapCodec;
import io.jaegertracing.propagation.Codec;
import io.jaegertracing.propagation.CompositeCodec;
import io.jaegertracing.propagation.TextMapCodec;
import io.jaegertracing.reporters.CompositeReporter;
import io.jaegertracing.reporters.LoggingReporter;
import io.jaegertracing.reporters.RemoteReporter;
import io.jaegertracing.reporters.Reporter;
import io.jaegertracing.samplers.ConstSampler;
import io.jaegertracing.samplers.HttpSamplingManager;
import io.jaegertracing.samplers.ProbabilisticSampler;
import io.jaegertracing.samplers.RateLimitingSampler;
import io.jaegertracing.samplers.RemoteControlledSampler;
import io.jaegertracing.samplers.Sampler;
import io.jaegertracing.senders.HttpSender;
import io.jaegertracing.senders.Sender;
import io.jaegertracing.senders.UdpSender;
import io.jaegertracing.internal.JaegerBaseTracer;
import io.jaegertracing.internal.metrics.Metrics;
import io.jaegertracing.internal.metrics.NoopMetricsFactory;
import io.jaegertracing.internal.propagation.B3TextMapCodec;
import io.jaegertracing.internal.propagation.CompositeCodec;
import io.jaegertracing.internal.propagation.TextMapCodec;
import io.jaegertracing.internal.reporters.CompositeReporter;
import io.jaegertracing.internal.reporters.LoggingReporter;
import io.jaegertracing.internal.reporters.RemoteReporter;
import io.jaegertracing.internal.samplers.ConstSampler;
import io.jaegertracing.internal.samplers.HttpSamplingManager;
import io.jaegertracing.internal.samplers.ProbabilisticSampler;
import io.jaegertracing.internal.samplers.RateLimitingSampler;
import io.jaegertracing.internal.samplers.RemoteControlledSampler;
import io.jaegertracing.internal.senders.HttpSender;
import io.jaegertracing.internal.senders.UdpSender;
import io.jaegertracing.spi.Codec;
import io.jaegertracing.spi.Reporter;
import io.jaegertracing.spi.Sampler;
import io.jaegertracing.spi.Sender;
import io.jaegertracing.spi.metrics.MetricsFactory;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import java.text.NumberFormat;
Expand All @@ -48,7 +49,7 @@
import lombok.extern.slf4j.Slf4j;

/**
* This class is designed to provide {@link Tracer} or {@link Tracer.Builder} when Jaeger client
* This class is designed to provide {@link JaegerBaseTracer} or {@link JaegerTracerBuilder} when Jaeger client
* configuration is provided in environmental or property variables. It also simplifies creation
* of the client from configuration files.
*/
Expand Down Expand Up @@ -162,12 +163,12 @@ public enum Propagation {
private Map<String, String> tracerTags;

/**
* lazy singleton Tracer initialized in getTracer() method.
* lazy singleton JaegerBaseTracer initialized in getTracer() method.
*/
private Tracer tracer;
private JaegerBaseTracer tracer;

public Configuration(String serviceName) {
this.serviceName = Tracer.Builder.checkValidServiceName(serviceName);
this.serviceName = JaegerTracerBuilder.checkValidServiceName(serviceName);
}

/**
Expand All @@ -181,7 +182,7 @@ public static Configuration fromEnv() {
.withCodec(CodecConfiguration.fromEnv());
}

public Tracer.Builder getTracerBuilder() {
public JaegerTracerBuilder getTracerBuilder() {
if (reporterConfig == null) {
reporterConfig = new ReporterConfiguration();
}
Expand All @@ -197,13 +198,13 @@ public Tracer.Builder getTracerBuilder() {
Metrics metrics = new Metrics(metricsFactory);
Reporter reporter = reporterConfig.getReporter(metrics);
Sampler sampler = samplerConfig.createSampler(serviceName, metrics);
Tracer.Builder builder = new Tracer.Builder(serviceName)
JaegerTracerBuilder jaegerTracerBuilder = new JaegerTracerBuilder(serviceName)
.withSampler(sampler)
.withReporter(reporter)
.withMetrics(metrics)
.withTags(tracerTags);
codecConfig.apply(builder);
return builder;
codecConfig.apply(jaegerTracerBuilder);
return jaegerTracerBuilder;
}

public synchronized io.opentracing.Tracer getTracer() {
Expand All @@ -224,15 +225,15 @@ public synchronized void closeTracer() {
}

/**
* @param metricsFactory the MetricsFactory to use on the Tracer to be built
* @param metricsFactory the MetricsFactory to use on the JaegerBaseTracer to be built
*/
public Configuration withMetricsFactory(MetricsFactory metricsFactory) {
this.metricsFactory = metricsFactory;
return this;
}

public Configuration withServiceName(String serviceName) {
this.serviceName = Tracer.Builder.checkValidServiceName(serviceName);
this.serviceName = JaegerTracerBuilder.checkValidServiceName(serviceName);
return this;
}

Expand Down Expand Up @@ -313,8 +314,7 @@ public static SamplerConfiguration fromEnv() {
.withManagerHostPort(getProperty(JAEGER_SAMPLER_MANAGER_HOST_PORT));
}

// for tests
Sampler createSampler(String serviceName, Metrics metrics) {
public Sampler createSampler(String serviceName, Metrics metrics) {
String samplerType = stringOrDefault(this.getType(), RemoteControlledSampler.TYPE);
Number samplerParam = numberOrDefault(this.getParam(), ProbabilisticSampler.DEFAULT_SAMPLING_PROBABILITY);
String hostPort = stringOrDefault(this.getManagerHostPort(), HttpSamplingManager.DEFAULT_HOST_PORT);
Expand Down Expand Up @@ -430,20 +430,20 @@ private static void addCodec(Map<Format<?>, List<Codec<TextMap>>> codecs, Format
codecList.add(codec);
}

public void apply(Tracer.Builder builder) {
public void apply(JaegerTracerBuilder jaegerTracerBuilder) {
// Replace existing TEXT_MAP and HTTP_HEADERS codec with one that represents the
// configured propagation formats
registerCodec(builder, Format.Builtin.HTTP_HEADERS);
registerCodec(builder, Format.Builtin.TEXT_MAP);
registerCodec(jaegerTracerBuilder, Format.Builtin.HTTP_HEADERS);
registerCodec(jaegerTracerBuilder, Format.Builtin.TEXT_MAP);
}

protected void registerCodec(Tracer.Builder builder, Format<TextMap> format) {
protected void registerCodec(JaegerTracerBuilder jaegerTracerBuilder, Format<TextMap> format) {
if (codecs.containsKey(format)) {
List<Codec<TextMap>> codecsForFormat = codecs.get(format);
Codec<TextMap> codec = codecsForFormat.size() == 1
? codecsForFormat.get(0) : new CompositeCodec<TextMap>(codecsForFormat);
builder.registerInjector(format, codec);
builder.registerExtractor(format, codec);
jaegerTracerBuilder.registerInjector(format, codec);
jaegerTracerBuilder.registerExtractor(format, codec);
}
}
}
Expand Down Expand Up @@ -705,7 +705,7 @@ private static Map<String, String> tracerTagsFromEnv() {
}
tracerTagMaps.put(tagValue[0], resolveValue(tagValue[1]));
} else {
log.error("Tracer tag incorrectly formatted: " + tag);
log.error("JaegerBaseTracer tag incorrectly formatted: " + tag);
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions jaeger-core/src/main/java/io/jaegertracing/JaegerTracer.java
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;

import io.opentracing.Tracer;

/**
* Defines the Jaeger Tracer extensions to the OpenTracing API.
*/
public interface JaegerTracer extends Tracer {
String getServiceName();

int getIpv4();
}
Loading

0 comments on commit 2595cf1

Please sign in to comment.