Skip to content

Commit

Permalink
Merge branch 'main' into proto-uint
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jul 26, 2023
2 parents 75a5c7e + 4939b2f commit 3e77841
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
all: generate-modelpb generate gomodtidy update-licenses fieldalignment fmt protolint

test:
go test -v ./...
go test -v -race ./...

fmt:
go run golang.org/x/tools/cmd/[email protected] -w .
Expand Down
9 changes: 9 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ func mapToErrorModel(from *errorEvent, event *modelpb.APMEvent) {
}
if from.TransactionID.IsSet() {
event.Transaction.Id = from.TransactionID.Val
event.Span = &modelpb.Span{
Id: from.TransactionID.Val,
}
}
if from.Transaction.IsSet() {
if from.Transaction.Sampled.IsSet() {
Expand Down Expand Up @@ -1341,6 +1344,9 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) {
}
if from.ID.IsSet() {
out.Id = from.ID.Val
event.Span = &modelpb.Span{
Id: from.ID.Val,
}
}
if from.Marks.IsSet() {
out.Marks = make(map[string]*modelpb.TransactionMark, len(from.Marks.Events))
Expand Down Expand Up @@ -1472,6 +1478,9 @@ func mapToLogModel(from *log, event *modelpb.APMEvent) {
event.Transaction = &modelpb.Transaction{
Id: from.TransactionID.Val,
}
event.Span = &modelpb.Span{
Id: from.TransactionID.Val,
}
}
if from.SpanID.IsSet() {
event.Span = &modelpb.Span{
Expand Down
9 changes: 9 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,13 @@ func TestDecodeMapToErrorModel(t *testing.T) {
mapToErrorModel(&input, &out)
assert.Equal(t, "12341231", out.Transaction.Id)
})

t.Run("transaction-span.id", func(t *testing.T) {
var input errorEvent
var out modelpb.APMEvent
input.TransactionID.Set("1234")
mapToErrorModel(&input, &out)
assert.Equal(t, "1234", out.Transaction.Id)
assert.Equal(t, "1234", out.Span.Id)
})
}
18 changes: 18 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,22 @@ func TestDecodeMapToLogModel(t *testing.T) {
"float64": {Value: 1.1},
}, modelpb.NumericLabels(out.NumericLabels))
})

t.Run("transaction-id", func(t *testing.T) {
var input log
var out modelpb.APMEvent
input.TransactionID.Set("1234")
mapToLogModel(&input, &out)
assert.Equal(t, "1234", out.Transaction.Id)
assert.Equal(t, "1234", out.Span.Id)
})

t.Run("span-id", func(t *testing.T) {
var input log
var out modelpb.APMEvent
input.SpanID.Set("1234")
mapToLogModel(&input, &out)
assert.Equal(t, "1234", out.Span.Id)
})

}
2 changes: 1 addition & 1 deletion input/elasticapm/internal/modeldecoder/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ type log struct {
TraceID nullable.String `json:"trace.id" validate:"maxLength=1024"`
// TransactionID holds the ID of the correlated transaction.
TransactionID nullable.String `json:"transaction.id" validate:"maxLength=1024"`
// SpanID holds the ID ID of the correlated span.
// SpanID holds the ID of the correlated span.
SpanID nullable.String `json:"span.id" validate:"maxLength=1024"`
// Message logged as part of the log. In case a parameterized message is
// captured, Message should contain the same information, but with any placeholders
Expand Down
9 changes: 9 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,4 +672,13 @@ func TestDecodeMapToTransactionModel(t *testing.T) {
RepresentativeCount: 1,
}, out.Span)
})

