From 207532fe977d02dec7aca226d8746b76ad093ec0 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Sun, 21 Sep 2025 21:15:46 +0300 Subject: [PATCH] Format New Relic and OpenTelemetry metadata values that implement the `fmt.Stringer` interface as strings --- CHANGELOG.md | 4 ++++ metrics/newrelic/newrelic.go | 5 +++++ metrics/otel/otel.go | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3134be55..31070523 100644 --- a/CHANGELOG.md +++ b/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. diff --git a/metrics/newrelic/newrelic.go b/metrics/newrelic/newrelic.go index 9edfb950..14a41ca6 100644 --- a/metrics/newrelic/newrelic.go +++ b/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: diff --git a/metrics/otel/otel.go b/metrics/otel/otel.go index 7514cc93..1f153c17 100644 --- a/metrics/otel/otel.go +++ b/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 {