Draft
Conversation
Adds support for structured logging with `slog`. To enable, pass
`--log-level json|logfmt` and optionally a `--log-level
debug|info|warn|error` (default info). `glog` is still the default
unless `slog` is explicitly enabled with the flags.
We still use a global logging package `go/vt/log` to make the migration
easier. In the future, each component should be passed in a logger.
The global functions in the log package now check if structured logging
is enabled. If so, passes the message to `slog`. If not, passes it to
`glog` as normal.
Call sites were migrated as so:
- `Info(...)` => `Info(fmt.Sprint(...))`
- `Infof(...)` => `Info(fmt.Sprintf(...))`
- ...and so on for other levels and `Depth` variants.
Example output:
```console
$ ./bin/vttablet
{"time":"2026-01-22T16:13:49.136782-05:00","level":"INFO","source":{"function":"vitess.io/vitess/go/vt/servenv.Init","file":"vitess.io/vitess/go/vt/servenv/servenv_unix.go","line":58},"msg":"Version: 24.0.0-SNAPSHOT (Git revision bba5510 branch 'structured-logging-slog') built on Thu Jan 22 15:59:46 EST 2026 by mhamza@mhamza-psc.local using go1.25.6 darwin/arm64"}
{"time":"2026-01-22T16:13:49.136913-05:00","level":"ERROR","source":{"function":"vitess.io/vitess/go/vt/topo.Open","file":"vitess.io/vitess/go/vt/topo/server.go","line":261},"msg":"topo-global-server-address must be configured"}
```
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Contributor
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Contributor
|
Hello! 👋 This Pull Request is now handled by arewefastyet. The current HEAD and future commits will be benchmarked. You can find the performance comparison on the arewefastyet website. |
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #19203 +/- ##
==========================================
- Coverage 69.97% 69.91% -0.07%
==========================================
Files 1610 1612 +2
Lines 215929 216143 +214
==========================================
+ Hits 151107 151125 +18
- Misses 64822 65018 +196 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Mohamed Hamza <mhamza@fastmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mohamed Hamza <mhamza@fastmail.com> Co-authored-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
Signed-off-by: Mohamed Hamza <mhamza@fastmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for JSON structured logging with
slog. To enable, pass--log-structuredand optionally a--log-level debug|info|warn|error(default info).glogis still the default unlessslogis explicitly enabled with the flags.We still use a global logging package
go/vt/logto make the migration easier. In the future, each component should be passed in a logger.The global functions in the log package now check if structured logging is enabled. If so, passes the message to
slog. If not, passes it toglogas normal.Call sites were migrated using ast-grep as so:
Info(...)=>Info(fmt.Sprint(...))Infof(...)=>Info(fmt.Sprintf(...))Depthvariants.Call sites are now free to incrementally add additional attributes to the message.
Example JSON output:
Benchmark quick links:
Related Issue(s)
Checklist
Deployment Notes
AI Disclosure