diff --git a/reporter/otlp_reporter.go b/reporter/otlp_reporter.go index 0a5163b6..1dcace29 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 requirement level: Required + required bool + value T } // OTLPReporter receives and transforms information to be OTLP/profiles compliant. @@ -753,6 +755,9 @@ func addProfileAttributes[T string | int64](profile *profiles.Profile, switch val := any(attr.value).(type) { case string: + if !attr.required && val == "" { + return + } attributeCompositeKey = attr.key + "_" + val attributeValue = common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: val}} case int64: 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{