emit
Override this method to provide custom logic for emitting one or more key/value pairs for a given metadata value (call safeEmit from logging code to actually emit values).
By default this method simply emits the given value with this key's label, but it can be customized key/value pairs if necessary.
Note that if multiple key/value pairs are emitted, the following best-practice should be followed:
- Key names should be of the form
"<label>.<suffix>". - Suffixes should only contain lower case ASCII letters and underscore (i.e. [a-z_]).
This method is called as part of logs processing and could be invoked a very large number of times in performance critical code. Implementations must be very careful to avoid calling any code which might risk deadlocks, stack overflow, concurrency issues or performance problems. In particular, implementations of this method should be careful to avoid:
- Calling any code which could log using the same
MetadataKeyinstance (unless you implement protection against reentrant calling in this method). - Calling code which might block (e.g. performing file I/O or acquiring locks).
- Allocating non-trivial amounds of memory (e.g. recording values in an unbounded data structure).
If you do implement a MetadataKey with non-trivial value processing, you should always make it very clear in the documentation that the key may not be suitable for widespread use.
By default this method just calls out.handle(getLabel(), value).