You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling WithValue on a ctx.Context that already has some attached fields, it will affect the parent context as well. For example:
package main
import (
"context""log/slog""os""github.com/PumpkinSeed/slog-context"
)
funcmain() {
slog.SetDefault(slog.New(slogcontext.NewHandler(slog.NewJSONHandler(os.Stdout, nil))))
ctx:=slogcontext.WithValue(context.Background(), "number", 12)
ctx2:=slogcontext.WithValue(ctx, "stringField", "data")
slog.InfoContext(ctx, "log1") // This will contain the stringField field even though it was meant to be added only to ctx2slog.InfoContext(ctx2, "log2")
}
The text was updated successfully, but these errors were encountered:
deansg
added a commit
to deansg/slog-context
that referenced
this issue
May 21, 2024
When calling
WithValue
on actx.Context
that already has some attached fields, it will affect the parent context as well. For example:The text was updated successfully, but these errors were encountered: