Skip to content

Commit

Permalink
Reduce tags to 20 and make sure os.host and token tags are always pre…
Browse files Browse the repository at this point in the history
…sent
  • Loading branch information
AkhigbeEromo committed Oct 24, 2024
1 parent a8346ed commit 02fec37
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions exporter/sematextexporter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,23 @@ type tag struct {

// optimizeTags sorts tags by key and removes tags with empty keys or values
func (b *sematextHTTPWriterBatch) optimizeTags(m map[string]string) []tag {
// Ensure token and os.host tags are always present
m["token"] = b.token
m["os.host"] = b.hostname

// Limit to 18 other tags, excluding token and os.host
if len(m) > 20 {
count := 0
for k := range m {
if k != "token" && k != "os.host" {
count++
if count > 18 {
delete(m, k)
}
}
}
}

tags := make([]tag, 0, len(m))
for k, v := range m {
switch {
Expand All @@ -220,9 +237,11 @@ func (b *sematextHTTPWriterBatch) optimizeTags(m map[string]string) []tag {
tags = append(tags, tag{k, v})
}
}

sort.Slice(tags, func(i, j int) bool {
return tags[i].k < tags[j].k
})

return tags
}

Expand Down

1 comment on commit 02fec37

@otisg
Copy link
Member

@otisg otisg commented on 02fec37 Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eromosele-SM I would imagine we don't want to just count any 18. I assume we want to select specific N tags. Although.... which tags are sent sent will depend on:

  1. The metric - different metrics come with different tags
  2. The runtime that's instrumented

Please sign in to comment.