Skip to content

Commit

Permalink
Added intakeV2 context.http.request.body field
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz committed Sep 9, 2024
1 parent 2f0f99a commit 8349427
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
7 changes: 7 additions & 0 deletions input/elasticapm/docs/spec/v2/span.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@
"object"
],
"properties": {
"body": {
"description": "The http request body as a string",
"type": [
"null",
"string"
]
},
"id": {
"description": "ID holds the unique identifier for the http request.",
"type": [
Expand Down
9 changes: 7 additions & 2 deletions input/elasticapm/internal/modeldecoder/v2/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,14 +1071,19 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) {
}
event.Http.Request.Method = from.Context.HTTP.Method.Val
}
if from.Context.HTTP.Request.ID.IsSet() {
if from.Context.HTTP.Request.IsSet() {
if event.Http == nil {
event.Http = &modelpb.HTTP{}
}
if event.Http.Request == nil {
event.Http.Request = &modelpb.HTTPRequest{}
}
event.Http.Request.Id = from.Context.HTTP.Request.ID.Val
if from.Context.HTTP.Request.ID.IsSet() {
event.Http.Request.Id = from.Context.HTTP.Request.ID.Val
}
if from.Context.HTTP.Request.Body.IsSet() {
event.Http.Request.Body = modeldecoderutil.ToValue(from.Context.HTTP.Request.Body.Val)
}
}
if from.Context.HTTP.Response.IsSet() {
if event.Http == nil {
Expand Down
2 changes: 2 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@ type spanContextHTTP struct {
type spanContextHTTPRequest struct {
// ID holds the unique identifier for the http request.
ID nullable.String `json:"id"`
// The http request body as a string
Body nullable.String `json:"body"`
}

type spanContextHTTPResponse struct {
Expand Down
3 changes: 2 additions & 1 deletion input/elasticapm/internal/modeldecoder/v2/model_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion input/elasticapm/internal/modeldecoder/v2/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package v2

import (
"encoding/json"
"google.golang.org/protobuf/types/known/structpb"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -258,14 +259,22 @@ func TestDecodeMapToSpanModel(t *testing.T) {
}
})

t.Run("http-request", func(t *testing.T) {
t.Run("http-request-id", func(t *testing.T) {
var input span
input.Context.HTTP.Request.ID.Set("some-request-id")
var out modelpb.APMEvent
mapToSpanModel(&input, &out)
assert.Equal(t, "some-request-id", out.Http.Request.Id)
})

t.Run("http-request-body", func(t *testing.T) {
var input span
input.Context.HTTP.Request.Body.Set("some-request-body")
var out modelpb.APMEvent
mapToSpanModel(&input, &out)
assert.Equal(t, structpb.NewStringValue("some-request-body"), out.Http.Request.Body)
})

t.Run("http-headers", func(t *testing.T) {
var input span
input.Context.HTTP.Response.Headers.Set(http.Header{"a": []string{"b", "c"}})
Expand Down

0 comments on commit 8349427

Please sign in to comment.