()
| 114 | } |
| 115 | |
| 116 | func (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 | |
| 149 | func (e *OTLPHTTPExporter) post(endpoint string, payload map[string]any) error { |
| 150 | raw, err := json.Marshal(payload) |
no test coverage detected