Skip to content

Commit 02fec37

Browse files
committed
Reduce tags to 20 and make sure os.host and token tags are always present
1 parent a8346ed commit 02fec37

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

exporter/sematextexporter/writer.go

+19
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ type tag struct {
209209

210210
// optimizeTags sorts tags by key and removes tags with empty keys or values
211211
func (b *sematextHTTPWriterBatch) optimizeTags(m map[string]string) []tag {
212+
// Ensure token and os.host tags are always present
213+
m["token"] = b.token
214+
m["os.host"] = b.hostname
215+
216+
// Limit to 18 other tags, excluding token and os.host
217+
if len(m) > 20 {
218+
count := 0
219+
for k := range m {
220+
if k != "token" && k != "os.host" {
221+
count++
222+
if count > 18 {
223+
delete(m, k)
224+
}
225+
}
226+
}
227+
}
228+
212229
tags := make([]tag, 0, len(m))
213230
for k, v := range m {
214231
switch {
@@ -220,9 +237,11 @@ func (b *sematextHTTPWriterBatch) optimizeTags(m map[string]string) []tag {
220237
tags = append(tags, tag{k, v})
221238
}
222239
}
240+
223241
sort.Slice(tags, func(i, j int) bool {
224242
return tags[i].k < tags[j].k
225243
})
244+
226245
return tags
227246
}
228247

0 commit comments

Comments
 (0)