[VOL-3142] Enabled tracing for rw-core and added config parameters
Change-Id: I0c5faa104f35b2af694f32785ec031c5277e3f64
diff --git a/rw_core/config/config.go b/rw_core/config/config.go
index 3d95f33..03abc67 100644
--- a/rw_core/config/config.go
+++ b/rw_core/config/config.go
@@ -50,6 +50,9 @@
defaultLiveProbeInterval = 60 * time.Second
defaultNotLiveProbeInterval = 5 * time.Second // Probe more frequently when not alive
defaultProbeAddress = ":8080"
+ defaultTraceEnabled = false
+ defaultTraceAgentAddress = "127.0.0.1:6831"
+ defaultLogCorrelationEnabled = true
)
// RWCoreFlags represents the set of configurations used by the read-write core service
@@ -79,6 +82,9 @@
LiveProbeInterval time.Duration
NotLiveProbeInterval time.Duration
ProbeAddress string
+ TraceEnabled bool
+ TraceAgentAddress string
+ LogCorrelationEnabled bool
}
// NewRWCoreFlags returns a new RWCore config
@@ -108,6 +114,9 @@
LiveProbeInterval: defaultLiveProbeInterval,
NotLiveProbeInterval: defaultNotLiveProbeInterval,
ProbeAddress: defaultProbeAddress,
+ TraceEnabled: defaultTraceEnabled,
+ TraceAgentAddress: defaultTraceAgentAddress,
+ LogCorrelationEnabled: defaultLogCorrelationEnabled,
}
return &rwCoreFlag
}
@@ -180,5 +189,14 @@
help = fmt.Sprintf("The address on which to listen to answer liveness and readiness probe queries over HTTP.")
flag.StringVar(&(cf.ProbeAddress), "probe_address", defaultProbeAddress, help)
+ help = fmt.Sprintf("Whether to send logs to tracing agent?")
+ flag.BoolVar(&(cf.TraceEnabled), "trace_enabled", defaultTraceEnabled, help)
+
+ help = fmt.Sprintf("The address of tracing agent to which span info should be sent.")
+ flag.StringVar(&(cf.TraceAgentAddress), "trace_agent_address", defaultTraceAgentAddress, help)
+
+ help = fmt.Sprintf("Whether to enrich log statements with fields denoting operation being executed for achieving correlation?")
+ flag.BoolVar(&(cf.LogCorrelationEnabled), "log_correlation_enabled", defaultLogCorrelationEnabled, help)
+
flag.Parse()
}
diff --git a/rw_core/main.go b/rw_core/main.go
index 19de6f0..98d3985 100644
--- a/rw_core/main.go
+++ b/rw_core/main.go
@@ -106,8 +106,6 @@
// Update all loggers to log level specified as input parameter
log.SetAllLogLevel(logLevel)
- //log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel)
-
defer func() {
err := log.CleanUp()
if err != nil {
@@ -143,6 +141,13 @@
// Add the probe to the context to pass to all the services started
probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p)
+ closer, err := log.InitTracingAndLogCorrelation(cf.TraceEnabled, cf.TraceAgentAddress, cf.LogCorrelationEnabled)
+ if err != nil {
+ logger.Warnw(ctx, "unable-to-initialize-tracing-and-log-correlation-module", log.Fields{"error": err})
+ } else {
+ defer closer.Close()
+ }
+
// create and start the core
core := c.NewCore(probeCtx, instanceID, cf)