Skip to content

Commit 623224c

Browse files
Merge pull request #97 from eocantu/skip-error-false
Set error tag to false when string value is false
2 parents 0ae2a9e + 92493fe commit 623224c

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

agent-providers/span/src/main/java/com/expedia/www/haystack/agent/pitchfork/processors/HaystackDomainConverter.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,29 @@ private static List<Tag> fromZipkinTag(String key, String value) {
156156
if ("error".equalsIgnoreCase(key)) {
157157
// Zipkin error tags are Strings where as in Haystack they're Booleans
158158
// Since a Zipkin error tag may contain relevant information about the error we expand it into two tags (error + error message)
159-
Tag errorTag = Tag.newBuilder()
159+
if (!"false".equalsIgnoreCase(value)) {
160+
Tag errorTag = Tag.newBuilder()
160161
.setKey(key)
161162
.setVBool(true)
162163
.setType(Tag.TagType.BOOL)
163164
.build();
164165

165-
Tag errorMessageTag = Tag.newBuilder()
166+
Tag errorMessageTag = Tag.newBuilder()
166167
.setKey("error_msg")
167168
.setVStr(value)
168169
.setType(Tag.TagType.STRING)
169170
.build();
170171

171-
return Arrays.asList(errorTag, errorMessageTag);
172+
return Arrays.asList(errorTag, errorMessageTag);
173+
} else {
174+
final Tag errorTag = Tag.newBuilder()
175+
.setKey(key)
176+
.setVBool(false)
177+
.setType(Tag.TagType.BOOL)
178+
.build();
179+
180+
return Collections.singletonList(errorTag);
181+
}
172182
}
173183

174184
final Tag tag = Tag.newBuilder()

agent-providers/span/src/test/scala/com/expedia/www/haystack/agent/pitchfork/processors/HaystackDomainConverterSpec.scala

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.expedia.www.haystack.agent.pitchfork.processors
22

3+
import com.expedia.open.tracing.Tag
34
import org.scalatest.{FunSpec, Matchers}
45
import org.scalatest.easymock.EasyMockSugar
56
import zipkin2.{Endpoint, Span}
@@ -16,17 +17,38 @@ class HaystackDomainConverterSpec extends FunSpec with Matchers with EasyMockSug
1617
.remoteEndpoint(Endpoint.newBuilder().serviceName("bar").port(8080).ip("10.10.10.10").build())
1718
.timestamp(System.currentTimeMillis() * 1000)
1819
.duration(100000l)
19-
.putTag("error", "true")
2020
.putTag("pos", "1")
2121
}
2222

2323
describe("Haystack Domain Converter") {
24-
it("should create span from Zipking span") {
24+
it("should create span from Zipkin span") {
2525
val traceId = "bd1068b1bc333ec0"
2626
val zipkinSpan = zipkinSpanBuilder(traceId).clearTags().build()
2727
val span = HaystackDomainConverter.fromZipkinV2(zipkinSpan)
2828

2929
span.getTraceId shouldBe traceId
30+
span.getTagsList.stream().filter(_.getKey == "error").count() shouldBe 0
31+
}
32+
33+
it("should create span from Zipkin span with error false") {
34+
val traceId = "bd1068b1bc333ec0"
35+
val zipkinSpan = zipkinSpanBuilder(traceId).putTag("error", "false").build()
36+
val span = HaystackDomainConverter.fromZipkinV2(zipkinSpan)
37+
38+
span.getTraceId shouldBe traceId
39+
span.getTagsList.stream().filter(_.getKey == "error").count() shouldBe 1
40+
span.getTagsList.stream().filter(tag => tag.getKey == "error" && tag.getType == Tag.TagType.BOOL && !tag.getVBool).count() shouldBe 1
41+
}
42+
43+
it("should create span from Zipkin span with error true") {
44+
val traceId = "bd1068b1bc333ec0"
45+
val zipkinSpan = zipkinSpanBuilder(traceId).putTag("error", "bad things").build()
46+
val span = HaystackDomainConverter.fromZipkinV2(zipkinSpan)
47+
48+
span.getTraceId shouldBe traceId
49+
span.getTagsList.stream().filter(_.getKey == "error").count() shouldBe 1
50+
span.getTagsList.stream().filter(tag => tag.getKey == "error" && tag.getType == Tag.TagType.BOOL && tag.getVBool).count() shouldBe 1
51+
span.getTagsList.stream().filter(_.getKey == "error_msg").count() shouldBe 1
3052
}
3153

3254
it("should create span with kind tag") {

0 commit comments

Comments
 (0)