Skip to content

Commit

Permalink
[8.0] Update default span/transaction type for OTel (backport #6834) (#…
Browse files Browse the repository at this point in the history
…6841)

* Update default span/transaction type for OTel (#6834)

(cherry picked from commit b571545)

# Conflicts:
#	changelogs/head.asciidoc

* Delete head.asciidoc

Co-authored-by: Andrew Wilkins <[email protected]>
  • Loading branch information
mergify[bot] and axw authored Dec 7, 2021
1 parent 76e4ceb commit 42f76af
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"us": 79000000
},
"sampled": true,
"type": "custom"
"type": "unknown"
}
},
{
Expand Down Expand Up @@ -62,7 +62,7 @@
"duration": {
"us": 79000000
},
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576500418000768
Expand Down Expand Up @@ -107,7 +107,7 @@
"us": 79000000
},
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"id": "0000000041414646",
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"id": "0000000041414646",
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion processor/otel/test_approved/metadata_jaeger.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"id": "0000000041414646",
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"us": 79000000
},
"id": "0000000041414646",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576500418000768
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"us": 79000000
},
"id": "0000000041414646",
"subtype": "whatever",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576500418000768
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"us": 0
},
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"result": "Error",
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"us": 0
},
"sampled": true,
"type": "amqp"
"type": "unknown"
}
}
]
Expand Down
25 changes: 8 additions & 17 deletions processor/otel/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ func TranslateTransaction(
var foundSpanType int
var message model.Message

var component string
var samplerType, samplerParam pdata.AttributeValue
attributes.Range(func(kDots string, v pdata.AttributeValue) bool {
if isJaeger {
Expand Down Expand Up @@ -394,9 +393,6 @@ func TranslateTransaction(
// should set this as a resource attribute (OTel) or tracer
// tag (Jaeger).
event.Service.Version = stringval
case "component":
component = stringval
fallthrough
default:
event.Labels.Set(k, stringval)
}
Expand All @@ -411,11 +407,7 @@ func TranslateTransaction(
case messagingSpan:
event.Transaction.Type = "messaging"
default:
if component != "" {
event.Transaction.Type = component
} else {
event.Transaction.Type = "custom"
}
event.Transaction.Type = "unknown"
}
}

Expand Down Expand Up @@ -510,7 +502,6 @@ func TranslateSpan(spanKind pdata.SpanKind, attributes pdata.AttributeMap, event
var db model.DB
var destinationService model.DestinationService
var foundSpanType int
var component string
var rpcSystem string
var samplerType, samplerParam pdata.AttributeValue
attributes.Range(func(kDots string, v pdata.AttributeValue) bool {
Expand Down Expand Up @@ -647,9 +638,6 @@ func TranslateSpan(spanKind pdata.SpanKind, attributes pdata.AttributeMap, event
// Prefer using peer.address for resource.
destinationService.Resource = stringval
}
case "component":
component = stringval
fallthrough
default:
event.Labels.Set(k, stringval)
}
Expand Down Expand Up @@ -765,10 +753,13 @@ func TranslateSpan(spanKind pdata.SpanKind, attributes pdata.AttributeMap, event
default:
// Only set event.Span.Type if not already set
if event.Span.Type == "" {
event.Span.Type = "app"
}
if event.Span.Subtype == "" {
event.Span.Subtype = component
switch spanKind {
case pdata.SpanKindInternal:
event.Span.Type = "app"
event.Span.Subtype = "internal"
default:
event.Span.Type = "unknown"
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions processor/otel/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,22 @@ func TestMessagingSpan(t *testing.T) {
}, event.Span.DestinationService)
}

func TestSpanType(t *testing.T) {
// Internal spans default to app.internal.
event := transformSpanWithAttributes(t, map[string]pdata.AttributeValue{}, func(s pdata.Span) {
s.SetKind(pdata.SpanKindInternal)
})
assert.Equal(t, "app", event.Span.Type)
assert.Equal(t, "internal", event.Span.Subtype)

// All other spans default to unknown.
event = transformSpanWithAttributes(t, map[string]pdata.AttributeValue{}, func(s pdata.Span) {
s.SetKind(pdata.SpanKindClient)
})
assert.Equal(t, "unknown", event.Span.Type)
assert.Equal(t, "", event.Span.Subtype)
}

func TestSpanNetworkAttributes(t *testing.T) {
networkAttributes := map[string]pdata.AttributeValue{
"net.host.connection.type": pdata.NewAttributeValueString("cell"),
Expand Down
2 changes: 1 addition & 1 deletion systemtest/approvals/TestOTLPGRPCTraces.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
"id": "b3ee9be3b687a611",
"name": "operation_name",
"sampled": true,
"type": "custom"
"type": "unknown"
}
}
]
Expand Down
8 changes: 4 additions & 4 deletions testdata/jaeger/batch_0.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"id": "7be2fd98d0973be3",
"name": "Driver::findNearest",
"sampled": true,
"type": "custom"
"type": "unknown"
}
},
{
Expand Down Expand Up @@ -163,7 +163,7 @@
"transaction": {
"id": "7be2fd98d0973be3",
"sampled": true,
"type": "custom"
"type": "unknown"
}
},
{
Expand Down Expand Up @@ -211,7 +211,7 @@
"transaction": {
"id": "7be2fd98d0973be3",
"sampled": true,
"type": "custom"
"type": "unknown"
}
},
{
Expand Down Expand Up @@ -259,7 +259,7 @@
"transaction": {
"id": "7be2fd98d0973be3",
"sampled": true,
"type": "custom"
"type": "unknown"
}
},
{
Expand Down
28 changes: 14 additions & 14 deletions testdata/jaeger/batch_1.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"id": "6e09e8bcefd6b828",
"name": "FindDriverIDs",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827704954062
Expand Down Expand Up @@ -120,7 +120,7 @@
},
"id": "333295bfb438ea03",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827704973809
Expand Down Expand Up @@ -213,7 +213,7 @@
},
"id": "627c37a97e475c2f",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705007578
Expand Down Expand Up @@ -260,7 +260,7 @@
},
"id": "7bd7663d39c5a847",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705016845
Expand Down Expand Up @@ -307,7 +307,7 @@
},
"id": "6b4051dd2a5e2366",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705029415
Expand Down Expand Up @@ -354,7 +354,7 @@
},
"id": "6df97a86b9b3451b",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705040082
Expand Down Expand Up @@ -401,7 +401,7 @@
},
"id": "614811d6c498bfb0",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705054046
Expand Down Expand Up @@ -494,7 +494,7 @@
},
"id": "231604559da84d61",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705089459
Expand Down Expand Up @@ -541,7 +541,7 @@
},
"id": "61f7ecf24d13c36a",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705101278
Expand Down Expand Up @@ -588,7 +588,7 @@
},
"id": "2ef335bad24accc2",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705113531
Expand Down Expand Up @@ -635,7 +635,7 @@
},
"id": "38ec645e7201224d",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705125567
Expand Down Expand Up @@ -682,7 +682,7 @@
},
"id": "0242ee3774d9eab1",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705132896
Expand Down Expand Up @@ -775,7 +775,7 @@
},
"id": "6a63d1e81cfc7d95",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705172618
Expand Down Expand Up @@ -822,7 +822,7 @@
},
"id": "2b4c28f02b272f17",
"name": "GetDriver",
"type": "app"
"type": "unknown"
},
"timestamp": {
"us": 1576827705186670
Expand Down

0 comments on commit 42f76af

Please sign in to comment.