MCPcopy Create free account
hub / github.com/InferCore/InferCore / flush

Method flush

internal/telemetry/otlp_http_exporter.go:116–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

114}
115
116func (e *OTLPHTTPExporter) flush() {
117 e.mu.Lock()
118 buffers := map[string][]map[string]any{
119 "metrics": append([]map[string]any(nil), e.buffer["metrics"]...),
120 "events": append([]map[string]any(nil), e.buffer["events"]...),
121 "traces": append([]map[string]any(nil), e.buffer["traces"]...),
122 }
123 e.buffer["metrics"] = nil
124 e.buffer["events"] = nil
125 e.buffer["traces"] = nil
126 e.lastFlush = time.Now()
127 e.mu.Unlock()
128
129 for kind, records := range buffers {
130 if len(records) == 0 {
131 continue
132 }
133 endpoint := endpointForKind(e.endpoint, kind)
134 payload := buildPayload(kind, records)
135 if err := e.post(endpoint, payload); err != nil {
136 e.mu.Lock()
137 e.lastError = err.Error()
138 e.mu.Unlock()
139 } else {
140 e.mu.Lock()
141 e.sentBatches++
142 e.sentRecords += len(records)
143 e.lastError = ""
144 e.mu.Unlock()
145 }
146 }
147}
148
149func (e *OTLPHTTPExporter) post(endpoint string, payload map[string]any) error {
150 raw, err := json.Marshal(payload)

Callers 1

enqueueMethod · 0.95

Calls 4

postMethod · 0.95
endpointForKindFunction · 0.85
buildPayloadFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected