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

Binary format implementation #613

Merged
merged 3 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions jaeger-core/src/main/java/io/jaegertracing/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.jaegertracing.internal.metrics.Metrics;
import io.jaegertracing.internal.metrics.NoopMetricsFactory;
import io.jaegertracing.internal.propagation.B3TextMapCodec;
import io.jaegertracing.internal.propagation.BinaryCodec;
import io.jaegertracing.internal.propagation.CompositeCodec;
import io.jaegertracing.internal.propagation.TextMapCodec;
import io.jaegertracing.internal.reporters.CompositeReporter;
Expand All @@ -36,6 +37,7 @@
import io.jaegertracing.spi.Sampler;
import io.jaegertracing.spi.Sender;
import io.jaegertracing.spi.SenderFactory;
import io.opentracing.propagation.Binary;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;
import java.text.NumberFormat;
Expand Down Expand Up @@ -424,9 +426,11 @@ public SamplerConfiguration withManagerHostPort(String managerHostPort) {
*/
public static class CodecConfiguration {
private final Map<Format<?>, List<Codec<TextMap>>> codecs;
private final Map<Format<?>, List<Codec<Binary>>> binaryCodecs;

public CodecConfiguration() {
codecs = new HashMap<Format<?>, List<Codec<TextMap>>>();
binaryCodecs = new HashMap<Format<?>, List<Codec<Binary>>>();
}

public static CodecConfiguration fromEnv() {
Expand Down Expand Up @@ -457,6 +461,7 @@ public CodecConfiguration withPropagation(Propagation propagation) {
case JAEGER:
addCodec(codecs, Format.Builtin.HTTP_HEADERS, new TextMapCodec(true));
addCodec(codecs, Format.Builtin.TEXT_MAP, new TextMapCodec(false));
addBinaryCodec(binaryCodecs, Format.Builtin.BINARY, new BinaryCodec());
break;
case B3:
addCodec(codecs, Format.Builtin.HTTP_HEADERS, new B3TextMapCodec.Builder().build());
Expand All @@ -473,10 +478,19 @@ public CodecConfiguration withCodec(Format<?> format, Codec<TextMap> codec) {
return this;
}

public CodecConfiguration withBinaryCodec(Format<?> format, Codec<Binary> codec) {
addBinaryCodec(binaryCodecs, format, codec);
return this;
}

public Map<Format<?>, List<Codec<TextMap>>> getCodecs() {
return Collections.unmodifiableMap(codecs);
}

public Map<Format<?>, List<Codec<Binary>>> getBinaryCodecs() {
return Collections.unmodifiableMap(binaryCodecs);
}

private static void addCodec(Map<Format<?>, List<Codec<TextMap>>> codecs, Format<?> format, Codec<TextMap> codec) {
List<Codec<TextMap>> codecList = codecs.get(format);
if (codecList == null) {
Expand All @@ -486,11 +500,23 @@ private static void addCodec(Map<Format<?>, List<Codec<TextMap>>> codecs, Format
codecList.add(codec);
}

private static void addBinaryCodec(Map<Format<?>, List<Codec<Binary>>> codecs,
Format<?> format, Codec<Binary> codec) {

List<Codec<Binary>> codecList = codecs.get(format);
if (codecList == null) {
codecList = new LinkedList<Codec<Binary>>();
codecs.put(format, codecList);
}
codecList.add(codec);
}

public void apply(JaegerTracer.Builder builder) {
// 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);
registerBinaryCodec(builder, Format.Builtin.BINARY);
}

protected void registerCodec(JaegerTracer.Builder builder, Format<TextMap> format) {
Expand All @@ -502,6 +528,16 @@ protected void registerCodec(JaegerTracer.Builder builder, Format<TextMap> forma
builder.registerExtractor(format, codec);
}
}

protected void registerBinaryCodec(JaegerTracer.Builder builder, Format<Binary> format) {
if (codecs.containsKey(format)) {
List<Codec<Binary>> codecsForFormat = binaryCodecs.get(format);
Codec<Binary> codec = codecsForFormat.size() == 1
? codecsForFormat.get(0) : new CompositeCodec<Binary>(codecsForFormat);
builder.registerInjector(format, codec);
builder.registerExtractor(format, codec);
}
}
}

public static class ReporterConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ public boolean isDebug() {
return (flags & flagDebug) == flagDebug;
}

/**
* @return the number of items in baggage.
*/
public int baggageCount() {
return baggage.size();
}

@Override
public String toString() {
return TextMapCodec.contextAsString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.jaegertracing.internal.exceptions.UnsupportedFormatException;
import io.jaegertracing.internal.metrics.Metrics;
import io.jaegertracing.internal.metrics.NoopMetricsFactory;
import io.jaegertracing.internal.propagation.BinaryCodec;
import io.jaegertracing.internal.propagation.TextMapCodec;
import io.jaegertracing.internal.reporters.RemoteReporter;
import io.jaegertracing.internal.samplers.RemoteControlledSampler;
Expand Down Expand Up @@ -538,7 +539,12 @@ protected Builder(String serviceName, JaegerObjectFactory objectFactory) {
.build();
this.registerInjector(Format.Builtin.HTTP_HEADERS, httpCodec);
this.registerExtractor(Format.Builtin.HTTP_HEADERS, httpCodec);
// TODO binary codec not implemented
BinaryCodec binaryCodec =
BinaryCodec.builder()
.withObjectFactory(this.objectFactory)
.build();
this.registerInjector(Format.Builtin.BINARY, binaryCodec);
this.registerExtractor(Format.Builtin.BINARY, binaryCodec);
}

/**
Expand Down
Loading