Skip to content

Commit

Permalink
Set both transaction and span on root exit root spans
Browse files Browse the repository at this point in the history
  • Loading branch information
gregkalapos committed Dec 9, 2024
1 parent aedf6aa commit 3def749
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
10 changes: 8 additions & 2 deletions enrichments/trace/internal/elastic/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,14 @@ func (s *spanEnrichmentContext) enrichSpan(
if cfg.Span.InferredSpans.Enabled {
s.setInferredSpans(span)
}
if cfg.Span.ProcessorEvent.Enabled && !isExitRootSpan {
span.Attributes().PutStr(AttributeProcessorEvent, "span")
if cfg.Span.ProcessorEvent.Enabled {
if isExitRootSpan {
attrSlice := span.Attributes().PutEmptySlice(AttributeProcessorEvent)
attrSlice.AppendEmpty().SetStr("transaction")
attrSlice.AppendEmpty().SetStr("span")
} else {
span.Attributes().PutStr(AttributeProcessorEvent, "span")
}
}

if isExitRootSpan && cfg.Transaction.Type.Enabled {
Expand Down
33 changes: 24 additions & 9 deletions enrichments/trace/internal/elastic/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,14 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) {
}(),
config: config.Enabled(),
enrichedAttrs: map[string]any{
AttributeTimestampUs: int64(0),
AttributeTransactionName: "rootClientSpan",
AttributeProcessorEvent: "transaction",
AttributeTimestampUs: int64(0),
AttributeTransactionName: "rootClientSpan",
AttributeProcessorEvent: func() pcommon.Slice {
p := pcommon.NewSlice()
p.AppendEmpty().SetStr("transaction")
p.AppendEmpty().SetStr("span")
return p
}().AsRaw(),
AttributeSpanType: "external",
AttributeSpanSubtype: "http",
AttributeSpanDestinationServiceResource: "localhost:8080",
Expand Down Expand Up @@ -448,9 +453,14 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) {
}(),
config: config.Enabled(),
enrichedAttrs: map[string]any{
AttributeTimestampUs: int64(0),
AttributeTransactionName: "rootClientSpan",
AttributeProcessorEvent: "transaction",
AttributeTimestampUs: int64(0),
AttributeTransactionName: "rootClientSpan",
AttributeProcessorEvent: func() pcommon.Slice {
p := pcommon.NewSlice()
p.AppendEmpty().SetStr("transaction")
p.AppendEmpty().SetStr("span")
return p
}().AsRaw(),
AttributeSpanType: "db",
AttributeSpanSubtype: "mssql",
AttributeSpanDestinationServiceResource: "mssql",
Expand Down Expand Up @@ -488,9 +498,14 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) {
}(),
config: config.Enabled(),
enrichedAttrs: map[string]any{
AttributeTimestampUs: int64(0),
AttributeTransactionName: "rootClientSpan",
AttributeProcessorEvent: "transaction",
AttributeTimestampUs: int64(0),
AttributeTransactionName: "rootClientSpan",
AttributeProcessorEvent: func() pcommon.Slice {
p := pcommon.NewSlice()
p.AppendEmpty().SetStr("transaction")
p.AppendEmpty().SetStr("span")
return p
}().AsRaw(),
AttributeSpanType: "messaging",
AttributeSpanSubtype: "rabbitmq",
AttributeSpanDestinationServiceResource: "rabbitmq/T",
Expand Down

0 comments on commit 3def749

Please sign in to comment.