diff --git a/Changes b/Changes index 73c3038..fa7304b 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for OpenTelemetry-Exporter-OTLP {{$NEXT}} * Bump OTLP Protobuf files to v1.2.0 + * Ensure JSON encoder encodes status messages as strings. 0.015 2023-11-26 16:19:58+00:00 Europe/London diff --git a/lib/OpenTelemetry/Exporter/OTLP/Encoder/JSON.pm b/lib/OpenTelemetry/Exporter/OTLP/Encoder/JSON.pm index 4aebb8d..8f3005a 100644 --- a/lib/OpenTelemetry/Exporter/OTLP/Encoder/JSON.pm +++ b/lib/OpenTelemetry/Exporter/OTLP/Encoder/JSON.pm @@ -74,7 +74,7 @@ class OpenTelemetry::Exporter::OTLP::Encoder::JSON { method encode_status ( $status ) { { code => $status->code, - message => $status->description, + message => '' . $status->description, }; } diff --git a/t/OpenTelemetry/Exporter/OTLP/Encoder/JSON.t b/t/OpenTelemetry/Exporter/OTLP/Encoder/JSON.t index 1c2bc5e..da764fc 100644 --- a/t/OpenTelemetry/Exporter/OTLP/Encoder/JSON.t +++ b/t/OpenTelemetry/Exporter/OTLP/Encoder/JSON.t @@ -59,7 +59,7 @@ my $span_mock = mock 'Local::Span' => add => [ trace_state => sub { shift->{context}->trace_state }, ]; -is decode_json(CLASS->new->encode([ +my $encoded = CLASS->new->encode([ Local::Span->new( scope => $a_scope, name => 'A-A', @@ -80,7 +80,11 @@ is decode_json(CLASS->new->encode([ name => 'B-B', resource => $b_resource, ), -])), { +]); + +like $encoded, qr/"message":"[^"]*?"/, "Status description is a string"; + +is decode_json($encoded), { resourceSpans => array { prop size => 2; all_items {