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

Simplify parent and child into strings instead of full-blown messages #98

Merged
merged 4 commits into from
Jul 4, 2023
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
8 changes: 2 additions & 6 deletions codec/fullevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent {
Original: "original",
Name: "name",
},
Parent: &modelpb.Parent{
Id: "id",
},
ParentId: "id",
Trace: &modelpb.Trace{
Id: "id",
},
Expand Down Expand Up @@ -437,9 +435,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent {
Domain: "example.com",
Port: 443,
},
Child: &modelpb.Child{
Id: []string{"id"},
},
Children: []string{"id"},
Destination: &modelpb.Destination{
Address: "127.0.0.1",
Port: 443,
Expand Down
15 changes: 4 additions & 11 deletions input/elasticapm/internal/modeldecoder/rumv3/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,15 @@ func DecodeNestedTransaction(d decoder.Decoder, input *modeldecoder.Input, batch
event := input.Base.CloneVT()
mapToSpanModel(&s, event)
event.Transaction = &modelpb.Transaction{Id: transaction.Transaction.Id}
event.Parent = &modelpb.Parent{
Id: transaction.GetTransaction().GetId(), // may be overridden later
}
event.ParentId = transaction.GetTransaction().GetId() // may be overridden later
event.Trace = transaction.Trace
*batch = append(*batch, event)
}
spans := (*batch)[offset:]
for i, s := range root.Transaction.Spans {
if s.ParentIndex.IsSet() && s.ParentIndex.Val >= 0 && s.ParentIndex.Val < len(spans) {
if e := spans[s.ParentIndex.Val]; e != nil {
spans[i].Parent = populateNil(spans[i].Parent)
spans[i].Parent.Id = e.Span.Id
spans[i].ParentId = e.Span.Id
}
}
}
Expand Down Expand Up @@ -249,9 +246,7 @@ func mapToErrorModel(from *errorEvent, event *modelpb.APMEvent) {
out.Log = &log
}
if from.ParentID.IsSet() {
event.Parent = &modelpb.Parent{
Id: from.ParentID.Val,
}
event.ParentId = from.ParentID.Val
}
if !from.Timestamp.Val.IsZero() {
event.Timestamp = timestamppb.New(from.Timestamp.Val)
Expand Down Expand Up @@ -772,9 +767,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) {
}
}
if from.ParentID.IsSet() {
event.Parent = &modelpb.Parent{
Id: from.ParentID.Val,
}
event.ParentId = from.ParentID.Val
}
if from.Result.IsSet() {
out.Result = from.Result.Val
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestDecodeNestedTransaction(t *testing.T) {
assert.Equal(t, now.Add(start), batch[2].Timestamp.AsTime()) // add start to timestamp
assert.Equal(t, "100", batch[2].Transaction.Id)
assert.Equal(t, "1", batch[2].Trace.Id)
assert.Equal(t, "100", batch[2].Parent.Id)
assert.Equal(t, "100", batch[2].ParentId)

err := DecodeNestedTransaction(decoder.NewJSONDecoder(strings.NewReader(`malformed`)), &input, &batch)
require.Error(t, err)
Expand Down
18 changes: 5 additions & 13 deletions input/elasticapm/internal/modeldecoder/v2/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,7 @@ func mapToErrorModel(from *errorEvent, event *modelpb.APMEvent) {
out.Log = &log
}
if from.ParentID.IsSet() {
event.Parent = &modelpb.Parent{
Id: from.ParentID.Val,
}
event.ParentId = from.ParentID.Val
}
if !from.Timestamp.Val.IsZero() {
event.Timestamp = timestamppb.New(from.Timestamp.Val)
Expand Down Expand Up @@ -1005,10 +1003,8 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) {
out.Composite = &composite
}
if len(from.ChildIDs) > 0 {
event.Child = &modelpb.Child{
Id: make([]string, len(from.ChildIDs)),
}
copy(event.Child.Id, from.ChildIDs)
event.Children = make([]string, len(from.ChildIDs))
copy(event.Children, from.ChildIDs)
}
if from.Context.Database.IsSet() {
db := modelpb.DB{}
Expand Down Expand Up @@ -1159,9 +1155,7 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) {
}
}
if from.ParentID.IsSet() {
event.Parent = &modelpb.Parent{
Id: from.ParentID.Val,
}
event.ParentId = from.ParentID.Val
}
if from.SampleRate.IsSet() {
if from.SampleRate.Val > 0 {
Expand Down Expand Up @@ -1380,9 +1374,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) {
}
}
if from.ParentID.IsSet() {
event.Parent = &modelpb.Parent{
Id: from.ParentID.Val,
}
event.ParentId = from.ParentID.Val
}
if from.Result.IsSet() {
out.Result = from.Result.Val
Expand Down
6 changes: 2 additions & 4 deletions input/elasticapm/internal/modeldecoder/v2/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func isIgnoredPrefix(key string) bool {
func isUnmappedMetadataField(key string) bool {
switch key {
case
"child",
"child.id",
"children",
"client.domain",
"client",
"client.ip",
Expand Down Expand Up @@ -98,8 +97,7 @@ func isUnmappedMetadataField(key string) bool {
"observer.type",
"observer.version",
"observer.version_major",
"parent",
"parent.id",
"parent_id",
"process.command_line",
"process.executable",
"process.thread",
Expand Down
2 changes: 1 addition & 1 deletion input/elasticapm/internal/modeldecoder/v2/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestDecodeNestedSpan(t *testing.T) {
require.NotNil(t, batch[0].Span)
assert.Equal(t, time.Time{}.Add(143*time.Millisecond), batch[0].Timestamp.AsTime())
assert.Equal(t, 100*time.Millisecond, batch[0].Event.Duration.AsDuration())
assert.Equal(t, &modelpb.Parent{Id: "parent-123"}, batch[0].Parent, protocmp.Transform())
assert.Equal(t, "parent-123", batch[0].ParentId, protocmp.Transform())
assert.Equal(t, &modelpb.Trace{Id: "trace-ab"}, batch[0].Trace, protocmp.Transform())
assert.Empty(t, cmp.Diff(&modelpb.Span{
Name: "s",
Expand Down
6 changes: 3 additions & 3 deletions input/otlp/exceptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Caused by: LowLevelException
NumericLabels: modelpb.NumericLabels{},
Processor: modelpb.ErrorProcessor(),
Trace: transactionEvent.Trace,
Parent: &modelpb.Parent{Id: transactionEvent.Transaction.Id},
ParentId: transactionEvent.Transaction.Id,
Transaction: &modelpb.Transaction{
Id: transactionEvent.Transaction.Id,
Type: transactionEvent.Transaction.Type,
Expand Down Expand Up @@ -172,7 +172,7 @@ Caused by: LowLevelException
NumericLabels: modelpb.NumericLabels{},
Processor: modelpb.ErrorProcessor(),
Trace: transactionEvent.Trace,
Parent: &modelpb.Parent{Id: transactionEvent.Transaction.Id},
ParentId: transactionEvent.Transaction.Id,
Transaction: &modelpb.Transaction{
Id: transactionEvent.Transaction.Id,
Type: transactionEvent.Transaction.Type,
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestEncodeSpanEventsNonJavaExceptions(t *testing.T) {
NumericLabels: modelpb.NumericLabels{},
Processor: modelpb.ErrorProcessor(),
Trace: transactionEvent.Trace,
Parent: &modelpb.Parent{Id: transactionEvent.Transaction.Id},
ParentId: transactionEvent.Transaction.Id,
Transaction: &modelpb.Transaction{
Id: transactionEvent.Transaction.Id,
Type: transactionEvent.Transaction.Type,
Expand Down
10 changes: 3 additions & 7 deletions input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ func (c *Consumer) convertSpan(
event.Event.Duration = durationpb.New(duration)
event.Event.Outcome = spanStatusOutcome(otelSpan.Status())
if parentID != "" {
event.Parent = &modelpb.Parent{
Id: parentID,
}
event.ParentId = parentID
}
if root || otelSpan.Kind() == ptrace.SpanKindServer || otelSpan.Kind() == ptrace.SpanKindConsumer {
event.Processor = modelpb.TransactionProcessor()
Expand Down Expand Up @@ -1010,12 +1008,10 @@ func setErrorContext(out *modelpb.APMEvent, parent *modelpb.APMEvent) {
Type: parent.Transaction.Type,
}
out.Error.Custom = parent.Transaction.Custom
out.Parent = &modelpb.Parent{
Id: parent.Transaction.Id,
}
out.ParentId = parent.Transaction.Id
}
if parent.Span != nil {
out.Parent.Id = parent.Span.Id
out.ParentId = parent.Span.Id
}
}

Expand Down
Loading