Skip to content

Commit 68a534c

Browse files
authored
etw-exporter-metrics updates to opentelemetry, better error logging (#105)
1 parent ca8f0d6 commit 68a534c

File tree

6 files changed

+31
-234
lines changed

6 files changed

+31
-234
lines changed

opentelemetry-etw-metrics/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## vNext
44

5+
## v0.4.0
6+
7+
- Improved logging when ETW write fails due to size limit being hit.
8+
[105](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/105)
9+
- Bump opentelemetry,opentelemetry_sdk and opentelemetry-proto versions to 0.25
10+
[105](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/105)
11+
512
## v0.3.0
613

714
### Changed

opentelemetry-etw-metrics/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "opentelemetry-etw-metrics"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
edition = "2021"
55
description = "OpenTelemetry metrics exporter to ETW (Event Tracing for Windows)"
66
homepage = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-etw-metrics"
@@ -11,9 +11,9 @@ license = "Apache-2.0"
1111
rust-version = "1.65"
1212

1313
[dependencies]
14-
opentelemetry = { workspace = true, features = ["metrics"] }
15-
opentelemetry_sdk = { workspace = true, features = ["metrics", "rt-tokio"] }
16-
opentelemetry-proto = { workspace = true, features = ["gen-tonic", "metrics"] }
14+
opentelemetry = { version = "0.25", features = ["metrics"] }
15+
opentelemetry_sdk = { version = "0.25", features = ["metrics", "rt-tokio"] }
16+
opentelemetry-proto = { version = "0.25", features = ["gen-tonic", "metrics"] }
1717
async-trait = "0.1"
1818
prost = "0.13"
1919
tracelogging = "1.2.1"

opentelemetry-etw-metrics/examples/advanced.rs

Lines changed: 0 additions & 218 deletions
This file was deleted.

opentelemetry-etw-metrics/examples/basic.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
//! run with `$ cargo run --example basic --all-features
2-
use opentelemetry::{metrics::MeterProvider as _, KeyValue};
1+
//! run with `$ cargo run --example basic
2+
use opentelemetry::{global, metrics::MeterProvider as _, KeyValue};
33
use opentelemetry_etw_metrics::MetricsExporter;
44
use opentelemetry_sdk::{
55
metrics::{PeriodicReader, SdkMeterProvider},
66
runtime, Resource,
77
};
8-
use std::{thread, time::Duration};
98

109
const SERVICE_NAME: &str = "service-name";
1110

@@ -24,6 +23,7 @@ fn setup_meter_provider() -> SdkMeterProvider {
2423
#[tokio::main]
2524
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2625
let meter_provider = setup_meter_provider();
26+
global::set_meter_provider(meter_provider.clone());
2727

2828
let meter = meter_provider.meter("user-event-test");
2929
let c = meter
@@ -81,10 +81,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8181
.as_ref(),
8282
);
8383

84-
// Sleep for 1 second
85-
thread::sleep(Duration::from_secs(1));
86-
println!("Running...");
87-
8884
meter_provider.shutdown()?;
8985
Ok(())
9086
}

opentelemetry-etw-metrics/src/etw/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tlg::define_provider!(
1111
);
1212

1313
static ETW_PROVIDER_REGISTRANT: Once = Once::new();
14+
pub(crate) const MAX_EVENT_SIZE: usize = 65360;
1415

1516
/// Register the ETW provider.
1617
pub fn register() {

opentelemetry-etw-metrics/src/exporter/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,25 @@ impl PushMetricsExporter for MetricsExporter {
7070
.encode(&mut byte_array)
7171
.map_err(|err| MetricsError::Other(err.to_string()))?;
7272

73-
let result = etw::write(&byte_array);
74-
if result != 0 {
73+
if (byte_array.len()) > etw::MAX_EVENT_SIZE {
7574
global::handle_error(MetricsError::Other(format!(
76-
"Failed to write ETW event with error code: {}",
77-
result
75+
"Exporting failed due to event size {} exceeding the maximum size of {} bytes",
76+
byte_array.len(),
77+
etw::MAX_EVENT_SIZE
7878
)));
79+
} else {
80+
let result = etw::write(&byte_array);
81+
// TODO: Better logging/internal metrics needed here for non-failure
82+
// case Uncomment the line below to see the exported bytes until a
83+
// better logging solution is implemented
84+
// println!("Exported {} bytes to ETW", byte_array.len());
85+
if result != 0 {
86+
global::handle_error(MetricsError::Other(format!(
87+
"Failed to write ETW event with error code: {}",
88+
result
89+
)));
90+
}
7991
}
80-
8192
Ok(())
8293
}
8394

0 commit comments

Comments
 (0)