diff --git a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs index fc68aed5fe2..338743df842 100644 --- a/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs +++ b/cardano-node/src/Cardano/Tracing/ToObjectOrphans.hs @@ -31,7 +31,7 @@ import Cardano.BM.Data.LogItem (LOContent (..), LogObject (..), import Cardano.BM.Tracing import Cardano.BM.Data.Tracer (trStructured, emptyObject, mkObject) -import Ouroboros.Consensus.Block (SupportedBlock, headerPoint) +import Ouroboros.Consensus.Block (Header, SupportedBlock, headerPoint) import Ouroboros.Consensus.BlockFetchServer (TraceBlockFetchServerEvent) import Ouroboros.Consensus.ChainSyncClient @@ -218,6 +218,34 @@ instance DefinePrivacyAnnotation (WithTip blk (ChainDB.TraceEvent blk)) instance DefineSeverity (WithTip blk (ChainDB.TraceEvent blk)) where defineSeverity (WithTip _tip ev) = defineSeverity ev +defaultTextTransformer + :: ( MonadIO m + , DefinePrivacyAnnotation b + , DefineSeverity b + , Show b + , ToObject b) + => TracingFormatting + -> TracingVerbosity + -> Trace m Text + -> Tracer m b +defaultTextTransformer TextualRepresentation _verb tr = + Tracer $ \s -> + traceWith tr =<< + LogObject + <$> pure mempty + <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) + <*> pure (LogMessage $ pack $ show s) +defaultTextTransformer _ verb tr = + trStructured verb tr + +instance ( DefinePrivacyAnnotation (ChainDB.TraceAddBlockEvent blk) + , DefineSeverity (ChainDB.TraceAddBlockEvent blk) + , ProtocolLedgerView blk + , Show (Ouroboros.Consensus.Block.Header blk) + , ToObject (ChainDB.TraceAddBlockEvent blk)) + => Transformable Text IO (ChainDB.TraceAddBlockEvent blk) where + trTransformer = defaultTextTransformer + instance DefineSeverity (ChainDB.TraceEvent blk) where defineSeverity (ChainDB.TraceAddBlockEvent ev) = case ev of ChainDB.IgnoreBlockOlderThanK {} -> Info @@ -369,31 +397,26 @@ instance Show peer => Transformable Text IO (TraceLabelPeer peer instance (Show peer, Show txid, Show tx) => Transformable Text IO (TraceLabelPeer peer (TraceSendRecv (TxSubmission txid tx))) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @BlockFetchServerEvent@ instance Transformable Text IO (TraceBlockFetchServerEvent blk) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (TraceTxSubmissionInbound (GenTxId blk) (GenTx blk)) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (TraceTxSubmissionOutbound (GenTxId blk) (GenTx blk)) where - trTransformer _ verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (TraceLocalTxSubmissionServerEvent blk) where trTransformer _ verb tr = trStructured verb tr instance (Condense (HeaderHash blk), Show (TxId tx), HasTxId tx, Show blk, Show tx, ProtocolLedgerView blk) => Transformable Text IO (TraceForgeEvent blk tx) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance (Show (GenTx blk), Show (GenTxId blk)) => Transformable Text IO (TraceEventMempool blk) where @@ -401,49 +424,24 @@ instance (Show (GenTx blk), Show (GenTxId blk)) -- transform @SubscriptionTrace@ instance Transformable Text IO (WithIPList (SubscriptionTrace Socket.SockAddr)) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer instance Transformable Text IO (WithDomainName (SubscriptionTrace Socket.SockAddr)) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @DnsTrace@ instance Transformable Text IO (WithDomainName DnsTrace) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @ErrorPolicyTrace@ instance Transformable Text IO (WithAddr Socket.SockAddr ErrorPolicyTrace) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @MuxTrace@ instance (Show peer) => Transformable Text IO (WithMuxBearer peer MuxTrace) where - trTransformer StructuredLogging verb tr = trStructured verb tr - trTransformer TextualRepresentation _verb tr = Tracer $ \s -> - traceWith tr =<< LogObject <$> pure mempty - <*> mkLOMeta (defineSeverity s) (definePrivacyAnnotation s) - <*> pure (LogMessage $ pack $ show s) - trTransformer UserdefinedFormatting verb tr = trStructured verb tr + trTransformer = defaultTextTransformer -- transform @TraceEvent@ instance (Condense (HeaderHash blk), ProtocolLedgerView blk) @@ -457,6 +455,7 @@ instance (Condense (HeaderHash blk), ProtocolLedgerView blk) <*> pure (LogMessage $ pack s) -- user defined formatting of log output trTransformer UserdefinedFormatting verb tr = trStructured verb tr + -- trTransformer _ verb tr = trStructured verb tr -- | tracer transformer to text messages for TraceEvents -- Converts the trace events from the ChainDB that we're interested in into diff --git a/cardano-node/src/Cardano/Tracing/Tracers.hs b/cardano-node/src/Cardano/Tracing/Tracers.hs index 7bb62405415..a1e421dfcec 100644 --- a/cardano-node/src/Cardano/Tracing/Tracers.hs +++ b/cardano-node/src/Cardano/Tracing/Tracers.hs @@ -190,8 +190,9 @@ mkTracers traceOptions tracer = do { chainDBTracer = tracerOnOff (traceChainDB traceOptions) $ annotateSeverity - $ teeTraceChainTip StructuredLogging tracingVerbosity elided - $ addName "ChainDB" tracer + $ teeTraceChainTip tracingVerbosity elided + $ addName "ChainDB" + $ tracer , consensusTracers = mkConsensusTracers forgeTracers traceOptions , protocolTracers @@ -230,14 +231,14 @@ mkTracers traceOptions tracer = do tracingVerbosity :: TracingVerbosity tracingVerbosity = traceVerbosity traceOptions - teeTraceChainTip :: TracingFormatting - -> TracingVerbosity + teeTraceChainTip :: TracingVerbosity -> MVar (Maybe (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))), Int) -> Tracer IO (LogObject Text) -> Tracer IO (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))) - teeTraceChainTip tform tverb elided tr = Tracer $ \ev -> do + teeTraceChainTip tverb elided tr = Tracer $ \ev -> do traceWith (teeTraceChainTip' tr) ev - traceWith (teeTraceChainTipElide tform tverb elided tr) ev + traceWith (teeTraceChainTipElide StructuredLogging tverb elided tr) ev + traceWith (teeTraceChainTipElide TextualRepresentation tverb elided (addName "text" tr)) ev teeTraceChainTipElide :: TracingFormatting -> TracingVerbosity -> MVar (Maybe (WithSeverity (WithTip blk (ChainDB.TraceEvent blk))), Int) @@ -314,12 +315,12 @@ mkTracers traceOptions tracer = do mempoolTracer = Tracer $ \ev -> do traceWith (mempoolMetricsTraceTransformer tracer) ev traceWith (measureTxsStart tracer) ev - traceWith mpTracer ev + let tr = addName "Mempool" tracer + traceWith (mpTracer StructuredLogging tr) ev + traceWith (mpTracer TextualRepresentation (addName "text" tr)) ev where - mpTracer :: Tracer IO (TraceEventMempool blk) - mpTracer = annotateSeverity - $ toLogObject' StructuredLogging tracingVerbosity - $ addName "Mempool" tracer + mpTracer :: TracingFormatting -> Tracer IO (LogObject Text) -> Tracer IO (TraceEventMempool blk) + mpTracer fmt tr = annotateSeverity $ toLogObject' fmt tracingVerbosity tr forgeTracer :: ForgeTracers @@ -334,16 +335,15 @@ mkTracers traceOptions tracer = do -- The consensus tracer. consensusForgeTracer = tracerOnOff (traceForge traceOpts) $ annotateSeverity - $ teeForge forgeTracers StructuredLogging tracingVerbosity + $ teeForge forgeTracers tracingVerbosity $ addName "Forge" tracer teeForge :: ForgeTracers - -> TracingFormatting -> TracingVerbosity -> Trace IO Text -> Tracer IO (WithSeverity (Consensus.TraceForgeEvent blk (GenTx blk))) - teeForge ft tform tverb tr = Tracer $ \ev -> do + teeForge ft tverb tr = Tracer $ \ev -> do traceWith (teeForge' tr) ev flip traceWith ev $ fanning $ \(WithSeverity _ e) -> case e of @@ -359,7 +359,8 @@ mkTracers traceOptions tracer = do Consensus.TraceSlotIsImmutable{} -> teeForge' (ftTraceSlotIsImmutable ft) Consensus.TraceNodeIsLeader{} -> teeForge' (ftTraceNodeIsLeader ft) - traceWith (toLogObject' tform tverb tr) ev + traceWith (toLogObject' StructuredLogging tverb tr) ev + traceWith (toLogObject' TextualRepresentation tverb (addName "text" tr)) ev teeForge' :: Trace IO Text diff --git a/configuration/log-configuration.yaml b/configuration/log-configuration.yaml index 77df740877d..23ab96940fa 100644 --- a/configuration/log-configuration.yaml +++ b/configuration/log-configuration.yaml @@ -27,17 +27,22 @@ setupScribes: scName: stdout scFormat: ScText scRotation: null + # for output to 'journald' add this scribe: + # - scKind: JournalSK + # scName: "cardano" + # scFormat: ScText # if not indicated otherwise, then log output is directed to this: defaultScribes: - - StdoutSK - stdout -# for output to 'journald' add this scribe: -# - - JournalSK -# - cardano # more options which can be passed as key-value pairs: options: + # for output to 'journald', map these TextualRepresentation traces: + # mapScribes: + # cardano.node.text: + # - JournalSK::cardano mapSubtrace: benchmark: contents: