Skip to content

Commit daf5ccf

Browse files
authored
logging: Document correct WithFieldsFromContext/WithFieldsFromContextAndCallMeta usage (#703)
Signed-off-by: Chance Zibolski <[email protected]>
1 parent ea545dc commit daf5ccf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

interceptors/logging/options.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ type (
138138
fieldsFromCtxCallMetaFn func(ctx context.Context, c interceptors.CallMeta) Fields
139139
)
140140

141-
// WithFieldsFromContext allows overriding existing or adding extra fields to all log messages per given context
141+
// WithFieldsFromContext allows overriding existing or adding extra fields to all log messages per given context.
142+
// If called multiple times, it overwrites the existing FieldsFromContext/WithFieldsFromContextAndCallMeta function.
143+
// If you need to use multiple FieldsFromContext functions then you should combine them in a wrapper fieldsFromCtxFn.
144+
// Only one of WithFieldsFromContextAndCallMeta or WithFieldsFromContext should
145+
// be used, using both will result in the last one overwriting the previous.
142146
func WithFieldsFromContext(f fieldsFromCtxFn) Option {
143147
return func(o *options) {
144148
o.fieldsFromCtxCallMetaFn = func(ctx context.Context, _ interceptors.CallMeta) Fields {
@@ -148,6 +152,10 @@ func WithFieldsFromContext(f fieldsFromCtxFn) Option {
148152
}
149153

150154
// WithFieldsFromContextAndCallMeta allows overriding existing or adding extra fields to all log messages per given context and interceptor.CallMeta
155+
// If called multiple times, it overwrites the existing FieldsFromContext/WithFieldsFromContextAndCallMeta function.
156+
// If you need to use multiple WithFieldsFromContextAndCallMeta functions then you should combine them in a wrapper fieldsFromCtxCallMetaFn.
157+
// Only one of WithFieldsFromContextAndCallMeta or WithFieldsFromContext should
158+
// be used, using both will result in the last one overwriting the previous.
151159
func WithFieldsFromContextAndCallMeta(f fieldsFromCtxCallMetaFn) Option {
152160
return func(o *options) {
153161
o.fieldsFromCtxCallMetaFn = f

0 commit comments

Comments
 (0)