From d19187db46ec445143ecdc0271794f71dce3055d Mon Sep 17 00:00:00 2001 From: Mohammad Mustakim Ali Date: Thu, 1 Feb 2024 15:46:07 +0100 Subject: [PATCH] chore: Add error logging for failed OpenTelemetry HTTP export (#1498) Co-authored-by: Lalit Kumar Bhasin Co-authored-by: Cijo Thomas --- opentelemetry-otlp/src/exporter/http/logs.rs | 13 ++++++++++++- opentelemetry-otlp/src/exporter/http/trace.rs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/opentelemetry-otlp/src/exporter/http/logs.rs b/opentelemetry-otlp/src/exporter/http/logs.rs index 8f358c977d..6bb8b76493 100644 --- a/opentelemetry-otlp/src/exporter/http/logs.rs +++ b/opentelemetry-otlp/src/exporter/http/logs.rs @@ -31,7 +31,18 @@ impl LogExporter for OtlpHttpClient { request.headers_mut().insert(k.clone(), v.clone()); } - client.send(request).await?; + let request_uri = request.uri().to_string(); + let response = client.send(request).await?; + + if !response.status().is_success() { + let error = format!( + "OpenTelemetry logs export failed. Url: {}, Status Code: {}, Response: {:?}", + response.status().as_u16(), + request_uri, + response.body() + ); + return Err(LogError::Other(error.into())); + } Ok(()) } diff --git a/opentelemetry-otlp/src/exporter/http/trace.rs b/opentelemetry-otlp/src/exporter/http/trace.rs index cb368e1e72..e824978b57 100644 --- a/opentelemetry-otlp/src/exporter/http/trace.rs +++ b/opentelemetry-otlp/src/exporter/http/trace.rs @@ -46,7 +46,18 @@ impl SpanExporter for OtlpHttpClient { } Box::pin(async move { - client.send(request).await?; + let request_uri = request.uri().to_string(); + let response = client.send(request).await?; + + if !response.status().is_success() { + let error = format!( + "OpenTelemetry trace export failed. Url: {}, Status Code: {}, Response: {:?}", + response.status().as_u16(), + request_uri, + response.body() + ); + return Err(TraceError::Other(error.into())); + } Ok(()) })