Files
traces/pkg/drain/data_heuristic.go
76c2c85b97 [Generator] Add DRAIN span_name sanitizer (#6098)
* [Generator] Add DRAIN span_name sanitizer

* Fix linter

* Fix formatting

* Update default manifest

* Fix build error in update-fixtures

* Remove bad test

* Remove misleading comment

* Add per-tenant override for drain mode

* Do a machines job

* Address PR feedback

* Address PR review: rename drain_mode config and improve sanitizer

- Rename `drain_mode` to `span_name_sanitization` across all config,
  legacy config, interfaces, and overrides for better user-facing clarity
- Add explicit default value "disabled" in RegisterFlagsAndApplyDefaults
- Add ValidateSpanNameSanitization function in validation/fields.go
- Rename metrics to remove DRAIN reference:
  `drain_spans_compacted_total` -> `spans_sanitized_total`
  `post_drain_demand_estimate` -> `post_sanitization_demand_estimate`
- Pass configured staleDuration to NewDrainSanitizer instead of
  hardcoded 15min, consistent with other registry components
- Extract "span_name" magic string to labelSpanName constant
- Update all tests with new names and signatures

* Update manifest

* Use empty string as disabled

* Update CHANGELOG.md

Co-authored-by: Suraj Nath <[email protected]>

* Update manifest

---------

Co-authored-by: Suraj Nath <[email protected]>
2026-02-22 00:55:22 -08:00

44 lines
1.2 KiB
Go

package drain
import "unicode"
type IsDataHeuristic func(token string) bool
// hexWithAtLeastOneDigit checks if the token contains at least one digit and is hex-like or guid-like.
func hexWithAtLeastOneDigit(token string) bool {
atLeastOneDigit := false
for _, c := range token {
if unicode.IsNumber(c) {
atLeastOneDigit = true
continue
}
if unicode.Is(unicode.Hex_Digit, c) || unicode.IsPunct(c) {
continue
}
// Non-hex, non-punct found.
return false
}
// All hex-like or guid-like values
// But still require at least one digit.
return atLeastOneDigit
}
// significantNumbers checks if the token is comprised of at least 25% numbers.
func significantNumbers(token string) bool {
numberCount := 0
for _, c := range token {
if unicode.IsNumber(c) {
numberCount++
}
}
return numberCount > max(len(token)/4, 1)
}
// defaultIsDataHeuristic is the default implementation of the IsDataHeuristic
// interface. It checks if the token is likely data based on a set of heuristics.
// This is the second main point of customization for the DRAIN algorithm, and is
// largely domain-specific.
func defaultIsDataHeuristic(token string) bool {
return hexWithAtLeastOneDigit(token) || significantNumbers(token)
}