Skip to content

refactor: use constants for component logger names#308

Open
jason-lynch wants to merge 1 commit intomainfrom
refactor/component-logger-constants
Open

refactor: use constants for component logger names#308
jason-lynch wants to merge 1 commit intomainfrom
refactor/component-logger-constants

Conversation

@jason-lynch
Copy link
Copy Markdown
Member

Summary

Switches to using constants for and centralizes all of the component names. This will make it easier to keep the component list in our docs up-to-date.

Testing

The only functional change in this PR is that I added support for configuring the workflows backend log level:

{
  "profiling_enabled": true,
  "client_addresses": ["127.0.0.1"],
  "logging": {
    "component_levels": {
      "workflows_backend": "debug"
    }
  }
}

Otherwise, everything should behave the same as it always has.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2b2103f-b402-43dc-8159-5b988af736b5

📥 Commits

Reviewing files that changed from the base of the PR and between 0eba7c4 and 08cb7d1.

📒 Files selected for processing (13)
  • docs/installation/configuration.md
  • server/internal/api/server.go
  • server/internal/election/candidate.go
  • server/internal/etcd/embedded.go
  • server/internal/etcd/logging.go
  • server/internal/etcd/remote.go
  • server/internal/logging/factory.go
  • server/internal/migrate/migrations/add_task_scope.go
  • server/internal/migrate/runner.go
  • server/internal/ports/service.go
  • server/internal/scheduler/service.go
  • server/internal/workflows/provide.go
  • server/internal/workflows/worker.go
✅ Files skipped from review due to trivial changes (9)
  • server/internal/etcd/embedded.go
  • server/internal/workflows/worker.go
  • server/internal/election/candidate.go
  • server/internal/etcd/remote.go
  • server/internal/etcd/logging.go
  • server/internal/scheduler/service.go
  • server/internal/workflows/provide.go
  • server/internal/api/server.go
  • server/internal/migrate/runner.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • server/internal/migrate/migrations/add_task_scope.go
  • docs/installation/configuration.md
  • server/internal/logging/factory.go

📝 Walkthrough

Walkthrough

Replaces string-based logger component names with a typed Component type and constants in the logging factory; updates logger initializations across the codebase to use those constants. Documentation adds workflows_backend and reorders two entries. Etcd logger now records its component under "etcd_component".

Changes

Cohort / File(s) Summary
Documentation
docs/installation/configuration.md
Added workflows_backend to logging.component_levels list and reordered remote_etcd and ports_service entries.
Logging Factory
server/internal/logging/factory.go
Added type Component string with String() and multiple Component* constants; changed Factory internals to use map[Component]zerolog.Level and Logger(component Component) zerolog.Logger; uses .Stringer("component", component) for context.
Logger initializations
server/internal/api/server.go, server/internal/election/candidate.go, server/internal/etcd/embedded.go, server/internal/etcd/remote.go, server/internal/migrate/migrations/add_task_scope.go, server/internal/migrate/runner.go, server/internal/ports/service.go, server/internal/scheduler/service.go, server/internal/workflows/worker.go
Replaced literal string component names with corresponding logging.Component* constants when obtaining loggers from the factory.
Etcd logging field
server/internal/etcd/logging.go
Changed structured log field key from "component" to "etcd_component" when writing the etcd component into log context.
Workflows provider wiring
server/internal/workflows/provide.go
Switched provider to receive *logging.Factory (instead of zerolog.Logger), derive a component-scoped zerolog logger via loggerFactory.Logger(logging.ComponentWorkflowsBackend), and wrap it with logging.Slog(...) for backend wiring.

Poem

🐇 I hopped from strings to typed delight,
constants glowing, tidy and bright.
Etcd whispers "etcd_component" in tune,
Workflows backend joins our moon.
Logs align, neat rows in sight — hip-hop, hooray tonight! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: refactoring to use constants for component logger names instead of hardcoded strings.
Description check ✅ Passed The PR description includes a clear summary, lists the functional changes (workflows backend log level support), and explains testing approach. All critical sections are covered despite missing some optional template sections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/component-logger-constants

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
server/internal/etcd/logging.go (1)

25-31: Consider: newGrpcLogger still uses "component" field key.

Unlike newZapLogger, this function uses Str("component", "grpc_logger"). Since gRPC logs are set to FatalLevel, this is unlikely to cause issues in practice, but for consistency you might consider renaming to "grpc_component" or similar.

♻️ Optional: Align field key with newZapLogger pattern
 func newGrpcLogger(base zerolog.Logger) *zapgrpc.Logger {
 	core := zerozap.New(base.
 		Level(zerolog.FatalLevel).
 		With().
-		Str("component", "grpc_logger").
+		Str("grpc_component", "grpc_logger").
 		Logger())
 	return zapgrpc.NewLogger(zap.New(core))
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/internal/etcd/logging.go` around lines 25 - 31, Update the field key
in newGrpcLogger so it matches the pattern used by newZapLogger: replace
Str("component", "grpc_logger") with a namespaced key like Str("grpc_component",
"grpc_logger") (or whatever key newZapLogger uses) to keep log field naming
consistent; locate this change inside the newGrpcLogger function where
zerozap.New is constructed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/internal/etcd/logging.go`:
- Around line 25-31: Update the field key in newGrpcLogger so it matches the
pattern used by newZapLogger: replace Str("component", "grpc_logger") with a
namespaced key like Str("grpc_component", "grpc_logger") (or whatever key
newZapLogger uses) to keep log field naming consistent; locate this change
inside the newGrpcLogger function where zerozap.New is constructed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ea4d9ea7-72ce-4531-bbf1-e8052c60d917

📥 Commits

Reviewing files that changed from the base of the PR and between bc20c0b and 0eba7c4.

📒 Files selected for processing (13)
  • docs/installation/configuration.md
  • server/internal/api/server.go
  • server/internal/election/candidate.go
  • server/internal/etcd/embedded.go
  • server/internal/etcd/logging.go
  • server/internal/etcd/remote.go
  • server/internal/logging/factory.go
  • server/internal/migrate/migrations/add_task_scope.go
  • server/internal/migrate/runner.go
  • server/internal/ports/service.go
  • server/internal/scheduler/service.go
  • server/internal/workflows/provide.go
  • server/internal/workflows/worker.go

Switches to using constants for and centralizes all of the component
names. This will make it easier to keep the component list in our docs
up-to-date.
@jason-lynch jason-lynch force-pushed the refactor/component-logger-constants branch from 0eba7c4 to 08cb7d1 Compare March 24, 2026 00:16
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.

1 participant