Skip to content

fix: Improved logging for OTLP Tonic Exporter #3108

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions opentelemetry-otlp/src/exporter/tonic/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ impl LogExporter for TonicLogsClient {
let (m, e, _) = inner
.interceptor
.call(Request::new(()))
.map_err(|e| OTelSdkError::InternalFailure(format!("error: {e:?}")))?
.map_err(|e| {
otel_debug!(
name: "TonicLogsClient.InterceptorFailed",
grpc_code = format!("{:?}", e.code()),
grpc_message = e.message(),
grpc_details = format!("{:?}", e.details())
);
OTelSdkError::InternalFailure("Logs export failed in interceptor".into())
Copy link
Member

@lalitb lalitb Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we at least add the grpc_code here ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neutral to it..we already log it here. And upstream SDK would log again... I can add just the grpc_code alone to the failure message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add TODO to do selective error handling - i.e. return detailed info for non-auth errors

})?
.into_parts();
(inner.client.clone(), m, e)
}
Expand All @@ -88,9 +96,13 @@ impl LogExporter for TonicLogsClient {
Ok(())
}
Err(e) => {
let error = format!("export error: {e:?}");
otel_debug!(name: "TonicLogsClient.ExportFailed", error = &error);
Err(OTelSdkError::InternalFailure(error))
otel_debug!(
name: "TonicLogsClient.ExportFailed",
grpc_code = format!("{:?}", e.code()),
grpc_message = e.message(),
grpc_details = format!("{:?}", e.details())
);
Err(OTelSdkError::InternalFailure("Logs export failed".into()))
}
}
}
Expand Down
24 changes: 18 additions & 6 deletions opentelemetry-otlp/src/exporter/tonic/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ impl MetricsClient for TonicMetricsClient {
.interceptor
.call(Request::new(()))
.map_err(|e| {
OTelSdkError::InternalFailure(format!(
"unexpected status while exporting {e:?}"
))
otel_debug!(
name: "TonicMetricsClient.InterceptorFailed",
grpc_code = format!("{:?}", e.code()),
grpc_message = e.message(),
grpc_details = format!("{:?}", e.details())
);
OTelSdkError::InternalFailure(
"Metrics export failed in interceptor".into(),
)
})?
.into_parts();
Ok((inner.client.clone(), m, e))
Expand All @@ -91,9 +97,15 @@ impl MetricsClient for TonicMetricsClient {
Ok(())
}
Err(e) => {
let error = format!("{e:?}");
otel_debug!(name: "TonicMetricsClient.ExportFailed", error = &error);
Err(OTelSdkError::InternalFailure(error))
otel_debug!(
name: "TonicMetricsClient.ExportFailed",
grpc_code = format!("{:?}", e.code()),
grpc_message = e.message(),
grpc_details = format!("{:?}", e.details())
);
Err(OTelSdkError::InternalFailure(
"Metrics export failed".into(),
))
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions opentelemetry-otlp/src/exporter/tonic/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ impl SpanExporter for TonicTracesClient {
.lock()
.await // tokio::sync::Mutex doesn't return a poisoned error, so we can safely use the interceptor here
.call(Request::new(()))
.map_err(|e| OTelSdkError::InternalFailure(format!("error: {e:?}")))?
.map_err(|e| {
otel_debug!(
name: "TonicTracesClient.InterceptorFailed",
grpc_code = format!("{:?}", e.code()),
grpc_message = e.message(),
grpc_details = format!("{:?}", e.details())
);
OTelSdkError::InternalFailure("Traces export failed in interceptor".into())
})?
.into_parts();
(inner.client.clone(), m, e)
}
Expand All @@ -92,9 +100,13 @@ impl SpanExporter for TonicTracesClient {
Ok(())
}
Err(e) => {
let error = e.to_string();
otel_debug!(name: "TonicTracesClient.ExportFailed", error = &error);
Err(OTelSdkError::InternalFailure(error))
otel_debug!(
name: "TonicTracesClient.ExportFailed",
grpc_code = format!("{:?}", e.code()),
grpc_message = e.message(),
grpc_details = format!("{:?}", e.details())
);
Err(OTelSdkError::InternalFailure("Traces export failed".into()))
}
}
}
Expand Down
Loading