Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etw-exporter-metrics updates to opentelemetry, better error logging #105

Merged
merged 8 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions opentelemetry-etw-metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## vNext

## v0.4.0

- Improved logging when ETW write fails due to size limit being hit.
[105](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/105)
- Bump opentelemetry,opentelemetry_sdk and opentelemetry-proto versions to 0.25
[105](https://github.com/open-telemetry/opentelemetry-rust-contrib/pull/105)

## v0.3.0

### Changed
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-etw-metrics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentelemetry-etw-metrics"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
description = "OpenTelemetry metrics exporter to ETW (Event Tracing for Windows)"
homepage = "https://github.com/open-telemetry/opentelemetry-rust-contrib/tree/main/opentelemetry-etw-metrics"
Expand All @@ -11,9 +11,9 @@ license = "Apache-2.0"
rust-version = "1.65"

[dependencies]
opentelemetry = { workspace = true, features = ["metrics"] }
opentelemetry_sdk = { workspace = true, features = ["metrics", "rt-tokio"] }
opentelemetry-proto = { workspace = true, features = ["gen-tonic", "metrics"] }
opentelemetry = { version = "0.25", features = ["metrics"] }
opentelemetry_sdk = { version = "0.25", features = ["metrics", "rt-tokio"] }
opentelemetry-proto = { version = "0.25", features = ["gen-tonic", "metrics"] }
async-trait = "0.1"
prost = "0.13"
tracelogging = "1.2.1"
Expand Down
218 changes: 0 additions & 218 deletions opentelemetry-etw-metrics/examples/advanced.rs

This file was deleted.

10 changes: 3 additions & 7 deletions opentelemetry-etw-metrics/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! run with `$ cargo run --example basic --all-features
use opentelemetry::{metrics::MeterProvider as _, KeyValue};
//! run with `$ cargo run --example basic
use opentelemetry::{global, metrics::MeterProvider as _, KeyValue};
use opentelemetry_etw_metrics::MetricsExporter;
use opentelemetry_sdk::{
metrics::{PeriodicReader, SdkMeterProvider},
runtime, Resource,
};
use std::{thread, time::Duration};

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

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

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

// Sleep for 1 second
thread::sleep(Duration::from_secs(1));
println!("Running...");

meter_provider.shutdown()?;
Ok(())
}
1 change: 1 addition & 0 deletions opentelemetry-etw-metrics/src/etw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tlg::define_provider!(
);

static ETW_PROVIDER_REGISTRANT: Once = Once::new();
pub(crate) const MAX_EVENT_SIZE: usize = 65360;

/// Register the ETW provider.
pub fn register() {
Expand Down
21 changes: 16 additions & 5 deletions opentelemetry-etw-metrics/src/exporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,25 @@
.encode(&mut byte_array)
.map_err(|err| MetricsError::Other(err.to_string()))?;

let result = etw::write(&byte_array);
if result != 0 {
if (byte_array.len()) > etw::MAX_EVENT_SIZE {

Check warning on line 73 in opentelemetry-etw-metrics/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L73 was not covered by tests
global::handle_error(MetricsError::Other(format!(
"Failed to write ETW event with error code: {}",
result
"Exporting failed due to event size {} exceeding the maximum size of {} bytes",
byte_array.len(),
etw::MAX_EVENT_SIZE

Check warning on line 77 in opentelemetry-etw-metrics/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-etw-metrics/src/exporter/mod.rs#L75-L77

Added lines #L75 - L77 were not covered by tests
)));
} else {
let result = etw::write(&byte_array);
// TODO: Better logging/internal metrics needed here for non-failure
// case Uncomment the line below to see the exported bytes until a
// better logging solution is implemented
// println!("Exported {} bytes to ETW", byte_array.len());
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
if result != 0 {
global::handle_error(MetricsError::Other(format!(
"Failed to write ETW event with error code: {}",
result
)));
}

Check warning on line 90 in opentelemetry-etw-metrics/src/exporter/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-etw-metrics/src/exporter/mod.rs#L79-L90

Added lines #L79 - L90 were not covered by tests
}

Ok(())
}

Expand Down
Loading