diff --git a/internal/monitoring/broadcast_conversion_test.go b/internal/monitoring/broadcast_conversion_test.go index 51acb44221..0702662cb2 100644 --- a/internal/monitoring/broadcast_conversion_test.go +++ b/internal/monitoring/broadcast_conversion_test.go @@ -22,6 +22,14 @@ type projectionNilMap map[string]string func (projectionNilMap) MarshalJSON() ([]byte, error) { return []byte(`{"custom":true}`), nil } +type projectionNilTextSlice []string + +func (projectionNilTextSlice) MarshalText() ([]byte, error) { return []byte("custom-text"), nil } + +type projectionNilTextMap map[string]string + +func (projectionNilTextMap) MarshalText() ([]byte, error) { return []byte("custom-text"), nil } + type projectionInvalidJSON struct{} func (projectionInvalidJSON) MarshalJSON() ([]byte, error) { return []byte(`{broken`), nil } @@ -53,6 +61,8 @@ func TestBroadcastRawJSONPreservesAbsentEmptyAndFailureSemantics(t *testing.T) { {"empty-slice", []string{}}, {"empty-map", map[string]string{}}, {"named-nil-slice-marshaler", projectionNilSlice(nil)}, {"named-nil-map-marshaler", projectionNilMap(nil)}, + {"named-nil-slice-text-marshaler", projectionNilTextSlice(nil)}, + {"named-nil-map-text-marshaler", projectionNilTextMap(nil)}, {"nil-pointer-marshaler", (*projectionNilSlice)(nil)}, {"invalid-json", projectionInvalidJSON{}}, {"encode-failure", projectionFailedJSON{}}, {"invalid-float", math.NaN()}, {"raw-null", json.RawMessage(`null`)}, diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index 57f0c98042..53182cf222 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -3,6 +3,7 @@ package monitoring import ( "context" "crypto/sha256" + "encoding" "encoding/hex" "encoding/json" stderrors "errors" @@ -6654,7 +6655,9 @@ func monitorRawJSON(value interface{}) json.RawMessage { case reflect.Slice, reflect.Map: if v.IsNil() { if _, custom := value.(json.Marshaler); !custom { - return nil + if _, customText := value.(encoding.TextMarshaler); !customText { + return nil + } } } }