Skip to content

Commit e910614

Browse files
Ashish AggarwalAshish Aggarwal
authored andcommitted
fix README and improving tests
1 parent 3632343 commit e910614

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

integrations/opencensus/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ For Maven add to your `pom.xml`:
1616
<version>0.17.0</version>
1717
</dependency>
1818
<dependency>
19-
<groupId>io.opencensus</groupId>
19+
<groupId>com.expedia.www</groupId>
2020
<artifactId>opencensus-exporter-trace-haystack</artifactId>
2121
<version>[0.2.1,)</version>
2222
</dependency>
@@ -32,7 +32,7 @@ For Maven add to your `pom.xml`:
3232
For Gradle add to your dependencies:
3333
```groovy
3434
compile 'io.opencensus:opencensus-api:0.17.0'
35-
compile 'io.opencensus:opencensus-exporter-trace-haystack:0.2.1'
35+
compile 'com.expedia.www:opencensus-exporter-trace-haystack:0.2.1'
3636
runtime 'io.opencensus:opencensus-impl:0.17.0'
3737
```
3838

integrations/opencensus/src/main/java/com/www/expedia/opencensus/exporter/trace/config/GrpcAgentDispatcherConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class GrpcAgentDispatcherConfig extends DispatcherConfig {
2424
private final String host;
2525
private int port;
2626

27+
public GrpcAgentDispatcherConfig() {
28+
this("haystack-agent", 35000);
29+
}
30+
2731
public GrpcAgentDispatcherConfig(final String host,
2832
final int port) {
2933
this(host, port, 5000);

integrations/opencensus/src/test/scala/com/www/expedia/opencensus/exporter/trace/HaystackExporterIntegrationSpec.scala

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import java.util
2222
import java.util.{Collections, Random}
2323

2424
import com.www.expedia.opencensus.exporter.trace.config.GrpcAgentDispatcherConfig
25+
import io.opencensus.trace._
2526
import io.opencensus.trace.samplers.Samplers
26-
import io.opencensus.trace.{AttributeValue, Status, Tracer, Tracing}
2727
import org.apache.kafka.clients.consumer.ConsumerConfig._
2828
import org.apache.kafka.clients.consumer.KafkaConsumer
2929
import org.apache.kafka.common.serialization.{ByteArrayDeserializer, StringDeserializer}
@@ -34,6 +34,8 @@ import scala.collection.JavaConverters._
3434
class HaystackExporterIntegrationSpec extends FunSpec with GivenWhenThen with Matchers with BeforeAndAfterAll {
3535
private val OPERATION_NAME = "/search"
3636
private val SERVICE_NAME = "my-service"
37+
private val START_TIME_MICROS = System.currentTimeMillis() * 1000
38+
private val MAX_DURATION_MILLIS = 10
3739
private var consumer: KafkaConsumer[String, Array[Byte]] = _
3840

3941
override def beforeAll(): Unit = {
@@ -51,27 +53,34 @@ class HaystackExporterIntegrationSpec extends FunSpec with GivenWhenThen with Ma
5153
}
5254

5355
private def generateTrace(tracer: Tracer) = {
54-
val spanBuilder = tracer.spanBuilder(OPERATION_NAME).setRecordEvents(true).setSampler(Samplers.alwaysSample())
55-
val spanDurationInMillis = new Random().nextInt(10) + 1
56+
val spanBuilder = tracer
57+
.spanBuilder(OPERATION_NAME)
58+
.setSpanKind(Span.Kind.SERVER)
59+
.setSampler(Samplers.alwaysSample())
60+
61+
val spanDurationInMillis = new Random().nextInt(MAX_DURATION_MILLIS) + 1
5662

5763
val scopedSpan = spanBuilder.startScopedSpan
5864
try {
5965
tracer.getCurrentSpan.addAnnotation("start searching")
6066
Thread.sleep(spanDurationInMillis)
6167
tracer.getCurrentSpan.putAttribute("foo", AttributeValue.stringAttributeValue("bar"))
6268
tracer.getCurrentSpan.putAttribute("items", AttributeValue.longAttributeValue(10l))
63-
tracer.getCurrentSpan.addAnnotation("done searching")
69+
tracer.getCurrentSpan.putAttribute("price", AttributeValue.doubleAttributeValue(5.5))
70+
tracer.getCurrentSpan.putAttribute("error", AttributeValue.booleanAttributeValue(true))
71+
tracer.getCurrentSpan.addAnnotation("done searching",
72+
Collections.singletonMap("someevent", AttributeValue.longAttributeValue(200)))
6473
} catch {
6574
case _: Exception =>
66-
tracer.getCurrentSpan.addAnnotation("Exception thrown when processing video.")
75+
tracer.getCurrentSpan.addAnnotation("Exception thrown when processing!")
6776
tracer.getCurrentSpan.setStatus(Status.UNKNOWN)
6877
} finally {
6978
scopedSpan.close()
7079
}
7180
}
7281

7382
describe("Integration Test with haystack and opencensus") {
74-
it ("should dispatch the spans to haystack-agent") {
83+
it("should dispatch the spans to haystack-agent") {
7584
HaystackTraceExporter.createAndRegister(new GrpcAgentDispatcherConfig("haystack-agent", 35000), SERVICE_NAME)
7685
val tracer = Tracing.getTracer
7786

@@ -89,9 +98,17 @@ class HaystackExporterIntegrationSpec extends FunSpec with GivenWhenThen with Ma
8998
protoSpan.getTraceId shouldEqual record.key()
9099
protoSpan.getServiceName shouldEqual SERVICE_NAME
91100
protoSpan.getOperationName shouldEqual OPERATION_NAME
92-
protoSpan.getTagsCount shouldBe 2
101+
protoSpan.getStartTime should be >= START_TIME_MICROS
102+
protoSpan.getTagsCount shouldBe 5
103+
protoSpan.getTagsList.asScala.find(_.getKey == "span.kind").get.getVStr shouldEqual "server"
93104
protoSpan.getTagsList.asScala.find(_.getKey == "foo").get.getVStr shouldEqual "bar"
94105
protoSpan.getTagsList.asScala.find(_.getKey == "items").get.getVLong shouldBe 10
106+
protoSpan.getTagsList.asScala.find(_.getKey == "price").get.getVDouble shouldBe 5.5
107+
protoSpan.getTagsList.asScala.find(_.getKey == "error").get.getVBool shouldBe true
108+
protoSpan.getLogsCount shouldBe 2
109+
protoSpan.getLogs(0).getFieldsList.asScala.find(_.getKey == "message").get.getVStr shouldEqual "start searching"
110+
protoSpan.getLogs(1).getFieldsList.asScala.find(_.getKey == "message").get.getVStr shouldEqual "done searching"
111+
protoSpan.getLogs(1).getFieldsList.asScala.find(_.getKey == "someevent").get.getVLong shouldBe 200l
95112
}
96113
}
97-
}
114+
}

0 commit comments

Comments
 (0)