const GRPC_STATUS_CODE_HEADER_NAME: &str = "grpc-status";
#[derive(Debug)]
pub(crate) enum ParsedStatusCodeError {
StatusHeaderMissing,
HeaderNotString,
HeaderNotInt,
}
pub(crate) fn get_status_code_from_headers(
header_map: &qcs_dependencies_client::http::header::HeaderMap,
) -> Result<qcs_dependencies_client::tonic::Code, ParsedStatusCodeError> {
header_map
.get(GRPC_STATUS_CODE_HEADER_NAME)
.ok_or(ParsedStatusCodeError::StatusHeaderMissing)
.and_then(|status| {
status
.to_str()
.map_err(|_| ParsedStatusCodeError::HeaderNotString)
})
.and_then(|status| {
status
.parse::<i32>()
.map_err(|_| ParsedStatusCodeError::HeaderNotInt)
})
.map(qcs_dependencies_client::tonic::Code::from)
}
#[cfg(feature = "tracing-opentelemetry")]
pub(super) fn pin_future_with_otel_context_if_available<F>(
fut: F,
) -> std::pin::Pin<Box<qcs_dependencies_client::opentelemetry::trace::WithContext<F>>> {
Box::pin(qcs_dependencies_client::opentelemetry::trace::FutureExt::with_current_context(fut))
}
#[cfg(not(feature = "tracing-opentelemetry"))]
pub(super) fn pin_future_with_otel_context_if_available<F>(fut: F) -> std::pin::Pin<Box<F>> {
Box::pin(fut)
}