t.Run("transaction-span.id", func(t *testing.T) {
var input transaction
var out modelpb.APMEvent
input.ID.Set("1234")
mapToTransactionModel(&input, &out)
assert.Equal(t, "1234", out.Transaction.Id)
assert.Equal(t, "1234", out.Span.Id)
})
}
9 changes: 9 additions & 0 deletions input/otlp/exceptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ Caused by: LowLevelException
Type: transactionEvent.Transaction.Type,
Sampled: true,
},
Span: &modelpb.Span{
Id: transactionEvent.Transaction.Id,
},
Event: &modelpb.Event{Received: transactionEvent.Event.Received},
Error: &modelpb.Error{
Exception: &modelpb.Exception{
Expand Down Expand Up @@ -176,6 +179,9 @@ Caused by: LowLevelException
Type: transactionEvent.Transaction.Type,
Sampled: true,
},
Span: &modelpb.Span{
Id: transactionEvent.Transaction.Id,
},
Event: &modelpb.Event{Received: transactionEvent.Event.Received},
Error: &modelpb.Error{
Exception: &modelpb.Exception{
Expand Down Expand Up @@ -337,6 +343,9 @@ func TestEncodeSpanEventsNonJavaExceptions(t *testing.T) {
Type: transactionEvent.Transaction.Type,
Sampled: true,
},
Span: &modelpb.Span{
Id: transactionEvent.Transaction.Id,
},
Event: &modelpb.Event{Received: transactionEvent.Event.Received},
Error: &modelpb.Error{
Exception: &modelpb.Exception{
Expand Down
1 change: 1 addition & 0 deletions input/otlp/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func transformResourceMetadata(t *testing.T, resourceAttrs map[string]interface{
otelSpan.SetSpanID(pcommon.SpanID{2})
events := transformTraces(t, traces)
(*events)[0].Transaction = nil
(*events)[0].Span = nil
(*events)[0].Trace = nil
(*events)[0].Event = nil
(*events)[0].Timestamp = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
},
"name": "unknown"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
},
"name": "unknown"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down
3 changes: 3 additions & 0 deletions input/otlp/test_approved/metadata_jaeger.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
},
"name": "foo"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
},
"name": "unknown"
},
"span": {
"id": "41414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down
30 changes: 30 additions & 0 deletions input/otlp/test_approved/transaction_jaeger_full.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -98,6 +101,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -150,6 +156,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -204,6 +213,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -258,6 +270,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -312,6 +327,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -364,6 +382,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"timestamp": {
"us": 1576500418000768
},
Expand Down Expand Up @@ -415,6 +436,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"trace": {
"id": "00000000000000000000000046467830"
},
Expand Down Expand Up @@ -461,6 +485,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"trace": {
"id": "00000000000000000000000046467830"
},
Expand Down Expand Up @@ -506,6 +533,9 @@
"name": "unknown",
"version": "1.0"
},
"span": {
"id": "0000000041414646"
},
"trace": {
"id": "00000000000000000000000046467830"
},
Expand Down
12 changes: 12 additions & 0 deletions input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func (c *Consumer) convertSpan(
Sampled: true,
RepresentativeCount: representativeCount,
}
if spanID != "" {
event.Span = &modelpb.Span{
Id: spanID,
}
}

TranslateTransaction(otelSpan.Attributes(), otelSpan.Status(), otelLibrary, event)
} else {
event.Span = &modelpb.Span{
Expand Down Expand Up @@ -1012,6 +1018,9 @@ func setErrorContext(out *modelpb.APMEvent, parent *modelpb.APMEvent) {
Sampled: parent.Transaction.Sampled,
Type: parent.Transaction.Type,
}
out.Span = &modelpb.Span{
Id: parent.Transaction.Id,
}
out.Error.Custom = parent.Transaction.Custom
out.ParentId = parent.Transaction.Id
}
Expand All @@ -1025,6 +1034,9 @@ func setLogContext(out *modelpb.APMEvent, parent *modelpb.APMEvent) {
out.Transaction = &modelpb.Transaction{
Id: parent.Transaction.Id,
}
out.Span = &modelpb.Span{
Id: parent.Transaction.Id,
}
}
if parent.Span != nil {
out.Span = &modelpb.Span{
Expand Down
16 changes: 10 additions & 6 deletions model/internal/modeljson/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ type Document struct {
Process *Process `json:"process,omitempty"`
Event *Event `json:"event,omitempty"`

Timestamp Time `json:"@timestamp"`
DataStreamType string `json:"data_stream.type,omitempty"`
DataStreamDataset string `json:"data_stream.dataset,omitempty"`
DataStreamNamespace string `json:"data_stream.namespace,omitempty"`
Message string `json:"message,omitempty"`
DocCount uint64 `json:"_doc_count,omitempty"`
Timestamp Time `json:"@timestamp"`
DataStream *DataStream `json:"data_stream,omitempty"`
Message string `json:"message,omitempty"`
DocCount uint64 `json:"_doc_count,omitempty"`
}

type Time time.Time
Expand All @@ -88,3 +86,9 @@ func (t Time) MarshalFastJSON(w *fastjson.Writer) error {
func (t Time) isZero() bool {
return time.Time(t).IsZero()
}

type DataStream struct {
Type string `json:"type,omitempty"`
Dataset string `json:"dataset,omitempty"`
Namespace string `json:"namespace,omitempty"`
}
Loading

0 comments on commit 3e77841

Please sign in to comment.