From 26c150c8bee385184d26669701560f99245bb16d Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 24 Aug 2023 14:20:01 -0700 Subject: [PATCH] [chore] add error message on parsing bad protobuf response (#8283) Fixes #8282 --- exporter/otlphttpexporter/otlp.go | 6 +++--- exporter/otlphttpexporter/otlp_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/exporter/otlphttpexporter/otlp.go b/exporter/otlphttpexporter/otlp.go index 5d196372b37..b118b72f2a3 100644 --- a/exporter/otlphttpexporter/otlp.go +++ b/exporter/otlphttpexporter/otlp.go @@ -266,7 +266,7 @@ func tracesPartialSuccessHandler(protoBytes []byte, contentType string) error { exportResponse := ptraceotlp.NewExportResponse() err := exportResponse.UnmarshalProto(protoBytes) if err != nil { - return err + return fmt.Errorf("error parsing protobuf response: %w", err) } partialSuccess := exportResponse.PartialSuccess() if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedSpans() == 0) { @@ -282,7 +282,7 @@ func metricsPartialSuccessHandler(protoBytes []byte, contentType string) error { exportResponse := pmetricotlp.NewExportResponse() err := exportResponse.UnmarshalProto(protoBytes) if err != nil { - return err + return fmt.Errorf("error parsing protobuf response: %w", err) } partialSuccess := exportResponse.PartialSuccess() if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedDataPoints() == 0) { @@ -298,7 +298,7 @@ func logsPartialSuccessHandler(protoBytes []byte, contentType string) error { exportResponse := plogotlp.NewExportResponse() err := exportResponse.UnmarshalProto(protoBytes) if err != nil { - return err + return fmt.Errorf("error parsing protobuf response: %w", err) } partialSuccess := exportResponse.PartialSuccess() if !(partialSuccess.ErrorMessage() == "" && partialSuccess.RejectedLogRecords() == 0) { diff --git a/exporter/otlphttpexporter/otlp_test.go b/exporter/otlphttpexporter/otlp_test.go index f04ec8a6190..daa54d4b7ea 100644 --- a/exporter/otlphttpexporter/otlp_test.go +++ b/exporter/otlphttpexporter/otlp_test.go @@ -892,7 +892,7 @@ func TestPartialSuccessInvalidBody(t *testing.T) { for _, tt := range invalidBodyCases { t.Run("Invalid response body_"+tt.telemetryType, func(t *testing.T) { err := tt.handler([]byte{1}, "application/x-protobuf") - assert.Error(t, err) + assert.ErrorContains(t, err, "error parsing protobuf response:") }) } }