Skip to content

Commit 49c9bca

Browse files
Copilotlalitb
andcommitted
Optimize span_processor_with_async_runtime to use read locks for shutdown operations
Co-authored-by: lalitb <[email protected]>
1 parent e512fba commit 49c9bca

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

opentelemetry-sdk/src/logs/in_memory_exporter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl InMemoryLogExporterBuilder {
132132

133133
/// If set, the records will not be [`InMemoryLogExporter::reset`] on shutdown.
134134
#[cfg(test)]
135+
#[allow(dead_code)]
135136
pub(crate) fn keep_records_on_shutdown(self) -> Self {
136137
Self {
137138
reset_on_shutdown: false,

opentelemetry-sdk/src/logs/logger_provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ mod tests {
607607
tracer.in_span("test-span", |cx| {
608608
let ambient_ctxt = cx.span().span_context().clone();
609609
let explicit_ctxt = TraceContext {
610-
trace_id: TraceId::from_u128(13),
611-
span_id: SpanId::from_u64(14),
610+
trace_id: TraceId::from_bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13]),
611+
span_id: SpanId::from_bytes([0, 0, 0, 0, 0, 0, 0, 14]),
612612
trace_flags: None,
613613
};
614614

opentelemetry-sdk/src/trace/span_processor_with_async_runtime.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ struct BatchSpanProcessorInternal<E, R> {
191191
export_tasks: FuturesUnordered<BoxFuture<'static, OTelSdkResult>>,
192192
runtime: R,
193193
config: BatchConfig,
194-
// TODO: Redesign the `SpanExporter` trait to use immutable references (`&self`)
195-
// for all methods. This would allow us to remove the `RwLock` and just use `Arc<E>`,
196-
// similar to how `crate::logs::LogExporter` is implemented.
197194
exporter: Arc<RwLock<E>>,
198195
}
199196

@@ -306,7 +303,7 @@ impl<E: SpanExporter + 'static, R: RuntimeChannel> BatchSpanProcessorInternal<E,
306303
// Stream has terminated or processor is shutdown, return to finish execution.
307304
BatchMessage::Shutdown(ch) => {
308305
self.flush(Some(ch)).await;
309-
let _ = self.exporter.write().await.shutdown();
306+
let _ = self.exporter.read().await.shutdown();
310307
return false;
311308
}
312309
// propagate the resource

0 commit comments

Comments
 (0)