ENT-8823: Added copyBaggageToTags configuration option to control if baggage is copied to tags.

Switched SimplLogTelemetryComponent to info logs.
This commit is contained in:
Adel El-Beik 2022-12-08 16:54:38 +00:00
parent 50a1a4ce09
commit 044b83508e
16 changed files with 51 additions and 35 deletions

View File

@ -179,7 +179,9 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
open val simpleLogTelemetryEnabled: Boolean = false,
open val spanStartEndEventsEnabled: Boolean = true
open val spanStartEndEventsEnabled: Boolean = false,
open val copyBaggageToTags: Boolean = false
) {
companion object {
@ -226,7 +228,8 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
deduplicationCacheExpiry,
openTelemetryEnabled,
simpleLogTelemetryEnabled,
spanStartEndEventsEnabled
spanStartEndEventsEnabled,
copyBaggageToTags
)
}
@ -246,7 +249,8 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
deduplicationCacheExpiry: Duration = this.deduplicationCacheExpiry,
openTelemetryEnabled: Boolean = this.openTelemetryEnabled,
simpleLogTelemetryEnabled: Boolean = this.simpleLogTelemetryEnabled,
spanStartEndEventsEnabled: Boolean = this.spanStartEndEventsEnabled
spanStartEndEventsEnabled: Boolean = this.spanStartEndEventsEnabled,
copyBaggageToTags: Boolean = this.copyBaggageToTags
): CordaRPCClientConfiguration {
return CordaRPCClientConfiguration(
connectionMaxRetryInterval,
@ -262,7 +266,8 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
deduplicationCacheExpiry,
openTelemetryEnabled,
simpleLogTelemetryEnabled,
spanStartEndEventsEnabled
spanStartEndEventsEnabled,
copyBaggageToTags
)
}
@ -286,6 +291,7 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
if (openTelemetryEnabled != other.openTelemetryEnabled) return false
if (simpleLogTelemetryEnabled != other.simpleLogTelemetryEnabled) return false
if (spanStartEndEventsEnabled != other.spanStartEndEventsEnabled) return false
if (copyBaggageToTags != other.copyBaggageToTags) return false
return true
}
@ -306,6 +312,7 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
result = 31 * result + openTelemetryEnabled.hashCode()
result = 31 * result + simpleLogTelemetryEnabled.hashCode()
result = 31 * result + spanStartEndEventsEnabled.hashCode()
result = 31 * result + copyBaggageToTags.hashCode()
return result
}
@ -321,7 +328,8 @@ open class CordaRPCClientConfiguration @JvmOverloads constructor(
"deduplicationCacheExpiry=$deduplicationCacheExpiry, " +
"openTelemetryEnabled=$openTelemetryEnabled, " +
"simpleLogTelemetryEnabled=$simpleLogTelemetryEnabled, " +
"spanStartEndEventsEnabled=$spanStartEndEventsEnabled)"
"spanStartEndEventsEnabled=$spanStartEndEventsEnabled, " +
"copyBaggageToTags=$copyBaggageToTags )"
}
// Left in for backwards compatibility with version 3.1

View File

