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

Commit

Permalink
Enable process level tags to be associated with the tracer (#143)
Browse files Browse the repository at this point in the history
* Enable process level tags to be associated with the tracer
* Improve test coverage
  • Loading branch information
objectiser authored and yurishkuro committed Apr 20, 2017
1 parent b06e541 commit 999283e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
22 changes: 19 additions & 3 deletions jaeger-core/src/main/java/com/uber/jaeger/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private Tracer(
Sampler sampler,
PropagationRegistry registry,
Clock clock,
Metrics metrics) {
Metrics metrics,
Map<String, Object> tags) {
this.serviceName = serviceName;
this.reporter = reporter;
this.sampler = sampler;
Expand All @@ -89,7 +90,6 @@ private Tracer(

this.version = loadVersion();

Map<String, Object> tags = new HashMap<String, Object>();
tags.put("jaeger.version", this.version);
String hostname = getHostName();
if (hostname != null) {
Expand Down Expand Up @@ -326,6 +326,7 @@ public static final class Builder {
private Metrics metrics;
private String serviceName;
private Clock clock = new SystemClock();
private Map<String, Object> tags = new HashMap<String, Object>();

public Builder(String serviceName, Reporter reporter, Sampler sampler) {
if (serviceName == null || serviceName.trim().length() == 0) {
Expand Down Expand Up @@ -370,8 +371,23 @@ Builder withMetrics(Metrics metrics) {
return this;
}

Builder withTag(String key, String value) {
tags.put(key, value);
return this;
}

Builder withTag(String key, boolean value) {
tags.put(key, value);
return this;
}

Builder withTag(String key, Number value) {
tags.put(key, value);
return this;
}

public Tracer build() {
return new Tracer(this.serviceName, reporter, sampler, registry, clock, metrics);
return new Tracer(this.serviceName, reporter, sampler, registry, clock, metrics, tags);
}
}

Expand Down
15 changes: 14 additions & 1 deletion jaeger-core/src/test/java/com/uber/jaeger/TracerTagsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,27 @@ public static Collection<Object[]> data() {
Map<String, Object> rootTags = new HashMap<>();
rootTags.put("jaeger.version", tracer.getVersion());
rootTags.put("jaeger.hostname", hostname);
rootTags.put("tracer.tag.str", "y");
rootTags.put("tracer.tag.bool", true);
rootTags.put("tracer.tag.num", 1);
rootTags.put("sampler.type", "const");
rootTags.put("sampler.param", true);

Map<String, Object> childTags = new HashMap<>();
childTags.put("jaeger.version", SENTINEL);
childTags.put("jaeger.hostname", SENTINEL);
childTags.put("tracer.tag.str", SENTINEL);
childTags.put("tracer.tag.bool", SENTINEL);
childTags.put("tracer.tag.num", SENTINEL);
childTags.put("sampler.type", SENTINEL);
childTags.put("sampler.param", SENTINEL);

Map<String, Object> rpcTags = new HashMap<>();
rpcTags.put("jaeger.version", tracer.getVersion());
rpcTags.put("jaeger.hostname", hostname);
rpcTags.put("tracer.tag.str", "y");
rpcTags.put("tracer.tag.bool", true);
rpcTags.put("tracer.tag.num", 1);
rpcTags.put("sampler.type", SENTINEL);
rpcTags.put("sampler.param", SENTINEL);

Expand All @@ -94,7 +103,11 @@ public void setUp() throws Exception {}
@Test
public void testTracerTags() throws Exception {
InMemoryReporter spanReporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("x", spanReporter, new ConstSampler(true)).build();
Tracer tracer = new Tracer.Builder("x", spanReporter, new ConstSampler(true))
.withTag("tracer.tag.str", "y")
.withTag("tracer.tag.bool", true)
.withTag("tracer.tag.num", 1)
.build();

Span span = (Span) tracer.buildSpan("root").start();
if (spanType == SpanType.CHILD) {
Expand Down

0 comments on commit 999283e

Please sign in to comment.