Skip to content

feat(logging): add node identifier to log lines#894

Merged
alexluong merged 2 commits into
hookdeck:mainfrom
mvanhorn:osc/307-node-id-log-lines
May 5, 2026
Merged

feat(logging): add node identifier to log lines#894
alexluong merged 2 commits into
hookdeck:mainfrom
mvanhorn:osc/307-node-id-log-lines

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented May 2, 2026

Closes #307.

Adds an os.Hostname()-derived node field to every log line so multi-node deployments can be traced from log output alone. Per the issue body, os.Hostname() returns sensible identifiers across the relevant deployment targets:

  • Kubernetes: pod name (e.g. outpost-api-5bbd447f65-x2444)
  • Docker: container ID
  • ECS: task/container ID
  • Cloud VMs: instance hostname

Implementation

The hostname is captured once inside makeLogger and attached as a default zap field via zapLogger.With(zap.String("node", hostname)). Both the main logger and the audit logger pick this up because they share the same construction path. otelzap preserves zap With fields, so Ctx(ctx) derivations also carry the node identifier with no additional wiring.

If os.Hostname() returns an error, the field falls back to "unknown". This matches the silent-fallback pattern in internal/redislock/redislock.go:136 and avoids failing logger construction on observability metadata.

Verification

  • go build ./...: pass
  • go vet ./...: pass
  • go test ./internal/logging/...: pass (no existing test files; the change is structural metadata)

Diff

A single 6-line addition in internal/logging/logger.go. No public surface change.

Closes hookdeck#307.

Adds an `os.Hostname()`-derived `node` field to every log line so multi-node
deployments can be traced from log output alone. Per the issue body,
`os.Hostname()` returns sensible identifiers across the relevant deployment
targets:

- Kubernetes: pod name (e.g. `outpost-api-5bbd447f65-x2444`)
- Docker: container ID
- ECS: task/container ID
- Cloud VMs: instance hostname

The hostname is captured once inside `makeLogger` and attached as a default
zap field via `zapLogger.With(...)`. Both the main logger and the audit
logger pick this up because they share the same construction path. otelzap
preserves zap `With` fields, so `Ctx(ctx)` derivations also carry the node
identifier.

If `os.Hostname()` returns an error, the field falls back to `"unknown"`.
This matches the silent-fallback pattern in `internal/redislock/redislock.go`
and avoids failing logger construction on observability metadata.
@alexbouchardd alexbouchardd requested a review from alexluong May 3, 2026 18:53
Comment thread internal/logging/logger.go Outdated
Per @alexluong's review: the hostname attribute should follow the OTEL
host semantic convention to avoid confusion with k8s node semantics.
Copy link
Copy Markdown
Collaborator

@alexluong alexluong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @mvanhorn for the contribution. Welcome, and please let me know if there's anything I can help with Outpost!

@alexluong alexluong merged commit eed63b0 into hookdeck:main May 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Node Identification to Log Lines

2 participants