MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / FromContext

Function FromContext

internal/logging/logr.go:33–49  ·  view source on GitHub ↗

FromContext returns the global Logger or the one stored by a prior call to NewContext.

(ctx context.Context)

Source from the content-addressed store, hash-verified

31// FromContext returns the global Logger or the one stored by a prior call
32// to NewContext.
33func FromContext(ctx context.Context) Logger {
34 log, err := logr.FromContext(ctx)
35 if err != nil {
36 log = global
37 }
38
39 // Add trace context, if any, according to OpenTelemetry recommendations.
40 // - https://github.com/open-telemetry/opentelemetry-specification/blob/v1.39.0/specification/compatibility/logging_trace_context.md
41 if sc := trace.SpanFromContext(ctx).SpanContext(); sc.IsValid() {
42 log = log.WithValues(
43 "span_id", sc.SpanID(),
44 "trace_id", sc.TraceID(),
45 "trace_flags", sc.TraceFlags())
46 }
47
48 return log
49}
50
51// sink implements logr.LogSink using two function pointers.
52type sink struct {

Callers 15

GetQueriesConfigDirFunction · 0.92
ReconcileMethod · 0.92
suite_test.goFile · 0.92
ReconcileMethod · 0.92

Calls 1

WithValuesMethod · 0.80

Tested by 2

TestFromContextFunction · 0.56