Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace-dispatcher: seperate routing of metrics #3876

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions trace-dispatcher/src/Cardano/Logging/DocuGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ docIt :: MonadIO m
=> BackendConfig
-> (LoggingContext, Either TraceControl a)
-> m ()
docIt EKGBackend (LoggingContext{},
Left (Document idx mdText mdMetrics (DocCollector docRef))) = do
liftIO $ modifyIORef docRef (\ docMap ->
Map.insert
idx
((\e -> e { ldBackends = EKGBackend : ldBackends e
})
(case Map.lookup idx docMap of
Just e -> e
Nothing -> seq mdText (seq mdMetrics (emptyLogDoc mdText mdMetrics))))
docMap)
docIt backend (LoggingContext {..},
Left (Document idx mdText mdMetrics (DocCollector docRef))) = do
liftIO $ modifyIORef docRef (\ docMap ->
Expand Down
4 changes: 2 additions & 2 deletions trace-dispatcher/src/Cardano/Logging/Formatter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ forwardFormatter application (Trace tr) = do
T.traceWith tr ( nlc
, Right (FormattedForwarder to))
(lc, Left ctrl) -> do
T.traceWith tr ( lc
, Left ctrl)
T.traceWith tr (lc { lcNamespace = application : lcNamespace lc}
, Left ctrl)

-- | Format this trace for human readability
-- The boolean value tells, if this representation is for the console and should be colored
Expand Down
28 changes: 15 additions & 13 deletions trace-dispatcher/src/Cardano/Logging/Tracer/Composed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ mkCardanoTracer' :: forall evt evt1.
-> IO (Trace IO evt)
mkCardanoTracer' trStdout trForward mbTrEkg name namesFor severityFor privacyFor
hook = do
tr <- withBackendsFromConfig backendsAndFormat
tr' <- withLimitersFromConfig (NT.contramap Message tr) (NT.contramap Limit tr)
tr'' <- hook tr'
addContextAndFilter tr''
messageTrace <- withBackendsFromConfig backendsAndFormat
messageTrace' <- withLimitersFromConfig
(NT.contramap Message messageTrace)
(NT.contramap Limit messageTrace)
messageTrace'' <- hook messageTrace'
messageTrace''' <- addContextAndFilter messageTrace''
let metricsTrace = case mbTrEkg of
Nothing -> Trace NT.nullTracer
Just ekgTrace -> metricsFormatter "Cardano" ekgTrace
let metricsTrace' = filterTrace (\(_,v) -> asMetrics v /= []) metricsTrace
metricsTrace'' <- hook metricsTrace'
pure $ messageTrace''' <> metricsTrace''

where
addContextAndFilter :: Trace IO evt -> IO (Trace IO evt)
addContextAndFilter tr = do
Expand All @@ -102,13 +111,6 @@ mkCardanoTracer' trStdout trForward mbTrEkg name namesFor severityFor privacyFor
[EKGBackend, Forwarder, Stdout HumanFormatColoured]
mbBackends
in do
mbEkgTrace <- case mbTrEkg of
Nothing -> pure Nothing
Just ekgTrace ->
if EKGBackend `elem` backends'
then pure $ Just
(metricsFormatter "Cardano" ekgTrace)
else pure Nothing
mbForwardTrace <- if Forwarder `elem` backends'
then fmap (Just . filterTraceByPrivacy (Just Public))
(forwardFormatter "Cardano" trForward)
Expand All @@ -123,9 +125,9 @@ mkCardanoTracer' trStdout trForward mbTrEkg name namesFor severityFor privacyFor
then fmap Just
(machineFormatter "Cardano" trStdout)
else pure Nothing
case mbEkgTrace <> mbForwardTrace <> mbStdoutTrace of
case mbForwardTrace <> mbStdoutTrace of
Nothing -> pure $ Trace NT.nullTracer
Just tr -> pure (preFormatted backends' tr)
Just tr -> pure $ preFormatted backends' tr

-- A simple dataPointTracer which supports building a namespace.
mkDataPointTracer :: forall dp. ToJSON dp
Expand Down