diff --git a/opentelemetry-otlp/src/exporter/http/mod.rs b/opentelemetry-otlp/src/exporter/http/mod.rs index 340939e0fa..2fa3ff851b 100644 --- a/opentelemetry-otlp/src/exporter/http/mod.rs +++ b/opentelemetry-otlp/src/exporter/http/mod.rs @@ -11,6 +11,8 @@ use opentelemetry_http::HttpClient; use opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema; #[cfg(feature = "logs")] use opentelemetry_proto::transform::logs::tonic::group_logs_by_resource_and_scope; +#[cfg(feature = "trace")] +use opentelemetry_proto::transform::trace::tonic::group_spans_by_resource_and_scope; #[cfg(feature = "logs")] use opentelemetry_sdk::export::logs::LogData; #[cfg(feature = "trace")] @@ -308,16 +310,9 @@ impl OtlpHttpClient { fn build_trace_export_body( &self, spans: Vec, - resource: &opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema, ) -> opentelemetry::trace::TraceResult<(Vec, &'static str)> { - use opentelemetry_proto::tonic::{ - collector::trace::v1::ExportTraceServiceRequest, trace::v1::ResourceSpans, - }; - - let resource_spans = spans - .into_iter() - .map(|span| ResourceSpans::new(span, resource)) - .collect::>(); + use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest; + let resource_spans = group_spans_by_resource_and_scope(spans, &self.resource); let req = ExportTraceServiceRequest { resource_spans }; match self.protocol { diff --git a/opentelemetry-otlp/src/exporter/http/trace.rs b/opentelemetry-otlp/src/exporter/http/trace.rs index 8d6c3116cd..cc7894c266 100644 --- a/opentelemetry-otlp/src/exporter/http/trace.rs +++ b/opentelemetry-otlp/src/exporter/http/trace.rs @@ -21,7 +21,7 @@ impl SpanExporter for OtlpHttpClient { Err(err) => return Box::pin(std::future::ready(Err(err))), }; - let (body, content_type) = match self.build_trace_export_body(batch, &self.resource) { + let (body, content_type) = match self.build_trace_export_body(batch) { Ok(body) => body, Err(e) => return Box::pin(std::future::ready(Err(e))), };