From 3abfe15d2f241efbe37cd5b303d028d2039aa092 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Fri, 8 Nov 2024 17:31:58 +0100 Subject: [PATCH 1/4] reporter: do not add empty attributes PR #212 changed the behaviour of addProfileAttributes(). Before adding an attribute the length of the string was checked - see https://github.com/open-telemetry/opentelemetry-ebpf-profiler/blob/0c58efd41280bce80cca9804896c76874d383b35/reporter/otlp_reporter.go#L747-L749 This returns to the original behaivour, where string attributes with no values are not added. Signed-off-by: Florian Lehner --- reporter/otlp_reporter.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index 1cf6201c..d742202c 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -753,6 +753,9 @@ func addProfileAttributes[T string | int64](profile *profiles.Profile, switch val := any(attr.value).(type) { case string: + if val == "" { + return + } attributeCompositeKey = attr.key + "_" + val attributeValue = common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: val}} case int64: From d8726784c5f76582a5792c481a7f00c0429f6d5d Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Fri, 8 Nov 2024 19:28:17 +0100 Subject: [PATCH 2/4] fixup: fix test Signed-off-by: Florian Lehner --- reporter/otlp_reporter_test.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/reporter/otlp_reporter_test.go b/reporter/otlp_reporter_test.go index bdfc22ed..42c64d04 100644 --- a/reporter/otlp_reporter_test.go +++ b/reporter/otlp_reporter_test.go @@ -30,26 +30,8 @@ func TestGetSampleAttributes(t *testing.T) { }, }, attributeMap: make(map[string]uint64), - expectedIndices: [][]uint64{{0, 1, 2, 3}}, + expectedIndices: [][]uint64{{0}}, expectedAttributeTable: []*common.KeyValue{ - { - Key: "container.id", - Value: &common.AnyValue{ - Value: &common.AnyValue_StringValue{StringValue: ""}, - }, - }, - { - Key: "thread.name", - Value: &common.AnyValue{ - Value: &common.AnyValue_StringValue{StringValue: ""}, - }, - }, - { - Key: "service.name", - Value: &common.AnyValue{ - Value: &common.AnyValue_StringValue{StringValue: ""}, - }, - }, { Key: "process.pid", Value: &common.AnyValue{ From 792c3cf05a5210e80a86b39eba97384011d8e967 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Mon, 11 Nov 2024 09:48:42 +0100 Subject: [PATCH 3/4] fixup: add OTel requirement level Signed-off-by: Florian Lehner --- reporter/otlp_reporter.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index d742202c..2f4030c9 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -86,8 +86,10 @@ type traceEvents struct { // attrKeyValue is a helper to populate Profile.attribute_table. type attrKeyValue[T string | int64] struct { - key string - value T + key string + // Set to true for OTel SemConv attributes with RequirementL: Required + required bool + value T } // OTLPReporter receives and transforms information to be OTLP/profiles compliant. @@ -753,7 +755,7 @@ func addProfileAttributes[T string | int64](profile *profiles.Profile, switch val := any(attr.value).(type) { case string: - if val == "" { + if !attr.required && val == "" { return } attributeCompositeKey = attr.key + "_" + val From 035f2339619f3e6972891f8616b27ee98de1fcd2 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Mon, 11 Nov 2024 09:50:43 +0100 Subject: [PATCH 4/4] fixup: typo Signed-off-by: Florian Lehner --- reporter/otlp_reporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index 2f4030c9..db666aa6 100644 --- a/reporter/otlp_reporter.go +++ b/reporter/otlp_reporter.go @@ -87,7 +87,7 @@ type traceEvents struct { // attrKeyValue is a helper to populate Profile.attribute_table. type attrKeyValue[T string | int64] struct { key string - // Set to true for OTel SemConv attributes with RequirementL: Required + // Set to true for OTel SemConv attributes with requirement level: Required required bool value T }