Skip to content

Conversation

@dunglas
Copy link
Contributor

@dunglas dunglas commented Nov 8, 2025

With this patch, contextual data can be added to all logs generated by a logger retrieved using context.Slogger().

For instance, this allows FrankenPHP and Mercure to include OpenTelemetry's traceID and spanID to all logs they generate using the logger created by Caddy.

Modules can also register handlers to add contextual data of their own (like the Mercure update ID, for instance).

Assistance Disclosure

No AI was used.

@dunglas dunglas force-pushed the feat/module-slog-handler branch from 6c5c95c to 9ce4728 Compare November 8, 2025 16:17
@dunglas dunglas force-pushed the feat/module-slog-handler branch from 9ce4728 to a62d829 Compare November 8, 2025 16:18
@francislavoie francislavoie added the feature ⚙️ New feature or request label Nov 8, 2025
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks Kevin!

Just so I understand, this doesn't affect MOST of Caddy's logs, i.e. won't noticeably impact their performance or change them -- just the logs that are emitted without zap, right?

Comment on lines +588 to +593
type slogHandlerFactory func(handler slog.Handler, core zapcore.Core, moduleID string) slog.Handler

var (
slogHandlerFactories []slogHandlerFactory
slogHandlerFactoriesMu sync.RWMutex
)
Copy link
Member

Choose a reason for hiding this comment

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

I know this is an annoying request, but how would you feel if we drop the "factory" thing? 😆 I just... it feels like Java.

What about like slogHandlerWrapper instead? Or, maybe even just slogHandler? I am not 100% sure since I haven't dived into slog too much yet to be that familiar with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this is a list of factory to create log/slog.Handler instances when needed (these are "wrapping" the main instance by implementing the decorator pattern). Removing the factory suffix will be confusing IMHO.

@dunglas
Copy link
Contributor Author

dunglas commented Nov 9, 2025

Right.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Alrighty -- sounds good then. Thank you!

@mholt mholt merged commit b3f2db2 into caddyserver:master Nov 12, 2025
25 checks passed
@github-actions github-actions bot mentioned this pull request Dec 3, 2025
4 tasks
@francislavoie francislavoie added this to the v2.11.0 milestone Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature ⚙️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants