Skip to content

Commit a03e707

Browse files
authored
Merge pull request #6429 from IntersectMBO/mkarg/bench-master
New tracing: Support environment variable for logging hostname
2 parents 23bb477 + 6e22b71 commit a03e707

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

nix/workbench/service/nodes.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ let
290290
''
291291
#!${pkgs.stdenv.shell}
292292
293+
export TRACE_DISPATCHER_LOGGING_HOSTNAME=${name}
294+
293295
${service.script}
294296
''
295297
;

trace-dispatcher/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Revision history for trace-dispatcher
22

3-
## 2.11.1 -- Jan 2026
3+
## 2.11.1 -- Feb 2026
44

55
* Add strict `contramap'` (infix alias `>!$!<`) to the API, capturing a common pattern to avoid unintentional space leaks when composing tracers
66
* Increase `PrometheusSimple` robustness by restarting the backend upon crash, adding start/stop traces and more eagerly reaping of dangling sockets
7+
* Setting the `TRACE_DISPATCHER_LOGGING_HOSTNAME` environment variable will override the system hostname in trace messages.
78
* Increased strictness when storing traced `DataPoints`
89
* Drastically reduced fallback value for forwarding queue capacity to minimize impact of forwarding service interruption on heap size and retention
910
* Removed `TraceConfig.tcPeerFrequency` and hence `TraceOptionPeerFrequency` from config representation

trace-dispatcher/src/Cardano/Logging/Formatter.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ import Data.Text.Lazy.Builder as TB
3939
import Data.Text.Lazy.Encoding (decodeUtf8)
4040
import Data.Time (defaultTimeLocale, formatTime, getCurrentTime)
4141
import Network.HostName
42+
import System.Environment (lookupEnv)
4243
import System.IO.Unsafe (unsafePerformIO)
4344

4445

45-
-- If the hostname in the logs should be anything different from the system reported hostname,
46-
-- a new field would need to be added to PreFormatted to carry a new hostname argument to preFormatted.
46+
-- | If the @TRACE_DISPATCHER_LOGGING_HOSTNAME@ environment variable is set,
47+
-- it overrides the system hostname in the trace message. This is useful when
48+
-- multiple instances of a service or application on the same host.
4749
hostname :: Text
4850
{-# NOINLINE hostname #-}
49-
hostname = unsafePerformIO $ T.pack <$> getHostName
51+
hostname = unsafePerformIO $
52+
lookupEnv "TRACE_DISPATCHER_LOGGING_HOSTNAME" >>= maybe hostNameOnly (pure . T.pack)
53+
where
54+
-- disregard FQDNs
55+
hostNameOnly = T.pack . takeWhile (/= '.') <$> getHostName
5056

5157

5258
-- | Format this trace as metrics

0 commit comments

Comments
 (0)