Skip to content

Commit

Permalink
reporter: do not add empty attributes (open-telemetry#233)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl authored Nov 18, 2024
1 parent 6d846a2 commit e40ccae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
9 changes: 7 additions & 2 deletions reporter/otlp_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 1 addition & 19 deletions reporter/otlp_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit e40ccae

Please sign in to comment.