1234567891011121314151617181920212223242526272829303132333435363738394041 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package tencentcloudlogserviceexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/tencentcloudlogserviceexporter"
- import (
- "strings"
- "unicode"
- )
- // The code for sanitize is mostly copied from:
- // https://github.com/open-telemetry/opentelemetry-collector/blob/2e84285efc665798d76773b9901727e8836e9d8f/exporter/prometheusexporter/sanitize.go
- // sanitize replaces non-alphanumeric characters with underscores in s.
- func sanitize(s string) string {
- if len(s) == 0 {
- return s
- }
- // Note: No length limit for label keys because Prometheus doesn't
- // define a length limit, thus we should NOT be truncating label keys.
- // See https://github.com/orijtech/prometheus-go-metrics-exporter/issues/4.
- s = strings.Map(sanitizeRune, s)
- if unicode.IsDigit(rune(s[0])) {
- s = "key_" + s
- }
- if s[0] == '_' {
- s = "key" + s
- }
- return s
- }
- // converts anything that is not a letter or digit to an underscore
- func sanitizeRune(r rune) rune {
- if unicode.IsLetter(r) || unicode.IsDigit(r) {
- return r
- }
- // Everything else turns into an underscore
- return '_'
- }
|