Skip to content

Commit

Permalink
feat: send user agent as a separate attribute (#79)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?

- Closes #76 

## Short description of the changes
- Pulls out `User-Agent` header and sets the `user_agent.original`
attribute

## How to verify that this has the expected result

<img width="606" alt="Screenshot 2023-08-16 at 11 49 55 AM"
src="https://github.com/honeycombio/honeycomb-ebpf-agent/assets/8810222/96032f66-e03a-4b04-8c4f-734e4717e08b">
  • Loading branch information
pkanal committed Aug 16, 2023
1 parent 1b64737 commit 340bcba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,28 @@ func handleHttpEvents(events chan assemblers.HttpEvent, client *kubernetes.Clien
select {
case event := <-events:

// create libhoney event
ev := libhoney.NewEvent()

// common attributes
ev.AddField("duration_ms", event.Duration.Microseconds())
ev.AddField(string(semconv.NetSockHostAddrKey), event.SrcIp)
ev.AddField("destination.address", event.DstIp)

// request attributes
if event.Request != nil {
ev.AddField("name", fmt.Sprintf("HTTP %s", event.Request.Method))
ev.AddField(string(semconv.HTTPMethodKey), event.Request.Method)
ev.AddField(string(semconv.HTTPURLKey), event.Request.RequestURI)
ev.AddField("http.request.body", fmt.Sprintf("%v", event.Request.Body))
ev.AddField("http.request.headers", fmt.Sprintf("%v", event.Request.Header))
ev.AddField(string(semconv.UserAgentOriginalKey), event.Request.Header.Get("User-Agent"))
} else {
ev.AddField("name", "HTTP")
ev.AddField("http.request.missing", "no request on this event")
}

// response attributes
if event.Response != nil {
ev.AddField(string(semconv.HTTPStatusCodeKey), event.Response.StatusCode)
ev.AddField("http.response.body", event.Response.Body)
Expand All @@ -125,7 +132,7 @@ func handleHttpEvents(events chan assemblers.HttpEvent, client *kubernetes.Clien
ev.AddField("http.response.missing", "no response on this event")
}

// k8s metadata
// k8s attributes
k8sEventAttrs := utils.GetK8sEventAttrs(client, event.SrcIp, event.DstIp)
ev.Add(k8sEventAttrs)

Expand Down

0 comments on commit 340bcba

Please sign in to comment.