-
Notifications
You must be signed in to change notification settings - Fork 639
fix: OTLP logging improvements #3343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
97ebbaf
077b508
e32c996
3d9f3b1
55a6f20
104d788
03351c2
79c6d7a
ee681f4
7b658dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ use super::{ | |
| }; | ||
| use crate::{ExportConfig, Protocol, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS}; | ||
| use http::{HeaderName, HeaderValue, Uri}; | ||
| use opentelemetry::otel_debug; | ||
| use opentelemetry::{otel_debug, otel_warn}; | ||
| use opentelemetry_http::{Bytes, HttpClient}; | ||
| use opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema; | ||
| #[cfg(feature = "logs")] | ||
|
|
@@ -488,7 +488,17 @@ impl OtlpHttpClient { | |
|
|
||
| // Send request | ||
| let response = client.send_bytes(request).await.map_err(|e| { | ||
| HttpExportError::new(0, format!("Network error: {e:?}")) // Network error | ||
| otel_warn!( | ||
| name: "HttpClient.ExportFailed", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using the same event name
Maybe we could use different event names for better diagnosability:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did consider that and ended up with same one. I am not 100% happy with this either. I tried to distinguish between failures where we don't get a response at all and the ones where we get response, but it has status code indicating failure. But then realized that let me know if we should try to make this better or this is acceptable tradeoff. |
||
| url = request_uri.as_str() | ||
| ); | ||
| // Error details may contain sensitive information, | ||
| // so log them at debug level only. | ||
| otel_debug!( | ||
| name: "HttpClient.ExportFailedDetails", | ||
| error = format!("{e:?}") | ||
| ); | ||
| HttpExportError::new(0, "HTTP export failed".to_string()) | ||
| })?; | ||
|
|
||
| let status_code = response.status().as_u16(); | ||
|
|
@@ -499,12 +509,18 @@ impl OtlpHttpClient { | |
| .map(|s| s.to_string()); | ||
|
|
||
| if !response.status().is_success() { | ||
| let message = format!( | ||
| "HTTP export failed. Url: {}, Status: {}, Response: {:?}", | ||
| request_uri, | ||
| status_code, | ||
| response.body() | ||
| otel_warn!( | ||
| name: "HttpClient.ExportFailed", | ||
| status_code = status_code, | ||
| url = request_uri.as_str() | ||
| ); | ||
| // Response body may contain sensitive information, | ||
| // so log it at debug level only. | ||
| otel_debug!( | ||
| name: "HttpClient.ExportFailedDetails", | ||
| response_body = format!("{:?}", response.body()) | ||
| ); | ||
| let message = "HTTP export failed".to_string(); | ||
| return Err(match retry_after { | ||
| Some(retry_after) => { | ||
| HttpExportError::with_retry_after(status_code, retry_after, message) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,9 +85,18 @@ impl MetricsClient for TonicMetricsClient { | |
| .interceptor | ||
| .call(Request::new(())) | ||
| .map_err(|e| { | ||
| tonic::Status::internal(format!( | ||
| "unexpected status while exporting {e:?}" | ||
| )) | ||
| otel_warn!( | ||
| name: "TonicMetricsClient.InterceptorFailed", | ||
| grpc_code = format!("{:?}", e.code()) | ||
| ); | ||
| // grpc_message and grpc_details may contain sensitive information, | ||
| // so log them at debug level only. | ||
| otel_debug!( | ||
| name: "TonicMetricsClient.InterceptorFailedDetails", | ||
| grpc_message = e.message(), | ||
| grpc_details = format!("{:?}", e.details()) | ||
| ); | ||
| tonic::Status::internal("Metrics export failed in interceptor") | ||
| })? | ||
| .into_parts(); | ||
| Ok((inner.client.clone(), m, e)) | ||
|
|
@@ -127,9 +136,22 @@ impl MetricsClient for TonicMetricsClient { | |
| .await | ||
| { | ||
| Ok(_) => Ok(()), | ||
| Err(tonic_status) => Err(OTelSdkError::InternalFailure(format!( | ||
| "export error: {tonic_status:?}" | ||
| ))), | ||
| Err(tonic_status) => { | ||
| otel_warn!( | ||
| name: "TonicMetricsClient.ExportFailed", | ||
| grpc_code = format!("{:?}", tonic_status.code()) | ||
| ); | ||
| // grpc_message and grpc_details may contain sensitive information, | ||
| // so log them at debug level only. | ||
| otel_debug!( | ||
| name: "TonicMetricsClient.ExportFailedDetails", | ||
| grpc_message = tonic_status.message(), | ||
| grpc_details = format!("{:?}", tonic_status.details()) | ||
| ); | ||
| Err(OTelSdkError::InternalFailure( | ||
| "Metrics export failed".into(), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| )) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,8 +96,19 @@ impl SpanExporter for TonicTracesClient { | |
| .interceptor | ||
| .call(Request::new(())) | ||
| .map_err(|e| { | ||
| otel_warn!( | ||
| name: "TonicTracesClient.InterceptorFailed", | ||
| grpc_code = format!("{:?}", e.code()) | ||
| ); | ||
| // grpc_message and grpc_details may contain sensitive information, | ||
| // so log them at debug level only. | ||
| otel_debug!( | ||
| name: "TonicTracesClient.InterceptorFailedDetails", | ||
| grpc_message = e.message(), | ||
| grpc_details = format!("{:?}", e.details()) | ||
| ); | ||
| // Convert interceptor errors to tonic::Status for retry classification | ||
| tonic::Status::internal(format!("interceptor error: {e:?}")) | ||
| tonic::Status::internal("Traces export failed in interceptor") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| })? | ||
| .into_parts(); | ||
| Ok((inner.client.clone(), m, e)) | ||
|
|
@@ -140,9 +151,20 @@ impl SpanExporter for TonicTracesClient { | |
| .await | ||
| { | ||
| Ok(_) => Ok(()), | ||
| Err(tonic_status) => Err(OTelSdkError::InternalFailure(format!( | ||
| "export error: {tonic_status:?}" | ||
| ))), | ||
| Err(tonic_status) => { | ||
| otel_warn!( | ||
| name: "TonicTracesClient.ExportFailed", | ||
| grpc_code = format!("{:?}", tonic_status.code()) | ||
| ); | ||
| // grpc_message and grpc_details may contain sensitive information, | ||
| // so log them at debug level only. | ||
| otel_debug!( | ||
| name: "TonicTracesClient.ExportFailedDetails", | ||
| grpc_message = tonic_status.message(), | ||
| grpc_details = format!("{:?}", tonic_status.details()) | ||
| ); | ||
| Err(OTelSdkError::InternalFailure("Traces export failed".into())) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.