Skip to content

Commit

Permalink
logging: Document correct WithFieldsFromContext/WithFieldsFromContext…
Browse files Browse the repository at this point in the history
…AndCallMeta usage (#703)

Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
  • Loading branch information
chancez authored Apr 8, 2024
1 parent ea545dc commit daf5ccf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion interceptors/logging/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ type (
fieldsFromCtxCallMetaFn func(ctx context.Context, c interceptors.CallMeta) Fields
)

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

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

0 comments on commit daf5ccf

Please sign in to comment.