@ -102,7 +102,7 @@ class RPCClient<I : RPCOps>(
val targetString = "${transport.params[TransportConstants.HOST_PROP_NAME]}:${transport.params[TransportConstants.PORT_PROP_NAME]}"
val rpcClientTelemetry = RPCClientTelemetry("rpcClient-$targetString", rpcConfiguration.openTelemetryEnabled,
rpcConfiguration.simpleLogTelemetryEnabled, rpcConfiguration.spanStartEndEventsEnabled)
rpcConfiguration.simpleLogTelemetryEnabled, rpcConfiguration.spanStartEndEventsEnabled, rpcConfiguration.copyBaggageToTags)
val sessionId = Trace.SessionId.newInstance()
val distributionMux = DistributionMux(listeners, username)
val proxyHandler = RPCClientProxyHandler(rpcConfiguration, username, password, serverLocator,

View File

@ -5,7 +5,9 @@ import net.corda.core.internal.telemetry.SimpleLogTelemetryComponent
import net.corda.core.internal.telemetry.TelemetryServiceImpl
import net.corda.core.utilities.contextLogger
class RPCClientTelemetry(val serviceName: String, val openTelemetryEnabled: Boolean, val simpleLogTelemetryEnabled: Boolean, val spanStartEndEventsEnabled: Boolean) {
class RPCClientTelemetry(val serviceName: String, val openTelemetryEnabled: Boolean,
val simpleLogTelemetryEnabled: Boolean, val spanStartEndEventsEnabled: Boolean,
val copyBaggageToTags: Boolean) {
companion object {
private val log = contextLogger()
@ -16,7 +18,7 @@ class RPCClientTelemetry(val serviceName: String, val openTelemetryEnabled: Bool
init {
if (openTelemetryEnabled) {
try {
val openTelemetryComponent = OpenTelemetryComponent(serviceName, spanStartEndEventsEnabled)
val openTelemetryComponent = OpenTelemetryComponent(serviceName, spanStartEndEventsEnabled, copyBaggageToTags)
if (openTelemetryComponent.isEnabled()) {
telemetryService.addTelemetryComponent(openTelemetryComponent)
log.debug("OpenTelemetry enabled")

View File

@ -13,8 +13,8 @@ java8MinUpdateVersion=171
# net.corda.core.internal.CordaUtilsKt.PLATFORM_VERSION as well. #
# ***************************************************************#
platformVersion=12
openTelemetryVersion=1.17.0
openTelemetrySemConvVersion=1.17.0-alpha
openTelemetryVersion=1.20.1
openTelemetrySemConvVersion=1.20.1-alpha
guavaVersion=28.0-jre
# Quasar version to use with Java 8:
quasarVersion=0.7.15_r3

View File

@ -53,7 +53,7 @@ class TracerSetup(serviceName: String) {
}
@Suppress("TooManyFunctions")
class OpenTelemetryComponent(val serviceName: String, val spanStartEndEventsEnabled: Boolean) : TelemetryComponent {
class OpenTelemetryComponent(val serviceName: String, val spanStartEndEventsEnabled: Boolean, val copyBaggageToTags: Boolean) : TelemetryComponent {
val tracerSetup = TracerSetup(serviceName)
val tracer: Tracer = tracerSetup.getTracer()
@ -118,8 +118,14 @@ class OpenTelemetryComponent(val serviceName: String, val spanStartEndEventsEnab
it
} ?: emptyMap()
// Also add any baggage to the span
val attributesMap = (attributes+baggageAttributes).toList()
val allAttributes = if (copyBaggageToTags) {
attributes + baggageAttributes
}
else {
attributes
}
val attributesMap = allAttributes.toList()
.fold(Attributes.builder()) { builder, attribute -> builder.put(attribute.first, attribute.second) }.also {
populateWithFlowAttributes(it, flowLogic)
}.build()
@ -212,7 +218,9 @@ class OpenTelemetryComponent(val serviceName: String, val spanStartEndEventsEnab
private fun startSpan(name: String, attributes: Map<String, String>, telemetryId: UUID, flowLogic: FlowLogic<*>?) {
val currentBaggage = Baggage.current()
val baggageAttributes = mutableMapOf<String,String>()
currentBaggage.forEach { t, u -> baggageAttributes[t] = u.value }
if (copyBaggageToTags) {
currentBaggage.forEach { t, u -> baggageAttributes[t] = u.value }
}
val parentSpan = Span.current()
val attributesMap = (attributes+baggageAttributes).toList().fold(Attributes.builder()) { builder, attribute -> builder.put(attribute.first, attribute.second) }.also {
populateWithFlowAttributes(it, flowLogic)

View File

@ -57,13 +57,13 @@ class SimpleLogTelemetryComponent : TelemetryComponent {
logContexts[traceId] = SimpleLogContext(traceId, baggageAttributes)
clientId?.let { MDC.put(CLIENT_ID, it) }
MDC.put(TRACE_ID, traceId.toString())
log.debug {"startSpanForFlow: name: $name, traceId: $traceId, flowId: $flowId, clientId: $clientId, attributes: ${attributes+baggageAttributes}"}
log.info("startSpanForFlow: name: $name, traceId: $traceId, flowId: $flowId, clientId: $clientId, attributes: ${attributes+baggageAttributes}")
}
// Check when you start a top level flow the startSpanForFlow appears just once, and so the endSpanForFlow also appears just once
// So its valid to do the MDC clear here. For remotes nodes as well
private fun endSpanForFlow(telemetryId: UUID) {
log.debug {"endSpanForFlow: traceId: ${traces.get()}"}
log.info("endSpanForFlow: traceId: ${traces.get()}")
logContexts.remove(telemetryId)
MDC.clear()
}
@ -73,12 +73,12 @@ class SimpleLogTelemetryComponent : TelemetryComponent {
val flowId = flowLogic?.runId
val clientId = flowLogic?.stateMachine?.clientId
val traceId = traces.get()
log.debug {"startSpan: name: $name, traceId: $traceId, flowId: $flowId, clientId: $clientId, attributes: $attributes"}
log.info("startSpan: name: $name, traceId: $traceId, flowId: $flowId, clientId: $clientId, attributes: $attributes")
}
@Suppress("UNUSED_PARAMETER")
private fun endSpan(telemetryId: UUID) {
log.debug {"endSpan: traceId: ${traces.get()}"}
log.info("endSpan: traceId: ${traces.get()}")
}
override fun getCurrentTelemetryData(): SimpleLogContext {
@ -119,7 +119,7 @@ class SimpleLogTelemetryComponent : TelemetryComponent {
private fun setStatus(telemetryId: UUID, telemetryStatusCode: TelemetryStatusCode, message: String) {
when(telemetryStatusCode) {
TelemetryStatusCode.ERROR -> log.error("setStatus: traceId: ${traces.get()}, statusCode: ${telemetryStatusCode}, message: message")
TelemetryStatusCode.OK, TelemetryStatusCode.UNSET -> log.debug {"setStatus: traceId: ${traces.get()}, statusCode: ${telemetryStatusCode}, message: message" }
TelemetryStatusCode.OK, TelemetryStatusCode.UNSET -> log.info("setStatus: traceId: ${traces.get()}, statusCode: ${telemetryStatusCode}, message: message")
}
}

View File

@ -256,7 +256,7 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
}
val cordappLoader: CordappLoader = makeCordappLoader(configuration, versionInfo).closeOnStop(false)
val telemetryService: TelemetryServiceImpl = TelemetryServiceImpl().also {
val openTelemetryComponent = OpenTelemetryComponent(configuration.myLegalName.toString(), configuration.telemetry.spanStartEndEventsEnabled)
val openTelemetryComponent = OpenTelemetryComponent(configuration.myLegalName.toString(), configuration.telemetry.spanStartEndEventsEnabled, configuration.telemetry.copyBaggageToTags)
if (configuration.telemetry.openTelemetryEnabled && openTelemetryComponent.isEnabled()) {
it.addTelemetryComponent(openTelemetryComponent)
}

View File

@ -224,7 +224,8 @@ data class FlowTimeoutConfiguration(
data class TelemetryConfiguration(
val openTelemetryEnabled: Boolean,
val simpleLogTelemetryEnabled: Boolean,
val spanStartEndEventsEnabled: Boolean
val spanStartEndEventsEnabled: Boolean,
val copyBaggageToTags: Boolean
)
internal typealias Valid<TARGET> = Validated<TARGET, Configuration.Validation.Error>

View File

@ -134,7 +134,7 @@ data class NodeConfigurationImpl(
fun database(devMode: Boolean) = DatabaseConfig(
exportHibernateJMXStatistics = devMode
)
val telemetry = TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = true)
val telemetry = TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = false, copyBaggageToTags = false)
}
companion object {

View File

@ -229,10 +229,11 @@ internal object TelemetryConfigurationSpec : Configuration.Specification<Telemet
private val openTelemetryEnabled by boolean()
private val simpleLogTelemetryEnabled by boolean()
private val spanStartEndEventsEnabled by boolean()
private val copyBaggageToTags by boolean()
override fun parseValid(configuration: Config, options: Configuration.Options): Valid<TelemetryConfiguration> {
val config = configuration.withOptions(options)
return valid(TelemetryConfiguration(config[openTelemetryEnabled], config[simpleLogTelemetryEnabled], config[spanStartEndEventsEnabled]))
return valid(TelemetryConfiguration(config[openTelemetryEnabled], config[simpleLogTelemetryEnabled], config[spanStartEndEventsEnabled], config[copyBaggageToTags]))
}
}

View File

@ -28,5 +28,6 @@ verifierType = InMemory
telemetry {
openTelemetryEnabled = true,
simpleLogTelemetryEnabled = false,
spanStartEndEventsEnabled = true
spanStartEndEventsEnabled = false,
copyBaggageToTags = false
}

View File

@ -196,7 +196,7 @@ class NodeTest {
rpcUsers = emptyList(),
verifierType = VerifierType.InMemory,
flowTimeout = FlowTimeoutConfiguration(timeout = Duration.ZERO, backoffBase = 1.0, maxRestartCount = 1),
telemetry = TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = true),
telemetry = TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = false, copyBaggageToTags = false),
rpcSettings = NodeRpcSettings(address = fakeAddress, adminAddress = null, ssl = null),
messagingServerAddress = null,
notary = null,

View File

@ -397,7 +397,7 @@ class NodeConfigurationImplTest {
p2pAddress = NetworkHostAndPort("localhost", 0),
messagingServerAddress = null,
flowTimeout = FlowTimeoutConfiguration(5.seconds, 3, 1.0),
telemetry = TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = true),
telemetry = TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = false, copyBaggageToTags = false),
notary = null,
devMode = true,
noLocalShell = false,

View File

@ -1,11 +1,8 @@
import static org.gradle.api.JavaVersion.VERSION_1_8
plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id 'org.jetbrains.kotlin.jvm' // version '1.6.21'
// Apply the java-library plugin for API and implementation separation.
id 'org.jetbrains.kotlin.jvm'
id 'java-library'
//id 'com.github.johnrengelman.shadow' // version '7.1.2'
id 'net.corda.plugins.publish-utils'
}

View File

@ -1,11 +1,9 @@
import static org.gradle.api.JavaVersion.VERSION_1_8
plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id 'org.jetbrains.kotlin.jvm' // version '1.6.21'
// Apply the java-library plugin for API and implementation separation.
id 'org.jetbrains.kotlin.jvm'
id 'java-library'
id 'com.github.johnrengelman.shadow' // version '7.1.2'
id 'com.github.johnrengelman.shadow'
id 'net.corda.plugins.publish-utils'
}

View File

@ -492,7 +492,7 @@ open class InternalMockNetwork(cordappPackages: List<String> = emptyList(),
doReturn(emptyList<SecureHash>()).whenever(it).extraNetworkMapKeys
doReturn(listOf(baseDirectory / "cordapps")).whenever(it).cordappDirectories
doReturn(emptyList<String>()).whenever(it).quasarExcludePackages
doReturn(TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = true)).whenever(it).telemetry
doReturn(TelemetryConfiguration(openTelemetryEnabled = true, simpleLogTelemetryEnabled = false, spanStartEndEventsEnabled = false, copyBaggageToTags = false)).whenever(it).telemetry
parameters.configOverrides(it)
}