From 42f76af860b4fd48d566e4e593e14bea91150880 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 7 Dec 2021 05:37:26 -0500 Subject: [PATCH] [8.0] Update default span/transaction type for OTel (backport #6834) (#6841) * Update default span/transaction type for OTel (#6834) (cherry picked from commit b571545ed6895523cd356c9925030134041c1295) # Conflicts: # changelogs/head.asciidoc * Delete head.asciidoc Co-authored-by: Andrew Wilkins --- .../jaeger_sampling_rate.approved.json | 6 ++-- .../metadata_jaeger-no-language.approved.json | 2 +- .../metadata_jaeger-version.approved.json | 2 +- .../metadata_jaeger.approved.json | 2 +- .../span_jaeger_custom.approved.json | 2 +- ...pan_jaeger_subtype_component.approved.json | 3 +- .../transaction_jaeger_custom.approved.json | 2 +- .../transaction_jaeger_no_attrs.approved.json | 2 +- ...action_jaeger_type_component.approved.json | 2 +- processor/otel/traces.go | 25 ++++++----------- processor/otel/traces_test.go | 16 +++++++++++ .../TestOTLPGRPCTraces.approved.json | 2 +- testdata/jaeger/batch_0.approved.json | 8 +++--- testdata/jaeger/batch_1.approved.json | 28 +++++++++---------- 14 files changed, 54 insertions(+), 48 deletions(-) diff --git a/processor/otel/test_approved/jaeger_sampling_rate.approved.json b/processor/otel/test_approved/jaeger_sampling_rate.approved.json index e339d4d4e63..3ef1a0ed339 100644 --- a/processor/otel/test_approved/jaeger_sampling_rate.approved.json +++ b/processor/otel/test_approved/jaeger_sampling_rate.approved.json @@ -30,7 +30,7 @@ "us": 79000000 }, "sampled": true, - "type": "custom" + "type": "unknown" } }, { @@ -62,7 +62,7 @@ "duration": { "us": 79000000 }, - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576500418000768 @@ -107,7 +107,7 @@ "us": 79000000 }, "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/processor/otel/test_approved/metadata_jaeger-no-language.approved.json b/processor/otel/test_approved/metadata_jaeger-no-language.approved.json index b0db5a40175..87be3d6eeab 100644 --- a/processor/otel/test_approved/metadata_jaeger-no-language.approved.json +++ b/processor/otel/test_approved/metadata_jaeger-no-language.approved.json @@ -31,7 +31,7 @@ }, "id": "0000000041414646", "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/processor/otel/test_approved/metadata_jaeger-version.approved.json b/processor/otel/test_approved/metadata_jaeger-version.approved.json index 4827fa32217..8fae43a507e 100644 --- a/processor/otel/test_approved/metadata_jaeger-version.approved.json +++ b/processor/otel/test_approved/metadata_jaeger-version.approved.json @@ -31,7 +31,7 @@ }, "id": "0000000041414646", "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/processor/otel/test_approved/metadata_jaeger.approved.json b/processor/otel/test_approved/metadata_jaeger.approved.json index 5b089296a69..725d00da461 100644 --- a/processor/otel/test_approved/metadata_jaeger.approved.json +++ b/processor/otel/test_approved/metadata_jaeger.approved.json @@ -42,7 +42,7 @@ }, "id": "0000000041414646", "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/processor/otel/test_approved/span_jaeger_custom.approved.json b/processor/otel/test_approved/span_jaeger_custom.approved.json index 333b4f4a282..363292146d5 100644 --- a/processor/otel/test_approved/span_jaeger_custom.approved.json +++ b/processor/otel/test_approved/span_jaeger_custom.approved.json @@ -30,7 +30,7 @@ "us": 79000000 }, "id": "0000000041414646", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576500418000768 diff --git a/processor/otel/test_approved/span_jaeger_subtype_component.approved.json b/processor/otel/test_approved/span_jaeger_subtype_component.approved.json index c850e2e27b6..7466a160b01 100644 --- a/processor/otel/test_approved/span_jaeger_subtype_component.approved.json +++ b/processor/otel/test_approved/span_jaeger_subtype_component.approved.json @@ -33,8 +33,7 @@ "us": 79000000 }, "id": "0000000041414646", - "subtype": "whatever", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576500418000768 diff --git a/processor/otel/test_approved/transaction_jaeger_custom.approved.json b/processor/otel/test_approved/transaction_jaeger_custom.approved.json index bd3a378e4e1..8072c9a31c2 100644 --- a/processor/otel/test_approved/transaction_jaeger_custom.approved.json +++ b/processor/otel/test_approved/transaction_jaeger_custom.approved.json @@ -33,7 +33,7 @@ "us": 0 }, "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/processor/otel/test_approved/transaction_jaeger_no_attrs.approved.json b/processor/otel/test_approved/transaction_jaeger_no_attrs.approved.json index 5ef68402367..13018ef45f6 100644 --- a/processor/otel/test_approved/transaction_jaeger_no_attrs.approved.json +++ b/processor/otel/test_approved/transaction_jaeger_no_attrs.approved.json @@ -31,7 +31,7 @@ }, "result": "Error", "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/processor/otel/test_approved/transaction_jaeger_type_component.approved.json b/processor/otel/test_approved/transaction_jaeger_type_component.approved.json index 8b034c4ea24..c0af37c8168 100644 --- a/processor/otel/test_approved/transaction_jaeger_type_component.approved.json +++ b/processor/otel/test_approved/transaction_jaeger_type_component.approved.json @@ -33,7 +33,7 @@ "us": 0 }, "sampled": true, - "type": "amqp" + "type": "unknown" } } ] diff --git a/processor/otel/traces.go b/processor/otel/traces.go index 53602f7f952..25aac29017f 100644 --- a/processor/otel/traces.go +++ b/processor/otel/traces.go @@ -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 { @@ -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) } @@ -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" } } @@ -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 { @@ -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) } @@ -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" + } } } diff --git a/processor/otel/traces_test.go b/processor/otel/traces_test.go index 50bc6c8dac0..e0d07fba097 100644 --- a/processor/otel/traces_test.go +++ b/processor/otel/traces_test.go @@ -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"), diff --git a/systemtest/approvals/TestOTLPGRPCTraces.approved.json b/systemtest/approvals/TestOTLPGRPCTraces.approved.json index 6468132b01b..6c7e7c19221 100644 --- a/systemtest/approvals/TestOTLPGRPCTraces.approved.json +++ b/systemtest/approvals/TestOTLPGRPCTraces.approved.json @@ -136,7 +136,7 @@ "id": "b3ee9be3b687a611", "name": "operation_name", "sampled": true, - "type": "custom" + "type": "unknown" } } ] diff --git a/testdata/jaeger/batch_0.approved.json b/testdata/jaeger/batch_0.approved.json index d45b90310cf..ce626c5bd96 100644 --- a/testdata/jaeger/batch_0.approved.json +++ b/testdata/jaeger/batch_0.approved.json @@ -49,7 +49,7 @@ "id": "7be2fd98d0973be3", "name": "Driver::findNearest", "sampled": true, - "type": "custom" + "type": "unknown" } }, { @@ -163,7 +163,7 @@ "transaction": { "id": "7be2fd98d0973be3", "sampled": true, - "type": "custom" + "type": "unknown" } }, { @@ -211,7 +211,7 @@ "transaction": { "id": "7be2fd98d0973be3", "sampled": true, - "type": "custom" + "type": "unknown" } }, { @@ -259,7 +259,7 @@ "transaction": { "id": "7be2fd98d0973be3", "sampled": true, - "type": "custom" + "type": "unknown" } }, { diff --git a/testdata/jaeger/batch_1.approved.json b/testdata/jaeger/batch_1.approved.json index 82f1a1675d6..6cbcc6a26d5 100644 --- a/testdata/jaeger/batch_1.approved.json +++ b/testdata/jaeger/batch_1.approved.json @@ -38,7 +38,7 @@ }, "id": "6e09e8bcefd6b828", "name": "FindDriverIDs", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827704954062 @@ -120,7 +120,7 @@ }, "id": "333295bfb438ea03", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827704973809 @@ -213,7 +213,7 @@ }, "id": "627c37a97e475c2f", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705007578 @@ -260,7 +260,7 @@ }, "id": "7bd7663d39c5a847", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705016845 @@ -307,7 +307,7 @@ }, "id": "6b4051dd2a5e2366", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705029415 @@ -354,7 +354,7 @@ }, "id": "6df97a86b9b3451b", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705040082 @@ -401,7 +401,7 @@ }, "id": "614811d6c498bfb0", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705054046 @@ -494,7 +494,7 @@ }, "id": "231604559da84d61", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705089459 @@ -541,7 +541,7 @@ }, "id": "61f7ecf24d13c36a", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705101278 @@ -588,7 +588,7 @@ }, "id": "2ef335bad24accc2", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705113531 @@ -635,7 +635,7 @@ }, "id": "38ec645e7201224d", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705125567 @@ -682,7 +682,7 @@ }, "id": "0242ee3774d9eab1", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705132896 @@ -775,7 +775,7 @@ }, "id": "6a63d1e81cfc7d95", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705172618 @@ -822,7 +822,7 @@ }, "id": "2b4c28f02b272f17", "name": "GetDriver", - "type": "app" + "type": "unknown" }, "timestamp": { "us": 1576827705186670