Skip to content

Commit

Permalink
Merge pull request #183 from ExpediaDotCom/ConditionallyIndexTagServi…
Browse files Browse the repository at this point in the history
…ceNameIfItExists

If the "service" tag exists in the span, send it to ElasticSearch and
  • Loading branch information
Jason Bulicek authored Oct 2, 2018
2 parents 8816a55 + d085b65 commit 4f5cef6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.time.Instant
import com.datastax.driver.core.Statement
import com.expedia.open.tracing.Span
import com.expedia.www.haystack.trace.commons.clients.cassandra.CassandraSession
import com.expedia.www.haystack.trace.commons.utils.SpanUtils
import com.expedia.www.haystack.trace.indexer.config.entities.ServiceMetadataWriteConfiguration
import org.apache.commons.lang3.StringUtils

Expand Down Expand Up @@ -72,8 +73,9 @@ class ServiceMetadataStatementBuilder(cassandra: CassandraSession,
def getAndUpdateServiceMetadata(spans: Iterable[Span]): Seq[Statement] = {
this.synchronized {
spans.foreach(span => {
if (StringUtils.isNotEmpty(span.getServiceName) && StringUtils.isNotEmpty(span.getOperationName)) {
val operationsList = serviceMetadataMap.getOrElseUpdate(span.getServiceName, mutable.Set[String]())
val serviceName = SpanUtils.getEffectiveServiceName(span)
if (StringUtils.isNotEmpty(serviceName) && StringUtils.isNotEmpty(span.getOperationName)) {
val operationsList = serviceMetadataMap.getOrElseUpdate(serviceName, mutable.Set[String]())
if (operationsList.add(span.getOperationName)) {
allOperationCount += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.expedia.www.haystack.trace.commons.clients.es.document.TraceIndexDoc
import com.expedia.www.haystack.trace.commons.clients.es.document.TraceIndexDoc.{OPERATION_KEY_NAME, SERVICE_KEY_NAME, TagValue}
import com.expedia.www.haystack.trace.commons.config.entities.IndexFieldType.IndexFieldType
import com.expedia.www.haystack.trace.commons.config.entities.{IndexFieldType, WhitelistIndexFieldConfiguration}
import com.expedia.www.haystack.trace.commons.utils.SpanUtils
import org.apache.commons.lang3.StringUtils

import scala.collection.JavaConverters._
Expand Down Expand Up @@ -53,11 +54,12 @@ class IndexDocumentGenerator(config: WhitelistIndexFieldConfiguration) extends M
traceStartTime = Math.min(traceStartTime, microsToSecondGranularity(span.getStartTime))
if(span.getParentSpanId == null) rootDuration = span.getDuration

val serviceName = SpanUtils.getEffectiveServiceName(span)
val spanIndexDoc = spanIndices
.find(sp => sp(OPERATION_KEY_NAME).equals(span.getOperationName) && sp(SERVICE_KEY_NAME).equals(span.getServiceName))
.find(sp => sp(OPERATION_KEY_NAME).equals(span.getOperationName) && sp(SERVICE_KEY_NAME).equals(serviceName))
.getOrElse({
val newSpanIndexDoc = mutable.Map[String, Any](
SERVICE_KEY_NAME -> span.getServiceName,
SERVICE_KEY_NAME -> serviceName,
OPERATION_KEY_NAME -> span.getOperationName)
spanIndices.append(newSpanIndexDoc)
newSpanIndexDoc
Expand All @@ -68,7 +70,7 @@ class IndexDocumentGenerator(config: WhitelistIndexFieldConfiguration) extends M
}

private def isValidForIndex(span: Span): Boolean = {
StringUtils.isNotEmpty(span.getServiceName) && StringUtils.isNotEmpty(span.getOperationName)
StringUtils.isNotEmpty(SpanUtils.getEffectiveServiceName(span)) && StringUtils.isNotEmpty(span.getOperationName)
}

/**
Expand Down
15 changes: 0 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,6 @@
<artifactId>config</artifactId>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</dependency>

<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>

<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ object SpanMerger {
Span
.newBuilder(serverSpan)
.setParentSpanId(clientSpan.getParentSpanId) // use the parentSpanId of the client span to stitch in the client's trace tree
.addAllTags((clientSpan.getTagsList.asScala ++ auxiliaryCommonTags(clientSpan, serverSpan) ++ auxiliaryClientTags(clientSpan) ++ auxiliaryServerTags(serverSpan)).asJavaCollection)
.clearLogs().addAllLogs((clientSpan.getLogsList.asScala ++ serverSpan.getLogsList.asScala.sortBy(_.getTimestamp)).asJavaCollection)
.addAllTags((clientSpan.getTagsList.asScala
++ auxiliaryCommonTags(clientSpan, serverSpan)
++ auxiliaryClientTags(clientSpan)
++ auxiliaryServerTags(serverSpan)).asJavaCollection)
.clearLogs().addAllLogs((clientSpan.getLogsList.asScala
++ serverSpan.getLogsList.asScala.sortBy(_.getTimestamp)).asJavaCollection)
.build()
}

Expand Down Expand Up @@ -108,7 +112,7 @@ object SpanMerger {

private def auxiliaryClientTags(span: Span): List[Tag] =
List(
buildStringTag(AuxiliaryTags.CLIENT_SERVICE_NAME, span.getServiceName),
buildStringTag(AuxiliaryTags.CLIENT_SERVICE_NAME, SpanUtils.getEffectiveServiceName(span)),
buildStringTag(AuxiliaryTags.CLIENT_OPERATION_NAME, span.getOperationName),
buildStringTag(AuxiliaryTags.CLIENT_INFRASTRUCTURE_PROVIDER, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_PROVIDER)),
buildStringTag(AuxiliaryTags.CLIENT_INFRASTRUCTURE_LOCATION, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_LOCATION)),
Expand All @@ -118,7 +122,7 @@ object SpanMerger {

private def auxiliaryServerTags(span: Span): List[Tag] = {
List(
buildStringTag(AuxiliaryTags.SERVER_SERVICE_NAME, span.getServiceName),
buildStringTag(AuxiliaryTags.SERVER_SERVICE_NAME, SpanUtils.getEffectiveServiceName(span)),
buildStringTag(AuxiliaryTags.SERVER_OPERATION_NAME, span.getOperationName),
buildStringTag(AuxiliaryTags.SERVER_INFRASTRUCTURE_PROVIDER, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_PROVIDER)),
buildStringTag(AuxiliaryTags.SERVER_INFRASTRUCTURE_LOCATION, extractTagStringValue(span, AuxiliaryTags.INFRASTRUCTURE_LOCATION)),
Expand Down

0 comments on commit 4f5cef6

Please sign in to comment.