@@ -24,14 +24,14 @@ import java.util.concurrent.ConcurrentHashMap
2424
2525import com .expedia .open .tracing .{Span , Tag }
2626import com .expedia .www .haystack .collector .commons .ProtoSpanExtractor ._
27- import com .expedia .www .haystack .collector .commons .config .{ExtractorConfiguration , Format , SpanMaxSize }
27+ import com .expedia .www .haystack .collector .commons .config .{ExtractorConfiguration , Format }
2828import com .expedia .www .haystack .collector .commons .record .{KeyValueExtractor , KeyValuePair }
2929import com .expedia .www .haystack .span .decorators .SpanDecorator
3030import com .google .protobuf .util .JsonFormat
3131import org .slf4j .Logger
3232
33- import scala .util .{Failure , Success , Try }
3433import scala .collection .JavaConverters ._
34+ import scala .util .{Failure , Success , Try }
3535
3636object ProtoSpanExtractor {
3737 private val DaysInYear1970 = 365
@@ -45,10 +45,9 @@ object ProtoSpanExtractor {
4545 val TraceIdIsRequired = " Trace ID is required: serviceName=[%s] operationName=[%s]"
4646 val StartTimeIsInvalid = " Start time [%d] is invalid: serviceName=[%s] operationName=[%s]"
4747 val DurationIsInvalid = " Duration [%d] is invalid: serviceName=[%s] operationName=[%s]"
48- val SpanSizeLimitExceeded = " Span Size Limit Exceeded: serviceName=[%s] operationName=[%s] traceId=[%s] spanSize=[%d]"
48+ val SpanSizeLimitExceeded = " Span Size Limit Exceeded: serviceName=[%s] operationName=[%s] traceId=[%s] spanSize=[%d] probableTags=[%s] "
4949
5050 val ServiceNameVsTtlAndOperationNames = new ConcurrentHashMap [String , TtlAndOperationNames ]
51- val MaximumOperationNameCount = 1000
5251 val OperationNameCountExceededMeterName = " operation.name.count.exceeded"
5352}
5453
@@ -60,7 +59,7 @@ class ProtoSpanExtractor(extractorConfiguration: ExtractorConfiguration,
6059
6160 private val invalidSpanMeter = metricRegistry.meter(" invalid.span" )
6261 private val validSpanMeter = metricRegistry.meter(" valid.span" )
63- private val spanSizeLimitExceeded = metricRegistry.meter(" sizeLimitExceeded.span" )
62+ private val spanSizeLimitExceededMeter = metricRegistry.meter(" sizeLimitExceeded.span" )
6463
6564 override def configure (): Unit = ()
6665
@@ -89,12 +88,12 @@ class ProtoSpanExtractor(extractorConfiguration: ExtractorConfiguration,
8988 }
9089
9190 def validateSpanSize (span : Span ): Try [Span ] = {
92- if (extractorConfiguration.spanValidation.spanMaxSize.enable)
93- {
94- val spanSize = span.toByteArray.length
95- val maxSizeLimit = extractorConfiguration.spanValidation.spanMaxSize.maxSizeLimit
96- validate(span, spanSize, SpanSizeLimitExceeded , maxSizeLimit)
97- }
91+ if (extractorConfiguration.spanValidation.spanMaxSize.enable
92+ && ! extractorConfiguration.spanValidation.spanMaxSize.skipServices.contains(span.getServiceName.toLowerCase)) {
93+ val spanSize = span.toByteArray.length
94+ val maxSizeLimit = extractorConfiguration.spanValidation.spanMaxSize.maxSizeLimit
95+ validate(span, spanSize, SpanSizeLimitExceeded , maxSizeLimit)
96+ }
9897 else
9998 Success (span)
10099 }
@@ -141,24 +140,39 @@ class ProtoSpanExtractor(extractorConfiguration: ExtractorConfiguration,
141140 highestValidValue : Int ): Try [Span ] = {
142141
143142 if (valueToValidate > highestValidValue) {
144- spanSizeLimitExceeded.mark()
145- LOGGER .debug(msg.format(span.getServiceName, span.getOperationName, span.getTraceId, valueToValidate))
146- Success (truncateTags(span))
143+ spanSizeLimitExceededMeter.mark()
144+ LOGGER .debug(msg.format(span.getServiceName, span.getOperationName, span.getTraceId, valueToValidate, getProbableTagsExceedingSizeLimit(span)))
145+ if (extractorConfiguration.spanValidation.spanMaxSize.logOnly) {
146+ Success (span)
147+ } else {
148+ Success (truncateTags(span))
149+ }
147150 }
148151 else {
149152 Success (span)
150153 }
151154 }
152155
153- private def truncateTags (span : Span ): Span = {
154- val errorTag = span.getTagsList.asScala.filter(tag => tag.getKey.equalsIgnoreCase(" error" ))
155- val spanBuilder = span.toBuilder
156- val messsageTagKey = extractorConfiguration.spanValidation.spanMaxSize.infoTagKey
157- val messageTagValue = extractorConfiguration.spanValidation.spanMaxSize.infoTagValue
156+ private def getProbableTagsExceedingSizeLimit (span : Span ): String = {
157+ span.getTagsList.asScala
158+ .filter(tag => tag.getVStrBytes.size > extractorConfiguration.spanValidation.spanMaxSize.maxSizeLimit)
159+ .map(_.getKey)
160+ .mkString(" , " )
161+ }
162+
163+ private def truncateTags (span : Span ): Span = {
164+ val skippedTags = span.getTagsList.asScala
165+ .filter(tag => extractorConfiguration.spanValidation.spanMaxSize.skipTags.contains(tag.getKey.toLowerCase))
158166
167+ val spanBuilder = span.toBuilder
159168 spanBuilder.clearTags()
160- errorTag.foreach(tag => spanBuilder.addTags(tag))
161- spanBuilder.addTags(Tag .newBuilder().setKey(messsageTagKey).setVStr(messageTagValue))
169+
170+ skippedTags.foreach(spanBuilder.addTags)
171+
172+ val truncateTagKey = extractorConfiguration.spanValidation.spanMaxSize.infoTagKey
173+ val truncateTagValue = extractorConfiguration.spanValidation.spanMaxSize.infoTagValue
174+ spanBuilder.addTags(Tag .newBuilder().setKey(truncateTagKey).setVStr(truncateTagValue))
175+
162176 spanBuilder.build()
163177 }
164178
0 commit comments