Переглянути джерело

Format New Relic and OpenTelemetry metadata values that implement the `fmt.Stringer` interface as strings

DarthSim 2 тижнів тому
батько
коміт
207532fe97
3 змінених файлів з 14 додано та 0 видалено
  1. 4 0
      CHANGELOG.md
  2. 5 0
      metrics/newrelic/newrelic.go
  3. 5 0
      metrics/otel/otel.go

+ 4 - 0
CHANGELOG.md

@@ -1,5 +1,9 @@
 # Changelog
 
+## [Unreleased]
+### Changed
+- Format New Relic and OpenTelemetry metadata values that implement the `fmt.Stringer` interface as strings.
+
 ## [3.30.0] - 2025-09-17
 ### Added
 - Add [IMGPROXY_GRACEFUL_STOP_TIMEOUT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_GRACEFUL_STOP_TIMEOUT) config.

+ 5 - 0
metrics/newrelic/newrelic.go

@@ -141,6 +141,11 @@ func setMetadata(span attributable, key string, value interface{}) {
 		return
 	}
 
+	if stringer, ok := value.(fmt.Stringer); ok {
+		span.AddAttribute(key, stringer.String())
+		return
+	}
+
 	rv := reflect.ValueOf(value)
 	switch {
 	case rv.Kind() == reflect.String || rv.Kind() == reflect.Bool:

+ 5 - 0
metrics/otel/otel.go

@@ -431,6 +431,11 @@ func setMetadata(span trace.Span, key string, value interface{}) {
 		return
 	}
 
+	if stringer, ok := value.(fmt.Stringer); ok {
+		span.SetAttributes(attribute.String(key, stringer.String()))
+		return
+	}
+
 	rv := reflect.ValueOf(value)
 
 	switch {