Send spans if they are too long (#225)
This commit is contained in:
@@ -3,7 +3,9 @@ package io.emeraldpay.dshackle.config.spans
|
|||||||
import brave.handler.MutableSpan
|
import brave.handler.MutableSpan
|
||||||
import io.emeraldpay.dshackle.commons.SPAN_ERROR
|
import io.emeraldpay.dshackle.commons.SPAN_ERROR
|
||||||
import io.emeraldpay.dshackle.commons.SPAN_NO_RESPONSE_MESSAGE
|
import io.emeraldpay.dshackle.commons.SPAN_NO_RESPONSE_MESSAGE
|
||||||
|
import org.springframework.beans.factory.annotation.Value
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
interface SpanExportable {
|
interface SpanExportable {
|
||||||
fun isExportable(span: MutableSpan): Boolean
|
fun isExportable(span: MutableSpan): Boolean
|
||||||
@@ -18,3 +20,15 @@ class ErrorSpanExportable : SpanExportable {
|
|||||||
class NoResponseSpanExportable : SpanExportable {
|
class NoResponseSpanExportable : SpanExportable {
|
||||||
override fun isExportable(span: MutableSpan): Boolean = span.tags().containsKey(SPAN_NO_RESPONSE_MESSAGE)
|
override fun isExportable(span: MutableSpan): Boolean = span.tags().containsKey(SPAN_NO_RESPONSE_MESSAGE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class LongResponseSpanExportable(
|
||||||
|
@Value("\${spans.collect.provider.long-span-threshold}")
|
||||||
|
private val longSpanThreshold: Long? = null
|
||||||
|
) : SpanExportable {
|
||||||
|
|
||||||
|
override fun isExportable(span: MutableSpan): Boolean {
|
||||||
|
val duration = span.finishTimestamp() - span.startTimestamp()
|
||||||
|
return TimeUnit.SECONDS.convert(duration, TimeUnit.MICROSECONDS) >= longSpanThreshold!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ spans:
|
|||||||
enabled: ${ENABLE_COLLECT_SPANS:false}
|
enabled: ${ENABLE_COLLECT_SPANS:false}
|
||||||
provider:
|
provider:
|
||||||
enabled: ${ENABLE_PROVIDER_COLLECT_SPANS:true}
|
enabled: ${ENABLE_PROVIDER_COLLECT_SPANS:true}
|
||||||
|
long-span-threshold: ${LONG_SPAN_THRESHOLD:1}
|
||||||
main:
|
main:
|
||||||
enabled: ${ENABLE_MAIN_COLLECT_SPANS:false}
|
enabled: ${ENABLE_MAIN_COLLECT_SPANS:false}
|
||||||
@@ -18,7 +18,9 @@ import org.springframework.cloud.sleuth.brave.bridge.BraveTraceContext
|
|||||||
|
|
||||||
class ProviderSpanHandlerTest {
|
class ProviderSpanHandlerTest {
|
||||||
private val mapper = SpanConfig().spanMapper()
|
private val mapper = SpanConfig().spanMapper()
|
||||||
private val spanExportableList = listOf(ErrorSpanExportable(), NoResponseSpanExportable())
|
private val spanExportableList = listOf(
|
||||||
|
ErrorSpanExportable(), NoResponseSpanExportable(), LongResponseSpanExportable(10)
|
||||||
|
)
|
||||||
private val ctx = TraceContext.newBuilder()
|
private val ctx = TraceContext.newBuilder()
|
||||||
.traceId(1223324)
|
.traceId(1223324)
|
||||||
.spanId(234235)
|
.spanId(234235)
|
||||||
@@ -110,6 +112,14 @@ class ProviderSpanHandlerTest {
|
|||||||
id("f7e83f2b69ec111d")
|
id("f7e83f2b69ec111d")
|
||||||
parentId("f7e83f2b69ec682d")
|
parentId("f7e83f2b69ec682d")
|
||||||
tag(SPAN_NO_RESPONSE_MESSAGE, "noResp")
|
tag(SPAN_NO_RESPONSE_MESSAGE, "noResp")
|
||||||
|
},
|
||||||
|
MutableSpan()
|
||||||
|
.apply {
|
||||||
|
traceId("6666632728347823749827349723985")
|
||||||
|
id("f7e83f2b69ec111d")
|
||||||
|
parentId("f7e83f2b69ec682d")
|
||||||
|
startTimestamp(3034272)
|
||||||
|
finishTimestamp(15034272)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user