grpc-ecosystem / go-grpc-middleware

Golang gRPC Middlewares: interceptor chaining, auth, logging, retries and more.
Apache License 2.0
6.29k stars 693 forks source link

logging: Document correct WithFieldsFromContext/WithFieldsFromContextAndCallMeta usage #703

Closed chancez closed 6 months ago

chancez commented 6 months ago

Changes

Updates the doc string for logging.WithFieldsFromContext and logging.WithFieldsFromContextAndCallMeta. I mistakenly thought these accumulated, so when I tried using one helper for logging some SQL query metadata and the traceID, only the traceID was getting logged since it overwrote my previous field extractor func. Without reading the source, it's not entirely obvious this is the behavior. Additionally, WithFieldsFromContext and WithFieldsFromContextAndCallMeta are mutually exclusive, so it should be documented only one should be used, and what happens when you use both, or either one of them more than once.