Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶ added in v0.0.64
FromContext returns the logger associated with ctx, enriched so that the OpenTelemetry log bridge (otellogr) can extract the active trace span.
logr.LogSink.Info/Error have no context.Context parameter, so klog.FromContext(ctx).Info(...) discards the span carried by ctx. Calling WithValues("ctx", ctx) stores the context inside the otellogr sink (via its convertKVs path), which then passes it to Emit — giving the OTel SDK the span context it needs for trace-log correlation.
The context is wrapped in otelCtx so that text loggers that don't strip context values (e.g. in tests without the teeSink) produce a harmless placeholder instead of formatting the full context chain, which could contain sensitive data such as HTTP request headers.
func LogInfo ¶
LogInfo logs msg with the provided attributes on the given logger. Pass a V-leveled logger (e.g. logger.V(4)) to preserve verbosity gating.
func LogWarn ¶
LogWarn logs msg with a log.severity=WARN tag and the provided attributes. This is done because the klog.Logger interface has no native Warn method. Pass a V-leveled logger (e.g. logger.V(1)) to preserve verbosity gating.
func SetOtelLogSinkActive ¶ added in v0.0.64
func SetOtelLogSinkActive(active bool)
SetOtelLogSinkActive records whether the OTel log bridge is active. When false, FromContext skips the WithValues("ctx", …) call, avoiding a per-call allocation and keeping the text log output free of the placeholder.
Types ¶
type Attr ¶
Attr is a single, complete key/value log attribute. Because every constructor returns a complete pair, attributes compose through the variadic logr/klog logging API without the "even number of varargs" footgun: keys and values cannot get out of sync.