{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE ImportQualifiedPost #-}
module Cardano.Node.Tracing
  ( Tracers (..)
  ) where

import Prelude (IO)

import Codec.CBOR.Read (DeserialiseFailure)
import "contra-tracer" Control.Tracer (Tracer)

import Ouroboros.Consensus.Network.NodeToClient qualified as NodeToClient
import Ouroboros.Consensus.Network.NodeToNode   qualified as NodeToNode
import Ouroboros.Consensus.Node.Tracers         qualified as Consensus
import Ouroboros.Consensus.Storage.ChainDB      qualified as ChainDB
import Ouroboros.Network.Diffusion              qualified as Diffusion

import Ouroboros.Network.NodeToNode   (NodeToNodeVersion, RemoteAddress)
import Ouroboros.Network.NodeToClient (LocalAddress, NodeToClientVersion)

import Cardano.Node.Handlers.Shutdown (ShutdownTrace)
import Cardano.Node.Startup           (NodeInfo, StartupTrace)

import Cardano.Logging.Resources
import Cardano.Node.Tracing.StateRep (NodeState)
import Cardano.Node.Tracing.Tracers.Peer (PeerT)

data Tracers peer localPeer blk p2p = Tracers
  { -- | Trace the ChainDB
    Tracers peer localPeer blk p2p -> Tracer IO (TraceEvent blk)
chainDBTracer         :: Tracer IO (ChainDB.TraceEvent blk)
    -- | Consensus-specific tracers.
  , Tracers peer localPeer blk p2p -> Tracers IO peer localPeer blk
consensusTracers      :: Consensus.Tracers IO peer localPeer blk
    -- | Tracers for the node-to-node protocols.
  , Tracers peer localPeer blk p2p
-> Tracers IO peer blk DeserialiseFailure
nodeToNodeTracers     :: NodeToNode.Tracers IO peer blk DeserialiseFailure
    --, serialisedBlockTracer :: NodeToNode.SerialisedTracer IO peer blk (SerialisedBlockTrace)
    -- | Tracers for the node-to-client protocols
  , Tracers peer localPeer blk p2p
-> Tracers IO localPeer blk DeserialiseFailure
nodeToClientTracers   :: NodeToClient.Tracers IO localPeer blk DeserialiseFailure
    -- | Diffusion tracers
  , Tracers peer localPeer blk p2p
-> Tracers
     RemoteAddress NodeToNodeVersion LocalAddress NodeToClientVersion IO
diffusionTracers      :: Diffusion.Tracers RemoteAddress NodeToNodeVersion
                                               LocalAddress  NodeToClientVersion
                                              IO
  , Tracers peer localPeer blk p2p -> ExtraTracers p2p
diffusionTracersExtra :: Diffusion.ExtraTracers p2p

  , Tracers peer localPeer blk p2p -> Tracer IO (StartupTrace blk)
startupTracer         :: Tracer IO (StartupTrace blk)
  , Tracers peer localPeer blk p2p -> Tracer IO ShutdownTrace
shutdownTracer        :: Tracer IO ShutdownTrace
  , Tracers peer localPeer blk p2p -> Tracer IO NodeInfo
nodeInfoTracer        :: Tracer IO NodeInfo
  , Tracers peer localPeer blk p2p -> Tracer IO NodeState
nodeStateTracer       :: Tracer IO NodeState
  , Tracers peer localPeer blk p2p -> Tracer IO ResourceStats
resourcesTracer       :: Tracer IO ResourceStats
  , Tracers peer localPeer blk p2p -> Tracer IO [PeerT blk]
peersTracer           :: Tracer IO [PeerT blk]
  }