Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field for span http request body to IntakeV2 #366

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 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,9 @@
"object"
],
"properties": {
"body": {
"description": "The http request body usually as a string, but may be a dictionary for multipart/form-data content"
},
"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 @@ -843,6 +843,8 @@ type spanContextHTTP struct {
}

type spanContextHTTPRequest struct {
// The http request body usually as a string, but may be a dictionary for multipart/form-data content
Body nullable.Interface `json:"body"`
// ID holds the unique identifier for the http request.
ID nullable.String `json:"id"`
}
Expand Down

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

12 changes: 11 additions & 1 deletion input/elasticapm/internal/modeldecoder/v2/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"testing"
"time"

"google.golang.org/protobuf/types/known/structpb"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -258,14 +260,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
6 changes: 6 additions & 0 deletions model/modeljson/http.pb.json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package modeljson
import (
"testing"

"google.golang.org/protobuf/types/known/structpb"

modeljson "github.com/elastic/apm-data/model/modeljson/internal"
"github.com/elastic/apm-data/model/modelpb"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -51,6 +53,7 @@ func TestHTTPToModelJSON(t *testing.T) {
Id: "id",
Method: "method",
Referrer: "referrer",
Body: structpb.NewStringValue("request-body"),
},
},
expected: &modeljson.HTTP{
Expand All @@ -61,6 +64,9 @@ func TestHTTPToModelJSON(t *testing.T) {
ID: "id",
Method: "method",
Referrer: "referrer",
Body: &modeljson.HTTPRequestBody{
Original: "request-body",
},
},
},
},
Expand Down
Loading