Skip to content

Conversation

@mhamza15
Copy link
Collaborator

@mhamza15 mhamza15 commented Jan 22, 2026

Description

Adds support for JSON structured logging with slog. To enable, pass --log-structured 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 using ast-grep as so:

  • Info(...) => Info(fmt.Sprint(...))
  • Infof(...) => Info(fmt.Sprintf(...))
  • ...and so on for other levels and Depth variants.

Call sites are now free to incrementally add additional attributes to the message.

Example JSON output:

$ ./bin/vttablet --log-structured
{"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 bba55101eeb6be4ce10914eec14daee3008189c7 branch 'structured-logging-slog') built on Thu Jan 22 15:59:46 EST 2026 by [email protected] 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"}

Benchmark quick links:

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

AI Disclosure

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 [email protected] 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 <[email protected]>
@mhamza15 mhamza15 self-assigned this Jan 22, 2026
@github-actions github-actions bot added this to the v24.0.0 milestone Jan 22, 2026
@mhamza15 mhamza15 added Type: Enhancement Logical improvement (somewhere between a bug and feature) Benchmark me Add label to PR to run benchmarks Component: Observability Pull requests that touch tracing/metrics/monitoring labels Jan 22, 2026
@vitess-bot vitess-bot bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 22, 2026
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Jan 22, 2026

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Jan 22, 2026

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.

@mhamza15 mhamza15 removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 22, 2026
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 32.23413% with 822 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.84%. Comparing base (ce8a335) to head (b14f15a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/mysqlctl/mysqld.go 8.97% 71 Missing ⚠️
go/vt/tlstest/tlstest.go 5.40% 70 Missing ⚠️
go/vt/log/log.go 63.04% 34 Missing ⚠️
go/vt/log/prefix.go 0.00% 31 Missing ⚠️
go/cmd/vtbackup/cli/vtbackup.go 0.00% 29 Missing ⚠️
go/mysql/conn.go 21.87% 25 Missing ⚠️
go/stats/statsd/statsd.go 0.00% 21 Missing ⚠️
go/cmd/vtcombo/cli/vschema_watcher.go 0.00% 19 Missing ⚠️
go/vt/binlog/binlogplayer/binlog_player.go 24.00% 19 Missing ⚠️
go/vt/servenv/servenv.go 26.08% 17 Missing ⚠️
... and 151 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19203      +/-   ##
==========================================
- Coverage   69.88%   69.84%   -0.04%     
==========================================
  Files        1611     1613       +2     
  Lines      215944   216158     +214     
==========================================
+ Hits       150919   150985      +66     
- Misses      65025    65173     +148     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

mhamza15 and others added 3 commits January 26, 2026 14:10
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mohamed Hamza <[email protected]>
Co-authored-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Signed-off-by: Mohamed Hamza <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Benchmark me Add label to PR to run benchmarks Component: Observability Pull requests that touch tracing/metrics/monitoring NeedsWebsiteDocsUpdate What it says Type: Enhancement Logical improvement (somewhere between a bug and feature)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant