Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/google.golang.org/prot…
Browse files Browse the repository at this point in the history
…obuf-1.36.0
  • Loading branch information
kruskall authored Dec 23, 2024
2 parents b84dafc + 560cc4b commit 13c9984
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
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
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.

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

0 comments on commit 13c9984

Please sign in to comment.