mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-02-05 13:15:41 +02:00
Fix #5317 According to the [specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/sdk.md#logrecord-limits), there should be a message printed in the SDK's log to indicate to the user that an attribute was discarded due to such a limit. To prevent excessive logging, the message must be printed at most once per `LogRecord` (i.e., not per discarded attribute). This change centralizes the `Record` dropped field writes and calls a global logging function. This will at most log once per any `Record` dropping attributes, meeting the specification requirement. This does not log once per `Record` when an attribute is dropped. To do that we would need to maintain state within the `Record` (i.e. `sync.Mutex` or `sync.Once`). These types cannot be copied, meaning the `Record` would take on this "no copy" requirement. This seems too restrictive and with the permissive specification allowing a single log line, that is the solution added. --------- Co-authored-by: Robert Pająk <pellared@hotmail.com>