fixes
This commit is contained in:
1 parent
f30adf05af
commit
8824af8699
29 files changed
+1201
-115
No files matched your search
@@ -175,6 +175,8 @@ func (c *Collector) HandleLogs(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
stampFrontendClient(logs, r)
|
||||
|
||||
if err := c.ConsumeLogs(context.Background(), logs); err != nil {
|
||||
log.Printf("failed to consume logs: %v", err)
|
||||
http.Error(w, "failed to consume logs", http.StatusInternalServerError)
|
||||
@@ -990,3 +992,31 @@ func (c *Collector) HandleNeedleClassify(w http.ResponseWriter, r *http.Request)
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
_, _ = io.Copy(w, resp.Body)
|
||||
}
|
||||
|
||||
// stampFrontendClient fills in client.address and user_agent.original on
|
||||
// browser-originated log records (source=frontend) from the ingest request,
|
||||
// since the browser cannot know its own public IP. Values the SDK already
|
||||
// sent are kept, and backend services are left alone.
|
||||
func stampFrontendClient(logs plog.Logs, r *http.Request) {
|
||||
ip := strings.TrimSpace(clientIP(r))
|
||||
ua := r.Header.Get("User-Agent")
|
||||
rls := logs.ResourceLogs()
|
||||
for i := 0; i < rls.Len(); i++ {
|
||||
sls := rls.At(i).ScopeLogs()
|
||||
for j := 0; j < sls.Len(); j++ {
|
||||
recs := sls.At(j).LogRecords()
|
||||
for k := 0; k < recs.Len(); k++ {
|
||||
a := recs.At(k).Attributes()
|
||||
if v, ok := a.Get("source"); !ok || v.Str() != "frontend" {
|
||||
continue
|
||||
}
|
||||
if _, ok := a.Get("client.address"); !ok && ip != "" {
|
||||
a.PutStr("client.address", ip)
|
||||
}
|
||||
if _, ok := a.Get("browser.userAgent"); !ok && ua != "" {
|
||||
a.PutStr("user_agent.original", ua)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user