Skip to content

Commit

Permalink
remove shutdown in tonic to unblock
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Mar 10, 2025
1 parent 3349727 commit dee8890
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 21 deletions.
8 changes: 3 additions & 5 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
- The `OTEL_EXPORTER_OTLP_TIMEOUT`, `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT`, `OTEL_EXPORTER_OTLP_METRICS_TIMEOUT` and `OTEL_EXPORTER_OTLP_LOGS_TIMEOUT` are changed from seconds to miliseconds.
- Fixed `.with_headers()` in `HttpExporterBuilder` to correctly support multiple key/value pairs. [#2699](https://github.com/open-telemetry/opentelemetry-rust/pull/2699)
- Fixed
[#2770](https://github.com/open-telemetry/opentelemetry-rust/issues/2770) to
properly handle `shutdown()`. When using gRPC/tonic, `shutdown()` must now be
called from a Tokio runtime. Previously, it was required to initialize the
provider from a Tokio runtime, and this requirement is now extended to
`shutdown()` as well.
[#2770](https://github.com/open-telemetry/opentelemetry-rust/issues/2770)
partially to properly handle `shutdown()` when using `http`. (`tonic` still
does not do proper shutdown)

## 0.28.0

Expand Down
24 changes: 8 additions & 16 deletions opentelemetry-otlp/src/exporter/tonic/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,14 @@ impl LogExporter for TonicLogsClient {
}

fn shutdown(&self) -> OTelSdkResult {
otel_debug!(name: "TonicsLogsClient.Shutdown");
let handle = match tokio::runtime::Handle::try_current() {
Ok(handle) => handle,
Err(e) => {
return Err(OTelSdkError::InternalFailure(format!(
"Shutdown must be called from a tokio runtime: {:?}",
e
)));
}
};

let mut inner = handle.block_on(self.inner.lock());
match inner.take() {
Some(_) => Ok(()), // Successfully took `inner`, indicating a successful shutdown.
None => Err(OTelSdkError::AlreadyShutdown), // `inner` was already `None`, meaning it's already shut down.
}
// TODO: Implement actual shutdown
// Due to the use to tokio::sync::Mutex to guard
// the inner client, we need to lock the mutex
// and that requires async runtime.
// It is possible to fix this by using
// a dedicated thread just to handle shutdown.
// But for now, we just return Ok.
Ok(())
}

fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) {
Expand Down
70 changes: 70 additions & 0 deletions opentelemetry-sdk/benches/log_enabled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
The benchmark results:
criterion = "0.5.1"
Hardware: Apple M4 Pro
Total Number of Cores: 14 (10 performance and 4 efficiency)
| Test | Average time|
|-----------------------------|-------------|
| exporter_enabled_false | 1.8 ns |
*/

use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::logs::{LoggerProvider,Logger};
use opentelemetry::InstrumentationScope;
use opentelemetry_sdk::error::OTelSdkResult;
use opentelemetry_sdk::logs::{LogBatch, LogExporter, LogProcessor, SdkLogRecord, SdkLoggerProvider};
use opentelemetry_sdk::Resource;
#[cfg(not(target_os = "windows"))]
use pprof::criterion::{Output, PProfProfiler};

#[derive(Debug)]
struct NoopExporter;
impl LogExporter for NoopExporter {
async fn export(&self, _: LogBatch<'_>) -> OTelSdkResult {
Ok(())
}

fn shutdown(&mut self) -> OTelSdkResult {
Ok(())
}

fn event_enabled(&self, _level: opentelemetry::logs::Severity, _target: &str, _name: Option<&str>) -> bool {
false
}

fn set_resource(&mut self, _: &Resource) {}
}



fn benchmark_exporter_enabled_false(c: &mut Criterion) {
let processor = ConcurrentExportProcessor::new(NoopExporter);
let provider = SdkLoggerProvider::builder()
.with_log_processor(processor)
.build();
let logger = provider.logger("test_logger");

c.bench_function("exporter_enabled_false", |b| {
b.iter(|| {
logger.event_enabled(opentelemetry::logs::Severity::Debug, "target", Some("name"));
});
});
}

fn criterion_benchmark(c: &mut Criterion) {
benchmark_exporter_enabled_false(c);
}

#[cfg(not(target_os = "windows"))]
criterion_group! {
name = benches;
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
targets = criterion_benchmark
}
#[cfg(target_os = "windows")]
criterion_group! {
name = benches;
config = Criterion::default();
targets = criterion_benchmark
}
criterion_main!(benches);

0 comments on commit dee8890

Please sign in to comment.