Skip to content

version: fix Slog godoc example to compile - #935

Merged
SuperQ merged 3 commits into
prometheus:mainfrom
sueun-dev:docs-fix-slog-example
Nov 10, 2026
Merged

SuperQ merged 3 commits into
prometheus:mainfrom
sueun-dev:docs-fix-slog-example

Conversation

@sueun-dev

@sueun-dev sueun-dev commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

The Example in the godoc for version.Slog() passes promslog.Config{} by value:

logger := promslog.New(promslog.Config{})
logger.Info("Starting Prometheus Server", version.Slog()...)

but promslog.New takes a pointer:

func New(config *Config) *slog.Logger

so the documented snippet does not compile. Building it verbatim fails with:

cannot use promslog.Config{} (value of struct type promslog.Config) as *promslog.Config value in argument to promslog.New

This changes it to &promslog.Config{}, matching the existing call in promslog/slog_test.go.

gofmt, go vet ./version/... and go test ./version/... pass.

The example for Slog() passed promslog.Config{} by value, but
promslog.New takes *Config, so the snippet does not compile. Use
&promslog.Config{} to match the function signature and the existing
call sites (e.g. promslog/slog.go, promslog/slog_test.go).

Add a compiled ExampleSlog so the documented usage stays in sync with
the API.

Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
@roidelapluie
roidelapluie requested a review from SuperQ June 30, 2026 14:37
Comment thread version/example_test.go Outdated
@@ -0,0 +1,26 @@
// Copyright 2024 The Prometheus Authors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2024 The Prometheus Authors
// Copyright The Prometheus Authors

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Minor nit on the new file copyright.

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, I don't see the point of adding the test file. How does it actively enforce the documentation match?

The example only compiles its own copy of the snippet, not the godoc
comment, so it does not keep the two in sync.

Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
@sueun-dev

Copy link
Copy Markdown
Contributor Author

Sorry for the very slow reply. The notification email for this review got buried and I missed it.

You're right, it doesn't. ExampleSlog only compiles its own copy of the snippet, not the comment: with the comment on this branch put back to promslog.New(promslog.Config{}), go test ./version/... still passes. I've removed the file, so the PR is now just the one-line comment fix. On main the documented snippet still fails to build:

cannot use promslog.Config{} (value of struct type promslog.Config) as *promslog.Config value in argument to promslog.New
@SuperQ SuperQ closed this Nov 10, 2026
@SuperQ SuperQ reopened this Nov 10, 2026
@SuperQ
SuperQ merged commit f072bc2 into prometheus:main Nov 10, 2026
8 checks passed
@SuperQ SuperQ mentioned this pull request Nov 11, 2026
SuperQ added a commit that referenced this pull request Nov 12, 2026
What's Changed
* expfmt: add ABNF parser for OpenMetrics 2.0 by @bwplotka in #1016
* build(deps): bump ossf/scorecard-action from 2.4.4 to 2.5.0 by @dependabot[bot] in #1032
* build(deps): bump actions/upload-artifact from 7.0.1 to 7.0.2 by @dependabot[bot] in #1033
* build(deps): bump golang.org/x/net from 0.61.0 to 0.62.0 in the golang-org-x group across 1 directory by @dependabot[bot] in #1030
* expfmt: bump go-abnf to v0.5.5 by @PerryLink in #1029
* config: move Secret into its own package by @mrueg in #1024
* build(deps): bump the codeql group with 4 updates by @dependabot[bot] in #1031
* version: fix Slog godoc example to compile by @sueun-dev in #935
* build(deps): bump go.yaml.in/yaml/v2 from 2.4.4 to 2.4.5 by @dependabot[bot] in #1043
* build(deps): bump golang.org/x/oauth2 from 0.37.0 to 0.38.0 in the golang-org-x group across 1 directory by @dependabot[bot] in #1042
* expfmt: support Prometheus text format 1.0.0 by @ArthurSens in #1035

New Contributors
* @PerryLink made their first contribution in #1029
* @sueun-dev made their first contribution in #935

**Full Changelog**: v0.73.1...v0.74.0

Signed-off-by: SuperQ <superq@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants