Fix collect spans (#209)

This commit is contained in:
KirillPamPam
2023-04-24 11:38:27 +04:00
committed by GitHub
parent dca0e6614f
commit 89330da4b0

View File

@@ -35,7 +35,7 @@ class ErrorSpanHandler(
currentSpan.context().parentId()?.let { currentSpan.context().parentId()?.let {
spans.getIfPresent(it)?.let { mutableSpans -> spans.getIfPresent(it)?.let { mutableSpans ->
if (mutableSpans.isNotEmpty()) { if (mutableSpans.isNotEmpty()) {
spansInfo.spans.add(mutableSpans[0]) processSpanInfo(mutableSpans[0], spansInfo)
} }
} }
} }
@@ -59,16 +59,20 @@ class ErrorSpanHandler(
val currentSpans: List<MutableSpan>? = spans.getIfPresent(spanId) val currentSpans: List<MutableSpan>? = spans.getIfPresent(spanId)
currentSpans?.forEach { currentSpans?.forEach {
spansInfo.spans.add(it) processSpanInfo(it, spansInfo)
if (it.tags().containsKey(SPAN_ERROR)) {
spansInfo.hasError = true
}
if (spanId != it.id()) { if (spanId != it.id()) {
enrichErrorSpans(it.id(), spansInfo) enrichErrorSpans(it.id(), spansInfo)
} }
} }
} }
private fun processSpanInfo(span: MutableSpan, spansInfo: SpansInfo) {
spansInfo.spans.add(span)
if (span.tags().containsKey(SPAN_ERROR)) {
spansInfo.hasError = true
}
}
private data class SpansInfo( private data class SpansInfo(
var hasError: Boolean = false, var hasError: Boolean = false,
val spans: MutableList<MutableSpan> = mutableListOf() val spans: MutableList<MutableSpan> = mutableListOf()