From 106ce5d24bb595a967043e143799a43b990b20d0 Mon Sep 17 00:00:00 2001 From: Lalit Date: Fri, 24 May 2024 00:38:01 -0700 Subject: [PATCH 1/9] initial commit --- .../src/proto/opentelemetry-proto | 2 +- .../benches/batch_span_processor.rs | 1 - opentelemetry-sdk/benches/context.rs | 2 ++ opentelemetry-sdk/benches/span_builder.rs | 2 ++ opentelemetry-sdk/benches/trace.rs | 2 ++ opentelemetry-sdk/src/export/trace.rs | 5 ++-- .../src/testing/trace/in_memory_exporter.rs | 8 +++++ .../src/testing/trace/span_exporters.rs | 10 +++++-- opentelemetry-sdk/src/trace/provider.rs | 17 ++++++++--- opentelemetry-sdk/src/trace/runtime_tests.rs | 3 ++ opentelemetry-sdk/src/trace/span.rs | 10 ++----- opentelemetry-sdk/src/trace/span_processor.rs | 29 +++++++++++++++++-- 12 files changed, 69 insertions(+), 22 deletions(-) diff --git a/opentelemetry-proto/src/proto/opentelemetry-proto b/opentelemetry-proto/src/proto/opentelemetry-proto index b3060d2104..39339ef177 160000 --- a/opentelemetry-proto/src/proto/opentelemetry-proto +++ b/opentelemetry-proto/src/proto/opentelemetry-proto @@ -1 +1 @@ -Subproject commit b3060d2104df364136d75a35779e6bd48bac449a +Subproject commit 39339ef177218cc965b8cf863d761775ec668858 diff --git a/opentelemetry-sdk/benches/batch_span_processor.rs b/opentelemetry-sdk/benches/batch_span_processor.rs index 7b6c096f4e..e111792720 100644 --- a/opentelemetry-sdk/benches/batch_span_processor.rs +++ b/opentelemetry-sdk/benches/batch_span_processor.rs @@ -34,7 +34,6 @@ fn get_span_data() -> Vec { events: SpanEvents::default(), links: SpanLinks::default(), status: Status::Unset, - resource: Cow::Owned(Resource::empty()), instrumentation_lib: Default::default(), }) .collect::>() diff --git a/opentelemetry-sdk/benches/context.rs b/opentelemetry-sdk/benches/context.rs index f5a1f7e2df..f2932e11d7 100644 --- a/opentelemetry-sdk/benches/context.rs +++ b/opentelemetry-sdk/benches/context.rs @@ -140,6 +140,8 @@ impl SpanExporter for NoopExporter { fn export(&mut self, _spans: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(futures_util::future::ready(Ok(()))) } + + fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } #[cfg(not(target_os = "windows"))] diff --git a/opentelemetry-sdk/benches/span_builder.rs b/opentelemetry-sdk/benches/span_builder.rs index de5c1fd235..54cea7684e 100644 --- a/opentelemetry-sdk/benches/span_builder.rs +++ b/opentelemetry-sdk/benches/span_builder.rs @@ -68,6 +68,8 @@ impl SpanExporter for NoopExporter { fn export(&mut self, _spans: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(futures_util::future::ready(Ok(()))) } + + fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } const MAP_KEYS: [&str; 64] = [ diff --git a/opentelemetry-sdk/benches/trace.rs b/opentelemetry-sdk/benches/trace.rs index 93bdf3859a..a51a5cfda5 100644 --- a/opentelemetry-sdk/benches/trace.rs +++ b/opentelemetry-sdk/benches/trace.rs @@ -63,6 +63,8 @@ impl SpanExporter for VoidExporter { fn export(&mut self, _spans: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(futures_util::future::ready(Ok(()))) } + + fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } fn trace_benchmark_group(c: &mut Criterion, name: &str, f: F) { diff --git a/opentelemetry-sdk/src/export/trace.rs b/opentelemetry-sdk/src/export/trace.rs index b3d99c9a13..9dfa986009 100644 --- a/opentelemetry-sdk/src/export/trace.rs +++ b/opentelemetry-sdk/src/export/trace.rs @@ -63,6 +63,9 @@ pub trait SpanExporter: Send + Sync + Debug { fn force_flush(&mut self) -> BoxFuture<'static, ExportResult> { Box::pin(async { Ok(()) }) } + + /// Set the resource for the exporter. + fn set_resource(&mut self, _resource: &Resource); } /// `SpanData` contains all the information collected by a `Span` and can be used @@ -92,8 +95,6 @@ pub struct SpanData { pub links: crate::trace::SpanLinks, /// Span status pub status: Status, - /// Resource contains attributes representing an entity that produced this span. - pub resource: Cow<'static, Resource>, /// Instrumentation library that produced this span pub instrumentation_lib: crate::InstrumentationLibrary, } diff --git a/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs index d10a4c1922..b2f9d7616b 100644 --- a/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs @@ -1,4 +1,5 @@ use crate::export::trace::{ExportResult, SpanData, SpanExporter}; +use crate::resource::Resource; use futures_util::future::BoxFuture; use opentelemetry::trace::{TraceError, TraceResult}; use std::sync::{Arc, Mutex}; @@ -51,6 +52,7 @@ use std::sync::{Arc, Mutex}; #[derive(Clone, Debug)] pub struct InMemorySpanExporter { spans: Arc>>, + resource: Arc>, } impl Default for InMemorySpanExporter { @@ -85,6 +87,7 @@ impl InMemorySpanExporterBuilder { pub fn build(&self) -> InMemorySpanExporter { InMemorySpanExporter { spans: Arc::new(Mutex::new(Vec::new())), + resource: Arc::new(Mutex::new(Resource::default())), } } } @@ -142,4 +145,9 @@ impl SpanExporter for InMemorySpanExporter { fn shutdown(&mut self) { self.reset() } + + fn set_resource(&mut self, resource: &Resource) { + let mut res_guard = self.resource.lock().expect("Resource lock poisoned"); + *res_guard = resource.clone(); + } } diff --git a/opentelemetry-sdk/src/testing/trace/span_exporters.rs b/opentelemetry-sdk/src/testing/trace/span_exporters.rs index 48ea2c6b43..263668fbcd 100644 --- a/opentelemetry-sdk/src/testing/trace/span_exporters.rs +++ b/opentelemetry-sdk/src/testing/trace/span_exporters.rs @@ -3,7 +3,8 @@ use crate::{ trace::{ExportResult, SpanData, SpanExporter}, ExportError, }, - trace::{Config, SpanEvents, SpanLinks}, + resource::Resource, + trace::{SpanEvents, SpanLinks}, InstrumentationLibrary, }; use futures_util::future::BoxFuture; @@ -14,7 +15,6 @@ use opentelemetry::trace::{ use std::fmt::{Display, Formatter}; pub fn new_test_export_span_data() -> SpanData { - let config = Config::default(); SpanData { span_context: SpanContext::new( TraceId::from_u128(1), @@ -33,7 +33,6 @@ pub fn new_test_export_span_data() -> SpanData { events: SpanEvents::default(), links: SpanLinks::default(), status: Status::Unset, - resource: config.resource, instrumentation_lib: InstrumentationLibrary::default(), } } @@ -61,6 +60,8 @@ impl SpanExporter for TokioSpanExporter { fn shutdown(&mut self) { self.tx_shutdown.send(()).unwrap(); } + + fn set_resource(&mut self, _resource: &crate::Resource) {} } pub fn new_tokio_test_exporter() -> ( @@ -121,4 +122,7 @@ impl SpanExporter for NoopSpanExporter { fn export(&mut self, _: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(std::future::ready(Ok(()))) } + + /// Set the resource for the exporter. + fn set_resource(&mut self, _resource: &Resource) {} } diff --git a/opentelemetry-sdk/src/trace/provider.rs b/opentelemetry-sdk/src/trace/provider.rs index 1fbe22d628..d988e6dd36 100644 --- a/opentelemetry-sdk/src/trace/provider.rs +++ b/opentelemetry-sdk/src/trace/provider.rs @@ -218,11 +218,16 @@ impl Builder { } } + // Create a new vector to hold the modified processors + let mut processors = self.processors; + + // Set the resource for each processor + for p in &mut processors { + p.set_resource(config.resource.as_ref()); + } + TracerProvider { - inner: Arc::new(TracerProviderInner { - processors: self.processors, - config, - }), + inner: Arc::new(TracerProviderInner { processors, config }), } } } @@ -267,6 +272,10 @@ mod tests { fn shutdown(&mut self) -> TraceResult<()> { self.force_flush() } + + fn set_resource(&mut self, _: &Resource) { + unimplemented!() + } } #[test] diff --git a/opentelemetry-sdk/src/trace/runtime_tests.rs b/opentelemetry-sdk/src/trace/runtime_tests.rs index 610d140b7a..66627f1bfb 100644 --- a/opentelemetry-sdk/src/trace/runtime_tests.rs +++ b/opentelemetry-sdk/src/trace/runtime_tests.rs @@ -2,6 +2,7 @@ // need to run those tests one by one as the GlobalTracerProvider is a shared object between // threads Use cargo test -- --ignored --test-threads=1 to run those tests. use crate::export::trace::{ExportResult, SpanExporter}; +use crate::resource::Resource; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use crate::runtime; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] @@ -28,6 +29,8 @@ impl SpanExporter for SpanCountExporter { self.span_count.fetch_add(batch.len(), Ordering::SeqCst); Box::pin(async { Ok(()) }) } + + fn set_resource(&mut self, _: &Resource) {} } #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] diff --git a/opentelemetry-sdk/src/trace/span.rs b/opentelemetry-sdk/src/trace/span.rs index 2ff3079cda..df45714cae 100644 --- a/opentelemetry-sdk/src/trace/span.rs +++ b/opentelemetry-sdk/src/trace/span.rs @@ -9,7 +9,6 @@ //! is possible to change its name, set its `Attributes`, and add `Links` and `Events`. //! These cannot be changed after the `Span`'s end time has been set. use crate::trace::SpanLimits; -use crate::Resource; use opentelemetry::trace::{Event, Link, SpanContext, SpanId, SpanKind, Status}; use opentelemetry::KeyValue; use std::borrow::Cow; @@ -77,11 +76,11 @@ impl Span { /// overhead. pub fn exported_data(&self) -> Option { let (span_context, tracer) = (self.span_context.clone(), &self.tracer); - let resource = self.tracer.provider()?.config().resource.clone(); + //let resource = self.tracer.provider()?.config().resource.clone(); self.data .as_ref() - .map(|data| build_export_data(data.clone(), span_context, resource, tracer)) + .map(|data| build_export_data(data.clone(), span_context, tracer)) } } @@ -225,17 +224,14 @@ impl Span { processor.on_end(build_export_data( data, self.span_context.clone(), - provider.config().resource.clone(), &self.tracer, )); } processors => { - let config = provider.config(); for processor in processors { processor.on_end(build_export_data( data.clone(), self.span_context.clone(), - config.resource.clone(), &self.tracer, )); } @@ -254,7 +250,6 @@ impl Drop for Span { fn build_export_data( data: SpanData, span_context: SpanContext, - resource: Cow<'static, Resource>, tracer: &crate::trace::Tracer, ) -> crate::export::trace::SpanData { crate::export::trace::SpanData { @@ -269,7 +264,6 @@ fn build_export_data( events: data.events, links: data.links, status: data.status, - resource, instrumentation_lib: tracer.instrumentation_library().clone(), } } diff --git a/opentelemetry-sdk/src/trace/span_processor.rs b/opentelemetry-sdk/src/trace/span_processor.rs index ac24cff1b0..43a1e5c9de 100644 --- a/opentelemetry-sdk/src/trace/span_processor.rs +++ b/opentelemetry-sdk/src/trace/span_processor.rs @@ -35,6 +35,7 @@ //! [`TracerProvider`]: opentelemetry::trace::TracerProvider use crate::export::trace::{ExportResult, SpanData, SpanExporter}; +use crate::resource::Resource; use crate::runtime::{RuntimeChannel, TrySend}; use crate::trace::Span; use futures_channel::oneshot; @@ -50,7 +51,7 @@ use opentelemetry::{ Context, }; use std::cmp::min; -use std::sync::Mutex; +use std::sync::{Arc, Mutex}; use std::{env, fmt, str::FromStr, time::Duration}; /// Delay interval between two consecutive exports. @@ -92,6 +93,8 @@ pub trait SpanProcessor: Send + Sync + std::fmt::Debug { /// Shuts down the processor. Called when SDK is shut down. This is an /// opportunity for processors to do any cleanup required. fn shutdown(&mut self) -> TraceResult<()>; + /// Set the resource for the log processor. + fn set_resource(&mut self, _resource: &Resource); } /// A [SpanProcessor] that passes finished spans to the configured @@ -147,6 +150,12 @@ impl SpanProcessor for SimpleSpanProcessor { )) } } + + fn set_resource(&mut self, resource: &Resource) { + if let Ok(mut exporter) = self.exporter.lock() { + exporter.set_resource(resource); + } + } } /// A [`SpanProcessor`] that asynchronously buffers finished spans and reports @@ -259,6 +268,13 @@ impl SpanProcessor for BatchSpanProcessor { .map_err(|err| TraceError::Other(err.into())) .and_then(|identity| identity) } + + fn set_resource(&mut self, resource: &Resource) { + let resource = Arc::new(resource.clone()); + let _ = self + .message_sender + .try_send(BatchMessage::SetResource(resource)); + } } /// Messages sent between application thread and batch span processor's work thread. @@ -275,6 +291,8 @@ enum BatchMessage { Flush(Option>), /// Shut down the worker thread, push all spans in buffer to the backend. Shutdown(oneshot::Sender), + /// Set the resource for the exporter. + SetResource(Arc), } struct BatchSpanProcessorInternal { @@ -375,8 +393,11 @@ impl BatchSpanProcessorInternal { self.exporter.shutdown(); return false; } + // propagate the resource + BatchMessage::SetResource(resource) => { + self.exporter.set_resource(&resource); + } } - true } @@ -669,6 +690,7 @@ mod tests { OTEL_BSP_SCHEDULE_DELAY, OTEL_BSP_SCHEDULE_DELAY_DEFAULT, }; use crate::export::trace::{ExportResult, SpanData, SpanExporter}; + use crate::resource::Resource; use crate::runtime; use crate::testing::trace::{ new_test_export_span_data, new_tokio_test_exporter, InMemorySpanExporterBuilder, @@ -710,7 +732,6 @@ mod tests { events: SpanEvents::default(), links: SpanLinks::default(), status: Status::Unset, - resource: Default::default(), instrumentation_lib: Default::default(), }; processor.on_end(unsampled); @@ -928,6 +949,8 @@ mod tests { use futures_util::FutureExt; Box::pin((self.delay_fn)(self.delay_for).map(|_| Ok(()))) } + + fn set_resource(&mut self, _resource: &Resource) {} } #[test] From 34f5e979ff14dff8234913eb3ecdd7ccbeb530eb Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Fri, 24 May 2024 10:24:49 -0700 Subject: [PATCH 2/9] initial commit --- opentelemetry-otlp/src/exporter/http/mod.rs | 10 ++++++--- opentelemetry-otlp/src/exporter/http/trace.rs | 6 +++++- opentelemetry-otlp/src/exporter/tonic/logs.rs | 2 +- .../src/exporter/tonic/trace.rs | 21 ++++++++++++++++--- opentelemetry-otlp/src/span.rs | 4 ++++ opentelemetry-proto/src/transform/trace.rs | 14 +++++-------- opentelemetry-stdout/src/trace/exporter.rs | 13 +++++++++++- opentelemetry-stdout/src/trace/transform.rs | 20 +++++++++++++----- opentelemetry-zipkin/src/exporter/mod.rs | 2 ++ .../src/exporter/model/span.rs | 4 +--- stress/src/traces.rs | 2 ++ 11 files changed, 72 insertions(+), 26 deletions(-) diff --git a/opentelemetry-otlp/src/exporter/http/mod.rs b/opentelemetry-otlp/src/exporter/http/mod.rs index a5ced848d4..04d3e8f520 100644 --- a/opentelemetry-otlp/src/exporter/http/mod.rs +++ b/opentelemetry-otlp/src/exporter/http/mod.rs @@ -307,12 +307,16 @@ 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; - let req = ExportTraceServiceRequest { - resource_spans: spans.into_iter().map(Into::into).collect(), - }; + let resource_spans = spans + .into_iter() + .map(|log_event| (log_event, resource).into()) + .collect::>(); + + let req = ExportTraceServiceRequest { resource_spans }; match self.protocol { #[cfg(feature = "http-json")] Protocol::HttpJson => match serde_json::to_string_pretty(&req) { diff --git a/opentelemetry-otlp/src/exporter/http/trace.rs b/opentelemetry-otlp/src/exporter/http/trace.rs index 8e272c93cf..8d6c3116cd 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) { + let (body, content_type) = match self.build_trace_export_body(batch, &self.resource) { Ok(body) => body, Err(e) => return Box::pin(std::future::ready(Err(e))), }; @@ -66,4 +66,8 @@ impl SpanExporter for OtlpHttpClient { fn shutdown(&mut self) { let _ = self.client.lock().map(|mut c| c.take()); } + + fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) { + self.resource = resource.into(); + } } diff --git a/opentelemetry-otlp/src/exporter/tonic/logs.rs b/opentelemetry-otlp/src/exporter/tonic/logs.rs index 8a6637a5b0..6cefd611ff 100644 --- a/opentelemetry-otlp/src/exporter/tonic/logs.rs +++ b/opentelemetry-otlp/src/exporter/tonic/logs.rs @@ -12,7 +12,7 @@ use super::BoxInterceptor; pub(crate) struct TonicLogsClient { inner: Option, #[allow(dead_code)] - // would be removed once we support set_resource for metrics and traces. + // would be removed once we support set_resource for metrics. resource: opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema, } diff --git a/opentelemetry-otlp/src/exporter/tonic/trace.rs b/opentelemetry-otlp/src/exporter/tonic/trace.rs index b328dfba5f..803d14626f 100644 --- a/opentelemetry-otlp/src/exporter/tonic/trace.rs +++ b/opentelemetry-otlp/src/exporter/tonic/trace.rs @@ -12,6 +12,9 @@ use super::BoxInterceptor; pub(crate) struct TonicTracesClient { inner: Option, + #[allow(dead_code)] + // would be removed once we support set_resource for metrics. + resource: opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema, } struct ClientInner { @@ -43,6 +46,7 @@ impl TonicTracesClient { client, interceptor, }), + resource: Default::default(), } } } @@ -66,14 +70,21 @@ impl SpanExporter for TonicTracesClient { } }; + // TODO: Avoid cloning here. + let resource_spans = { + batch + .into_iter() + .map(|log_data| (log_data, &self.resource)) + .map(Into::into) + .collect() + }; + Box::pin(async move { client .export(Request::from_parts( metadata, extensions, - ExportTraceServiceRequest { - resource_spans: batch.into_iter().map(Into::into).collect(), - }, + ExportTraceServiceRequest { resource_spans }, )) .await .map_err(crate::Error::from)?; @@ -85,4 +96,8 @@ impl SpanExporter for TonicTracesClient { fn shutdown(&mut self) { let _ = self.inner.take(); } + + fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) { + self.resource = resource.into(); + } } diff --git a/opentelemetry-otlp/src/span.rs b/opentelemetry-otlp/src/span.rs index 4b658a89e2..34aafd4734 100644 --- a/opentelemetry-otlp/src/span.rs +++ b/opentelemetry-otlp/src/span.rs @@ -227,4 +227,8 @@ impl opentelemetry_sdk::export::trace::SpanExporter for SpanExporter { fn export(&mut self, batch: Vec) -> BoxFuture<'static, ExportResult> { self.0.export(batch) } + + fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) { + self.0.set_resource(resource); + } } diff --git a/opentelemetry-proto/src/transform/trace.rs b/opentelemetry-proto/src/transform/trace.rs index 77f4f18de2..74ddc0cf32 100644 --- a/opentelemetry-proto/src/transform/trace.rs +++ b/opentelemetry-proto/src/transform/trace.rs @@ -4,7 +4,7 @@ pub mod tonic { use crate::proto::tonic::trace::v1::{span, status, ResourceSpans, ScopeSpans, Span, Status}; use crate::transform::common::{ to_nanos, - tonic::{resource_attributes, Attributes}, + tonic::{Attributes, ResourceAttributesWithSchema}, }; use opentelemetry::trace; use opentelemetry::trace::{Link, SpanId, SpanKind}; @@ -45,19 +45,15 @@ pub mod tonic { } } - impl From for ResourceSpans { - fn from(source_span: SpanData) -> Self { + impl From<(SpanData, &ResourceAttributesWithSchema)> for ResourceSpans { + fn from((source_span, resource): (SpanData, &ResourceAttributesWithSchema)) -> Self { let span_kind: span::SpanKind = source_span.span_kind.into(); ResourceSpans { resource: Some(Resource { - attributes: resource_attributes(&source_span.resource).0, + attributes: resource.attributes.0.clone(), dropped_attributes_count: 0, }), - schema_url: source_span - .resource - .schema_url() - .map(|url| url.to_string()) - .unwrap_or_default(), + schema_url: resource.schema_url.clone().unwrap_or_default(), scope_spans: vec![ScopeSpans { schema_url: source_span .instrumentation_lib diff --git a/opentelemetry-stdout/src/trace/exporter.rs b/opentelemetry-stdout/src/trace/exporter.rs index 774920267a..e0d67d0b50 100644 --- a/opentelemetry-stdout/src/trace/exporter.rs +++ b/opentelemetry-stdout/src/trace/exporter.rs @@ -5,6 +5,7 @@ use opentelemetry_sdk::export::{self, trace::ExportResult}; use std::io::{stdout, Write}; use crate::trace::transform::SpanData; +use opentelemetry_sdk::resource::Resource; type Encoder = Box TraceResult<()> + Send + Sync>; @@ -12,6 +13,7 @@ type Encoder = Box TraceResult<()> + Send + pub struct SpanExporter { writer: Option>, encoder: Encoder, + resource: Resource, } impl fmt::Debug for SpanExporter { @@ -36,7 +38,11 @@ impl Default for SpanExporter { impl opentelemetry_sdk::export::trace::SpanExporter for SpanExporter { fn export(&mut self, batch: Vec) -> BoxFuture<'static, ExportResult> { let res = if let Some(writer) = &mut self.writer { - (self.encoder)(writer, crate::trace::SpanData::from(batch)).and_then(|_| { + (self.encoder)( + writer, + crate::trace::SpanData::from((batch, &self.resource)), + ) + .and_then(|_| { writer .write_all(b"\n") .map_err(|err| TraceError::Other(Box::new(err))) @@ -51,6 +57,10 @@ impl opentelemetry_sdk::export::trace::SpanExporter for SpanExporter { fn shutdown(&mut self) { self.writer.take(); } + + fn set_resource(&mut self, res: &opentelemetry_sdk::Resource) { + self.resource = res.clone(); + } } /// Configuration for the stdout trace exporter @@ -107,6 +117,7 @@ impl SpanExporterBuilder { pub fn build(self) -> SpanExporter { SpanExporter { writer: Some(self.writer.unwrap_or_else(|| Box::new(stdout()))), + resource: Resource::default(), encoder: self.encoder.unwrap_or_else(|| { Box::new(|writer, spans| { serde_json::to_writer(writer, &spans) diff --git a/opentelemetry-stdout/src/trace/transform.rs b/opentelemetry-stdout/src/trace/transform.rs index 66a659de07..7c0903cbc6 100644 --- a/opentelemetry-stdout/src/trace/transform.rs +++ b/opentelemetry-stdout/src/trace/transform.rs @@ -9,17 +9,27 @@ pub struct SpanData { resource_spans: Vec, } -impl From> for SpanData { - fn from(sdk_spans: Vec) -> Self { +impl + From<( + Vec, + &opentelemetry_sdk::Resource, + )> for SpanData +{ + fn from( + (sdk_spans, sdk_resource): ( + Vec, + &opentelemetry_sdk::Resource, + ), + ) -> Self { let mut resource_spans = HashMap::::new(); for sdk_span in sdk_spans { - let resource_schema_url = sdk_span.resource.schema_url().map(|s| s.to_string().into()); + let resource_schema_url = sdk_resource.schema_url().map(|s| s.to_string().into()); let schema_url = sdk_span.instrumentation_lib.schema_url.clone(); let scope = sdk_span.instrumentation_lib.clone().into(); - let resource = sdk_span.resource.as_ref().into(); + let resource: Resource = sdk_resource.into(); let rs = resource_spans - .entry(sdk_span.resource.as_ref().into()) + .entry(sdk_resource.into()) .or_insert_with(move || ResourceSpans { resource, scope_spans: Vec::with_capacity(1), diff --git a/opentelemetry-zipkin/src/exporter/mod.rs b/opentelemetry-zipkin/src/exporter/mod.rs index 0bd2d19016..15dfdd3ce6 100644 --- a/opentelemetry-zipkin/src/exporter/mod.rs +++ b/opentelemetry-zipkin/src/exporter/mod.rs @@ -231,6 +231,8 @@ impl trace::SpanExporter for Exporter { self.local_endpoint.clone(), )) } + + fn set_resource(&mut self, _resource: &Resource) {} } /// Wrap type for errors from opentelemetry zipkin diff --git a/opentelemetry-zipkin/src/exporter/model/span.rs b/opentelemetry-zipkin/src/exporter/model/span.rs index 6e21b52588..8c9c7fd5a1 100644 --- a/opentelemetry-zipkin/src/exporter/model/span.rs +++ b/opentelemetry-zipkin/src/exporter/model/span.rs @@ -60,9 +60,8 @@ mod tests { use crate::exporter::model::span::{Kind, Span}; use crate::exporter::model::{into_zipkin_span, OTEL_ERROR_DESCRIPTION, OTEL_STATUS_CODE}; use opentelemetry::trace::{SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId}; + use opentelemetry_sdk::export::trace::SpanData; use opentelemetry_sdk::trace::{SpanEvents, SpanLinks}; - use opentelemetry_sdk::{export::trace::SpanData, Resource}; - use std::borrow::Cow; use std::collections::HashMap; use std::net::Ipv4Addr; use std::time::SystemTime; @@ -166,7 +165,6 @@ mod tests { events: SpanEvents::default(), links: SpanLinks::default(), status, - resource: Cow::Owned(Resource::default()), instrumentation_lib: Default::default(), }; let local_endpoint = Endpoint::new("test".into(), None); diff --git a/stress/src/traces.rs b/stress/src/traces.rs index 0dd992f708..c1c8872f50 100644 --- a/stress/src/traces.rs +++ b/stress/src/traces.rs @@ -45,6 +45,8 @@ impl SpanProcessor for NoOpSpanProcessor { fn shutdown(&mut self) -> TraceResult<()> { Ok(()) } + + fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } fn main() { From 401bfa525787c02ad11bd38ba02159ade3e14fb7 Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 28 May 2024 18:40:30 -0700 Subject: [PATCH 3/9] fix comments --- opentelemetry-sdk/benches/context.rs | 2 -- opentelemetry-sdk/benches/span_builder.rs | 2 -- opentelemetry-sdk/benches/trace.rs | 2 -- opentelemetry-sdk/src/export/trace.rs | 2 +- opentelemetry-sdk/src/testing/trace/span_exporters.rs | 5 ----- opentelemetry-sdk/src/trace/runtime_tests.rs | 2 -- opentelemetry-sdk/src/trace/span_processor.rs | 4 +--- opentelemetry-zipkin/src/exporter/mod.rs | 2 -- stress/src/traces.rs | 2 -- 9 files changed, 2 insertions(+), 21 deletions(-) diff --git a/opentelemetry-sdk/benches/context.rs b/opentelemetry-sdk/benches/context.rs index f2932e11d7..f5a1f7e2df 100644 --- a/opentelemetry-sdk/benches/context.rs +++ b/opentelemetry-sdk/benches/context.rs @@ -140,8 +140,6 @@ impl SpanExporter for NoopExporter { fn export(&mut self, _spans: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(futures_util::future::ready(Ok(()))) } - - fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } #[cfg(not(target_os = "windows"))] diff --git a/opentelemetry-sdk/benches/span_builder.rs b/opentelemetry-sdk/benches/span_builder.rs index 54cea7684e..de5c1fd235 100644 --- a/opentelemetry-sdk/benches/span_builder.rs +++ b/opentelemetry-sdk/benches/span_builder.rs @@ -68,8 +68,6 @@ impl SpanExporter for NoopExporter { fn export(&mut self, _spans: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(futures_util::future::ready(Ok(()))) } - - fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } const MAP_KEYS: [&str; 64] = [ diff --git a/opentelemetry-sdk/benches/trace.rs b/opentelemetry-sdk/benches/trace.rs index a51a5cfda5..93bdf3859a 100644 --- a/opentelemetry-sdk/benches/trace.rs +++ b/opentelemetry-sdk/benches/trace.rs @@ -63,8 +63,6 @@ impl SpanExporter for VoidExporter { fn export(&mut self, _spans: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(futures_util::future::ready(Ok(()))) } - - fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } fn trace_benchmark_group(c: &mut Criterion, name: &str, f: F) { diff --git a/opentelemetry-sdk/src/export/trace.rs b/opentelemetry-sdk/src/export/trace.rs index 9dfa986009..4b43e00c36 100644 --- a/opentelemetry-sdk/src/export/trace.rs +++ b/opentelemetry-sdk/src/export/trace.rs @@ -65,7 +65,7 @@ pub trait SpanExporter: Send + Sync + Debug { } /// Set the resource for the exporter. - fn set_resource(&mut self, _resource: &Resource); + fn set_resource(&mut self, _resource: &Resource) {} } /// `SpanData` contains all the information collected by a `Span` and can be used diff --git a/opentelemetry-sdk/src/testing/trace/span_exporters.rs b/opentelemetry-sdk/src/testing/trace/span_exporters.rs index 263668fbcd..33346c524f 100644 --- a/opentelemetry-sdk/src/testing/trace/span_exporters.rs +++ b/opentelemetry-sdk/src/testing/trace/span_exporters.rs @@ -60,8 +60,6 @@ impl SpanExporter for TokioSpanExporter { fn shutdown(&mut self) { self.tx_shutdown.send(()).unwrap(); } - - fn set_resource(&mut self, _resource: &crate::Resource) {} } pub fn new_tokio_test_exporter() -> ( @@ -122,7 +120,4 @@ impl SpanExporter for NoopSpanExporter { fn export(&mut self, _: Vec) -> BoxFuture<'static, ExportResult> { Box::pin(std::future::ready(Ok(()))) } - - /// Set the resource for the exporter. - fn set_resource(&mut self, _resource: &Resource) {} } diff --git a/opentelemetry-sdk/src/trace/runtime_tests.rs b/opentelemetry-sdk/src/trace/runtime_tests.rs index 66627f1bfb..1874dadf96 100644 --- a/opentelemetry-sdk/src/trace/runtime_tests.rs +++ b/opentelemetry-sdk/src/trace/runtime_tests.rs @@ -29,8 +29,6 @@ impl SpanExporter for SpanCountExporter { self.span_count.fetch_add(batch.len(), Ordering::SeqCst); Box::pin(async { Ok(()) }) } - - fn set_resource(&mut self, _: &Resource) {} } #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] diff --git a/opentelemetry-sdk/src/trace/span_processor.rs b/opentelemetry-sdk/src/trace/span_processor.rs index d038e2908f..082e86d117 100644 --- a/opentelemetry-sdk/src/trace/span_processor.rs +++ b/opentelemetry-sdk/src/trace/span_processor.rs @@ -94,7 +94,7 @@ pub trait SpanProcessor: Send + Sync + std::fmt::Debug { /// opportunity for processors to do any cleanup required. fn shutdown(&self) -> TraceResult<()>; /// Set the resource for the log processor. - fn set_resource(&mut self, _resource: &Resource); + fn set_resource(&mut self, _resource: &Resource) {} } /// A [SpanProcessor] that passes finished spans to the configured @@ -949,8 +949,6 @@ mod tests { use futures_util::FutureExt; Box::pin((self.delay_fn)(self.delay_for).map(|_| Ok(()))) } - - fn set_resource(&mut self, _resource: &Resource) {} } #[test] diff --git a/opentelemetry-zipkin/src/exporter/mod.rs b/opentelemetry-zipkin/src/exporter/mod.rs index 15dfdd3ce6..0bd2d19016 100644 --- a/opentelemetry-zipkin/src/exporter/mod.rs +++ b/opentelemetry-zipkin/src/exporter/mod.rs @@ -231,8 +231,6 @@ impl trace::SpanExporter for Exporter { self.local_endpoint.clone(), )) } - - fn set_resource(&mut self, _resource: &Resource) {} } /// Wrap type for errors from opentelemetry zipkin diff --git a/stress/src/traces.rs b/stress/src/traces.rs index a6583d6077..9f9065d1a5 100644 --- a/stress/src/traces.rs +++ b/stress/src/traces.rs @@ -45,8 +45,6 @@ impl SpanProcessor for NoOpSpanProcessor { fn shutdown(&self) -> TraceResult<()> { Ok(()) } - - fn set_resource(&mut self, _resource: &opentelemetry_sdk::Resource) {} } fn main() { From 90f5554e8c8e12c458d889676654056f96b8d073 Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 28 May 2024 18:41:51 -0700 Subject: [PATCH 4/9] lint --- opentelemetry-sdk/src/testing/trace/span_exporters.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/opentelemetry-sdk/src/testing/trace/span_exporters.rs b/opentelemetry-sdk/src/testing/trace/span_exporters.rs index 33346c524f..c92a64f399 100644 --- a/opentelemetry-sdk/src/testing/trace/span_exporters.rs +++ b/opentelemetry-sdk/src/testing/trace/span_exporters.rs @@ -3,7 +3,6 @@ use crate::{ trace::{ExportResult, SpanData, SpanExporter}, ExportError, }, - resource::Resource, trace::{SpanEvents, SpanLinks}, InstrumentationLibrary, }; From 300d6d0806ae5ab8bcd9cc68b256a4d6b19257f8 Mon Sep 17 00:00:00 2001 From: Lalit Date: Tue, 28 May 2024 18:52:27 -0700 Subject: [PATCH 5/9] fix test --- opentelemetry-sdk/CHANGELOG.md | 9 +++++++++ opentelemetry-sdk/src/trace/runtime_tests.rs | 1 - opentelemetry-sdk/src/trace/span_processor.rs | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index ff0fa8cdb8..ccd7fd1e36 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -28,6 +28,15 @@ asynchronously, it should clone the log data to ensure it can be safely processed without lifetime issues. +- **Breaking** [#1830](https://github.com/open-telemetry/opentelemetry-rust/pull/1830/files) [Traces SDK] Improves + performance by sending Resource information to processors (and exporters) once, instead of sending with every log. If you are an author + of Processor, Exporter, the following are *BREAKING* changes. + - Implement `set_resource` method in your custom SpanProcessor, which invokes exporter's `set_resource`. + - Implement `set_resource` method in your custom SpanExporter. This method should save the resource object + in original or serialized format, to be merged with every span event during export. + - `SpanData` doesn't have the resource attributes. The `SpanExporter::export()` method needs to merge it + with the earlier preserved resource before export. + - **Breaking** [1836](https://github.com/open-telemetry/opentelemetry-rust/pull/1836) `SpanProcessor::shutdown` now takes an immutable reference to self. Any reference can call shutdown on the processor. After the first call to `shutdown` the processor will not process any new spans. ## v0.23.0 diff --git a/opentelemetry-sdk/src/trace/runtime_tests.rs b/opentelemetry-sdk/src/trace/runtime_tests.rs index 1874dadf96..610d140b7a 100644 --- a/opentelemetry-sdk/src/trace/runtime_tests.rs +++ b/opentelemetry-sdk/src/trace/runtime_tests.rs @@ -2,7 +2,6 @@ // need to run those tests one by one as the GlobalTracerProvider is a shared object between // threads Use cargo test -- --ignored --test-threads=1 to run those tests. use crate::export::trace::{ExportResult, SpanExporter}; -use crate::resource::Resource; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use crate::runtime; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] diff --git a/opentelemetry-sdk/src/trace/span_processor.rs b/opentelemetry-sdk/src/trace/span_processor.rs index 082e86d117..30fb543768 100644 --- a/opentelemetry-sdk/src/trace/span_processor.rs +++ b/opentelemetry-sdk/src/trace/span_processor.rs @@ -690,7 +690,6 @@ mod tests { OTEL_BSP_SCHEDULE_DELAY, OTEL_BSP_SCHEDULE_DELAY_DEFAULT, }; use crate::export::trace::{ExportResult, SpanData, SpanExporter}; - use crate::resource::Resource; use crate::runtime; use crate::testing::trace::{ new_test_export_span_data, new_tokio_test_exporter, InMemorySpanExporterBuilder, From 2acff9e4857bbf05d34e4daab03589639975efb6 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 29 May 2024 08:39:35 -0700 Subject: [PATCH 6/9] revert otel-roto --- opentelemetry-proto/src/proto/opentelemetry-proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-proto/src/proto/opentelemetry-proto b/opentelemetry-proto/src/proto/opentelemetry-proto index 39339ef177..b3060d2104 160000 --- a/opentelemetry-proto/src/proto/opentelemetry-proto +++ b/opentelemetry-proto/src/proto/opentelemetry-proto @@ -1 +1 @@ -Subproject commit 39339ef177218cc965b8cf863d761775ec668858 +Subproject commit b3060d2104df364136d75a35779e6bd48bac449a From 29240d55055f99d7acbb6cf884f3c6b6f610fd1d Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 29 May 2024 08:52:06 -0700 Subject: [PATCH 7/9] review comments --- opentelemetry-sdk/src/trace/provider.rs | 4 ---- opentelemetry-sdk/src/trace/span.rs | 1 - opentelemetry-stdout/src/trace/exporter.rs | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/trace/provider.rs b/opentelemetry-sdk/src/trace/provider.rs index deb8d7150f..560d37dae9 100644 --- a/opentelemetry-sdk/src/trace/provider.rs +++ b/opentelemetry-sdk/src/trace/provider.rs @@ -272,10 +272,6 @@ mod tests { fn shutdown(&self) -> TraceResult<()> { self.force_flush() } - - fn set_resource(&mut self, _: &Resource) { - unimplemented!() - } } #[test] diff --git a/opentelemetry-sdk/src/trace/span.rs b/opentelemetry-sdk/src/trace/span.rs index df45714cae..d672348885 100644 --- a/opentelemetry-sdk/src/trace/span.rs +++ b/opentelemetry-sdk/src/trace/span.rs @@ -76,7 +76,6 @@ impl Span { /// overhead. pub fn exported_data(&self) -> Option { let (span_context, tracer) = (self.span_context.clone(), &self.tracer); - //let resource = self.tracer.provider()?.config().resource.clone(); self.data .as_ref() diff --git a/opentelemetry-stdout/src/trace/exporter.rs b/opentelemetry-stdout/src/trace/exporter.rs index e0d67d0b50..2ed974fd50 100644 --- a/opentelemetry-stdout/src/trace/exporter.rs +++ b/opentelemetry-stdout/src/trace/exporter.rs @@ -117,7 +117,7 @@ impl SpanExporterBuilder { pub fn build(self) -> SpanExporter { SpanExporter { writer: Some(self.writer.unwrap_or_else(|| Box::new(stdout()))), - resource: Resource::default(), + resource: Resource::empty(), encoder: self.encoder.unwrap_or_else(|| { Box::new(|writer, spans| { serde_json::to_writer(writer, &spans) From 080186749e1e8b3997ba7a74dfc6dff9e676bc50 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 29 May 2024 08:55:33 -0700 Subject: [PATCH 8/9] lint --- opentelemetry-sdk/benches/batch_span_processor.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/opentelemetry-sdk/benches/batch_span_processor.rs b/opentelemetry-sdk/benches/batch_span_processor.rs index e111792720..abc7d0df02 100644 --- a/opentelemetry-sdk/benches/batch_span_processor.rs +++ b/opentelemetry-sdk/benches/batch_span_processor.rs @@ -8,8 +8,6 @@ use opentelemetry_sdk::testing::trace::NoopSpanExporter; use opentelemetry_sdk::trace::{ BatchConfigBuilder, BatchSpanProcessor, SpanEvents, SpanLinks, SpanProcessor, }; -use opentelemetry_sdk::Resource; -use std::borrow::Cow; use std::sync::Arc; use std::time::SystemTime; use tokio::runtime::Runtime; From 1cde2938bbd054a48455a49df7f4f88288094c27 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Wed, 29 May 2024 10:48:09 -0700 Subject: [PATCH 9/9] review comments --- opentelemetry-otlp/src/exporter/http/mod.rs | 6 ++++-- opentelemetry-otlp/src/exporter/tonic/trace.rs | 4 ++-- opentelemetry-proto/src/transform/trace.rs | 4 ++-- .../src/testing/trace/in_memory_exporter.rs | 6 ++++-- opentelemetry-stdout/src/trace/exporter.rs | 14 ++++++-------- opentelemetry-stdout/src/trace/transform.rs | 15 ++++----------- 6 files changed, 22 insertions(+), 27 deletions(-) diff --git a/opentelemetry-otlp/src/exporter/http/mod.rs b/opentelemetry-otlp/src/exporter/http/mod.rs index 04d3e8f520..4a45379121 100644 --- a/opentelemetry-otlp/src/exporter/http/mod.rs +++ b/opentelemetry-otlp/src/exporter/http/mod.rs @@ -309,11 +309,13 @@ impl OtlpHttpClient { spans: Vec, resource: &opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema, ) -> opentelemetry::trace::TraceResult<(Vec, &'static str)> { - use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest; + use opentelemetry_proto::tonic::{ + collector::trace::v1::ExportTraceServiceRequest, trace::v1::ResourceSpans, + }; let resource_spans = spans .into_iter() - .map(|log_event| (log_event, resource).into()) + .map(|span| ResourceSpans::new(span, resource)) .collect::>(); let req = ExportTraceServiceRequest { resource_spans }; diff --git a/opentelemetry-otlp/src/exporter/tonic/trace.rs b/opentelemetry-otlp/src/exporter/tonic/trace.rs index 803d14626f..a0dbe0e76b 100644 --- a/opentelemetry-otlp/src/exporter/tonic/trace.rs +++ b/opentelemetry-otlp/src/exporter/tonic/trace.rs @@ -5,6 +5,7 @@ use opentelemetry::trace::TraceError; use opentelemetry_proto::tonic::collector::trace::v1::{ trace_service_client::TraceServiceClient, ExportTraceServiceRequest, }; +use opentelemetry_proto::tonic::trace::v1::ResourceSpans; use opentelemetry_sdk::export::trace::{ExportResult, SpanData, SpanExporter}; use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Channel, Request}; @@ -74,8 +75,7 @@ impl SpanExporter for TonicTracesClient { let resource_spans = { batch .into_iter() - .map(|log_data| (log_data, &self.resource)) - .map(Into::into) + .map(|log_data| ResourceSpans::new(log_data, &self.resource)) .collect() }; diff --git a/opentelemetry-proto/src/transform/trace.rs b/opentelemetry-proto/src/transform/trace.rs index 74ddc0cf32..3f0003d44e 100644 --- a/opentelemetry-proto/src/transform/trace.rs +++ b/opentelemetry-proto/src/transform/trace.rs @@ -45,8 +45,8 @@ pub mod tonic { } } - impl From<(SpanData, &ResourceAttributesWithSchema)> for ResourceSpans { - fn from((source_span, resource): (SpanData, &ResourceAttributesWithSchema)) -> Self { + impl ResourceSpans { + pub fn new(source_span: SpanData, resource: &ResourceAttributesWithSchema) -> Self { let span_kind: span::SpanKind = source_span.span_kind.into(); ResourceSpans { resource: Some(Resource { diff --git a/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs index b2f9d7616b..5853558436 100644 --- a/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/trace/in_memory_exporter.rs @@ -147,7 +147,9 @@ impl SpanExporter for InMemorySpanExporter { } fn set_resource(&mut self, resource: &Resource) { - let mut res_guard = self.resource.lock().expect("Resource lock poisoned"); - *res_guard = resource.clone(); + self.resource + .lock() + .map(|mut res_guard| *res_guard = resource.clone()) + .expect("Resource lock poisoned"); } } diff --git a/opentelemetry-stdout/src/trace/exporter.rs b/opentelemetry-stdout/src/trace/exporter.rs index 2ed974fd50..c4d319ff31 100644 --- a/opentelemetry-stdout/src/trace/exporter.rs +++ b/opentelemetry-stdout/src/trace/exporter.rs @@ -38,15 +38,13 @@ impl Default for SpanExporter { impl opentelemetry_sdk::export::trace::SpanExporter for SpanExporter { fn export(&mut self, batch: Vec) -> BoxFuture<'static, ExportResult> { let res = if let Some(writer) = &mut self.writer { - (self.encoder)( - writer, - crate::trace::SpanData::from((batch, &self.resource)), + (self.encoder)(writer, crate::trace::SpanData::new(batch, &self.resource)).and_then( + |_| { + writer + .write_all(b"\n") + .map_err(|err| TraceError::Other(Box::new(err))) + }, ) - .and_then(|_| { - writer - .write_all(b"\n") - .map_err(|err| TraceError::Other(Box::new(err))) - }) } else { Err("exporter is shut down".into()) }; diff --git a/opentelemetry-stdout/src/trace/transform.rs b/opentelemetry-stdout/src/trace/transform.rs index 7c0903cbc6..484a222f42 100644 --- a/opentelemetry-stdout/src/trace/transform.rs +++ b/opentelemetry-stdout/src/trace/transform.rs @@ -9,17 +9,10 @@ pub struct SpanData { resource_spans: Vec, } -impl - From<( - Vec, - &opentelemetry_sdk::Resource, - )> for SpanData -{ - fn from( - (sdk_spans, sdk_resource): ( - Vec, - &opentelemetry_sdk::Resource, - ), +impl SpanData { + pub(crate) fn new( + sdk_spans: Vec, + sdk_resource: &opentelemetry_sdk::Resource, ) -> Self { let mut resource_spans = HashMap::::new(); for sdk_span in sdk_spans {