MCPcopy
hub / github.com/mudler/LocalAI / InitBackendTracingIfEnabled

Function InitBackendTracingIfEnabled

core/trace/backend_trace.go:82–113  ·  view source on GitHub ↗
(maxItems, maxBodyBytes int)

Source from the content-addressed store, hash-verified

80var backendMaxBodyBytes int
81
82func InitBackendTracingIfEnabled(maxItems, maxBodyBytes int) {
83 backendInitOnce.Do(func() {
84 if maxItems <= 0 {
85 maxItems = 100
86 }
87 backendMu.Lock()
88 backendTraceBuffer = circularbuffer.New[*BackendTrace](maxItems)
89 backendMu.Unlock()
90
91 go func() {
92 for t := range backendLogChan {
93 backendMu.Lock()
94 if backendTraceBuffer != nil {
95 backendTraceBuffer.Enqueue(t)
96 }
97 backendMu.Unlock()
98 }
99 }()
100 })
101
102 // The body cap tracks the LATEST call, not the first: tracing_max_body_bytes
103 // is runtime-mutable via the settings API (ApplyRuntimeSettings), and every
104 // recording path calls this right before RecordBackendTrace with the current
105 // appConfig value. Freezing the cap on first init meant a raised setting let
106 // producers (e.g. trace.AudioSnippet, which reads the live value) embed
107 // payloads that this recorder then stomped with the "<truncated: N bytes>"
108 // marker — corrupting audio_wav_base64 into an unplayable string. maxItems
109 // keeps first-call semantics: resizing the ring buffer would drop entries.
110 backendMu.Lock()
111 backendMaxBodyBytes = maxBodyBytes
112 backendMu.Unlock()
113}
114
115func RecordBackendTrace(t BackendTrace) {
116 backendMu.Lock()

Callers 15

DetectionFunction · 0.92
VoiceEmbedFunction · 0.92
ModelScoreFunction · 0.92
ModelAudioTransformFunction · 0.92
ImageGenerationFunction · 0.92
SoundGenerationFunction · 0.92
ModelLoadTraceObserverFunction · 0.92
recordModelLoadFailureFunction · 0.92
newLiveTraceStateFunction · 0.92
RerankFunction · 0.92
ModelTTSFunction · 0.92
ModelTTSStreamFunction · 0.92

Calls 3

LockMethod · 0.65
UnlockMethod · 0.65
EnqueueMethod · 0.65

Tested by

no test coverage detected