in internal/telemetrygen/logs/exporter.go [89:123]
func (e *httpClientExporter) export(logs plog.Logs) error {
scheme := "https"
if e.cfg.Insecure {
scheme = "http"
}
path := e.cfg.HTTPPath
url := fmt.Sprintf("%s://%s%s", scheme, e.cfg.Endpoint(), path)
req := plogotlp.NewExportRequestFromLogs(logs)
body, err := req.MarshalProto()
if err != nil {
return fmt.Errorf("failed to marshal logs to protobuf: %w", err)
}
httpReq, err := http.NewRequestWithContext(context.Background(), "POST", url, bytes.NewReader(body))
if err != nil {
return fmt.Errorf("failed to create logs HTTP request: %w", err)
}
for k, v := range e.cfg.Headers {
httpReq.Header.Set(k, v)
}
httpReq.Header.Set("Content-Type", "application/x-protobuf")
resp, err := e.client.Do(httpReq)
if err != nil {
return fmt.Errorf("failed to execute logs HTTP request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
var respData bytes.Buffer
_, _ = io.Copy(&respData, resp.Body)
return fmt.Errorf("log request failed with status %s (%s)", resp.Status, respData.String())
}
return nil
}