Support was added for specifying callables as extra fields. This is super useful if we're trying to attach span_id and trace_id to a log entry in order to cross-match it with a tracing system, such as Jaeger, and we need that data dynamically rather than statically at startup.
Example:
get_context = lambda: tracer.active_span.context
add_trace_id = lambda: hex(get_context().trace_id)[2:] if tracer is not None and tracer.active_span is not None else None
add_span_id = lambda: hex(get_context().span_id)[2:] if tracer is not None and tracer.active_span else None
formatter = LogstashFormatter(extra={'span_id': add_span_id, 'trace_id': add_trace_id})
logging.getLogger().setFormatter(formatter)
Support was added for specifying callables as extra fields. This is super useful if we're trying to attach span_id and trace_id to a log entry in order to cross-match it with a tracing system, such as Jaeger, and we need that data dynamically rather than statically at startup.
Example: