Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-prometheus-to-otel-27
Browse files Browse the repository at this point in the history
  • Loading branch information
kudlatyamroth authored Dec 3, 2024
2 parents 13d72d7 + 506a4f9 commit ce41608
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 56 deletions.
4 changes: 3 additions & 1 deletion opentelemetry-jaeger-propagator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ rustdoc-args = ["--cfg", "docsrs"]
opentelemetry = { version = "0.27", default-features = false, features = [
"trace",
], path = "../opentelemetry" }
tracing = {workspace = true, optional = true} # optional for opentelemetry internal logging

[dev-dependencies]
opentelemetry = { features = ["testing"], path = "../opentelemetry" }

[features]
default = []
default = ["internal-logs"]
internal-logs = ["tracing"]
2 changes: 1 addition & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ reqwest-rustls-webpki-roots = ["reqwest", "opentelemetry-http/reqwest-rustls-web
hyper-client = ["opentelemetry-http/hyper"]

# test
integration-testing = ["tonic", "prost", "tokio/full", "trace"]
integration-testing = ["tonic", "prost", "tokio/full", "trace", "logs"]
12 changes: 11 additions & 1 deletion opentelemetry-otlp/tests/integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@ testcontainers = "0.15.0"

[target.'cfg(unix)'.dependencies]
opentelemetry-appender-log = { path = "../../../opentelemetry-appender-log", default-features = false}
opentelemetry-otlp = { path = "../../../opentelemetry-otlp", features = ["tonic", "metrics", "logs"] }
opentelemetry-otlp = { path = "../../../opentelemetry-otlp", default-features = false }
opentelemetry-semantic-conventions = { path = "../../../opentelemetry-semantic-conventions" }

[features]
hyper-client = ["opentelemetry-otlp/hyper-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
reqwest-client = ["opentelemetry-otlp/reqwest-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
reqwest-blocking-client = ["opentelemetry-otlp/reqwest-blocking-client", "opentelemetry-otlp/http-proto", "opentelemetry-otlp/trace","opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]
tonic-client = ["opentelemetry-otlp/grpc-tonic", "opentelemetry-otlp/trace", "opentelemetry-otlp/logs", "opentelemetry-otlp/metrics"]

# Keep tonic as the default client
default = ["tonic-client"]

13 changes: 12 additions & 1 deletion opentelemetry-otlp/tests/integration_test/tests/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ use std::fs::File;
use std::os::unix::fs::MetadataExt;

fn init_logs() -> Result<sdklogs::LoggerProvider, LogError> {
let exporter = LogExporter::builder().with_tonic().build()?;
let exporter_builder = LogExporter::builder();
#[cfg(feature = "tonic-client")]
let exporter_builder = exporter_builder.with_tonic();
#[cfg(not(feature = "tonic-client"))]
#[cfg(any(
feature = "hyper-client",
feature = "reqwest-client",
feature = "reqwest-blocking-client"
))]
let exporter_builder = exporter_builder.with_http();

let exporter = exporter_builder.build()?;

Ok(LoggerProvider::builder()
.with_batch_exporter(exporter, runtime::Tokio)
Expand Down
18 changes: 15 additions & 3 deletions opentelemetry-otlp/tests/integration_test/tests/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use opentelemetry::{
trace::{TraceContextExt, Tracer},
Key, KeyValue,
};
use opentelemetry_otlp::SpanExporter;

use opentelemetry_proto::tonic::trace::v1::TracesData;
use opentelemetry_sdk::{runtime, trace as sdktrace, Resource};
use std::error::Error;
Expand All @@ -16,9 +18,19 @@ use std::io::Write;
use std::os::unix::fs::MetadataExt;

fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
let exporter = opentelemetry_otlp::SpanExporter::builder()
.with_tonic()
.build()?;
let exporter_builder = SpanExporter::builder();
#[cfg(feature = "tonic-client")]
let exporter_builder = exporter_builder.with_tonic();
#[cfg(not(feature = "tonic-client"))]
#[cfg(any(
feature = "hyper-client",
feature = "reqwest-client",
feature = "reqwest-blocking-client"
))]
let exporter_builder = exporter_builder.with_http();

let exporter = exporter_builder.build()?;

Ok(opentelemetry_sdk::trace::TracerProvider::builder()
.with_batch_exporter(exporter, runtime::Tokio)
.with_resource(Resource::new(vec![KeyValue::new(
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-proto/src/transform/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ pub mod tonic {
.iter()
.map(|dp| TonicNumberDataPoint {
attributes: dp.attributes.iter().map(Into::into).collect(),
start_time_unix_nano: dp.start_time.map(to_nanos).unwrap_or_default(),
time_unix_nano: dp.time.map(to_nanos).unwrap_or_default(),
start_time_unix_nano: to_nanos(dp.start_time),
time_unix_nano: to_nanos(dp.time),
exemplars: dp.exemplars.iter().map(Into::into).collect(),
flags: TonicDataPointFlags::default() as u32,
value: Some(dp.value.into()),
Expand All @@ -319,8 +319,8 @@ pub mod tonic {
.iter()
.map(|dp| TonicNumberDataPoint {
attributes: dp.attributes.iter().map(Into::into).collect(),
start_time_unix_nano: dp.start_time.map(to_nanos).unwrap_or_default(),
time_unix_nano: dp.time.map(to_nanos).unwrap_or_default(),
start_time_unix_nano: to_nanos(dp.start_time),
time_unix_nano: to_nanos(dp.time),
exemplars: dp.exemplars.iter().map(Into::into).collect(),
flags: TonicDataPointFlags::default() as u32,
value: Some(dp.value.into()),
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/metrics/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ pub struct DataPoint<T> {
/// time series.
pub attributes: Vec<KeyValue>,
/// The time when the time series was started.
pub start_time: Option<SystemTime>,
pub start_time: SystemTime,
/// The time when the time series was recorded.
pub time: Option<SystemTime>,
pub time: SystemTime,
/// The value of this data point.
pub value: T,
/// The sampled [Exemplar]s collected during the time series.
Expand Down Expand Up @@ -338,8 +338,8 @@ mod tests {
fn validate_cloning_data_points() {
let data_type = DataPoint {
attributes: vec![KeyValue::new("key", "value")],
start_time: Some(std::time::SystemTime::now()),
time: Some(std::time::SystemTime::now()),
start_time: std::time::SystemTime::now(),
time: std::time::SystemTime::now(),
value: 0u32,
exemplars: vec![Exemplar {
filtered_attributes: vec![],
Expand Down
20 changes: 10 additions & 10 deletions opentelemetry-sdk/src/metrics/internal/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ mod tests {
let mut a = Gauge {
data_points: vec![DataPoint {
attributes: vec![KeyValue::new("a", 1)],
start_time: Some(SystemTime::now()),
time: Some(SystemTime::now()),
start_time: SystemTime::now(),
time: SystemTime::now(),
value: 1u64,
exemplars: vec![],
}],
Expand All @@ -251,15 +251,15 @@ mod tests {
data_points: vec![
DataPoint {
attributes: vec![KeyValue::new("a1", 1)],
start_time: Some(SystemTime::now()),
time: Some(SystemTime::now()),
start_time: SystemTime::now(),
time: SystemTime::now(),
value: 1u64,
exemplars: vec![],
},
DataPoint {
attributes: vec![KeyValue::new("a2", 1)],
start_time: Some(SystemTime::now()),
time: Some(SystemTime::now()),
start_time: SystemTime::now(),
time: SystemTime::now(),
value: 2u64,
exemplars: vec![],
},
Expand Down Expand Up @@ -294,15 +294,15 @@ mod tests {
data_points: vec![
DataPoint {
attributes: vec![KeyValue::new("a1", 1)],
start_time: Some(SystemTime::now()),
time: Some(SystemTime::now()),
start_time: SystemTime::now(),
time: SystemTime::now(),
value: 1u64,
exemplars: vec![],
},
DataPoint {
attributes: vec![KeyValue::new("a2", 1)],
start_time: Some(SystemTime::now()),
time: Some(SystemTime::now()),
start_time: SystemTime::now(),
time: SystemTime::now(),
value: 2u64,
exemplars: vec![],
},
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/metrics/internal/last_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl<T: Number> LastValue<T> {
self.value_map
.collect_and_reset(dest, |attributes, aggr| DataPoint {
attributes,
start_time: Some(prev_start),
time: Some(t),
start_time: prev_start,
time: t,
value: aggr.value.get_value(),
exemplars: vec![],
});
Expand All @@ -79,8 +79,8 @@ impl<T: Number> LastValue<T> {
self.value_map
.collect_readonly(dest, |attributes, aggr| DataPoint {
attributes,
start_time: Some(prev_start),
time: Some(t),
start_time: prev_start,
time: t,
value: aggr.value.get_value(),
exemplars: vec![],
});
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl<T: Number> PrecomputedSum<T> {
let delta = value - *reported.get(&attributes).unwrap_or(&T::default());
DataPoint {
attributes,
start_time: Some(prev_start),
time: Some(t),
start_time: prev_start,
time: t,
value: delta,
exemplars: vec![],
}
Expand Down Expand Up @@ -109,8 +109,8 @@ impl<T: Number> PrecomputedSum<T> {
self.value_map
.collect_readonly(&mut s_data.data_points, |attributes, aggr| DataPoint {
attributes,
start_time: Some(prev_start),
time: Some(t),
start_time: prev_start,
time: t,
value: aggr.value.get_value(),
exemplars: vec![],
});
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/metrics/internal/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ impl<T: Number> Sum<T> {
self.value_map
.collect_and_reset(&mut s_data.data_points, |attributes, aggr| DataPoint {
attributes,
start_time: Some(prev_start),
time: Some(t),
start_time: prev_start,
time: t,
value: aggr.value.get_value(),
exemplars: vec![],
});
Expand Down Expand Up @@ -132,8 +132,8 @@ impl<T: Number> Sum<T> {
self.value_map
.collect_readonly(&mut s_data.data_points, |attributes, aggr| DataPoint {
attributes,
start_time: Some(prev_start),
time: Some(t),
start_time: prev_start,
time: t,
value: aggr.value.get_value(),
exemplars: vec![],
});
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/metrics/manual_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::{
/// # drop(reader)
/// ```
pub struct ManualReader {
inner: Box<Mutex<ManualReaderInner>>,
inner: Mutex<ManualReaderInner>,
temporality: Temporality,
}

Expand Down Expand Up @@ -58,10 +58,10 @@ impl ManualReader {
/// A [MetricReader] which is directly called to collect metrics.
pub(crate) fn new(temporality: Temporality) -> Self {
ManualReader {
inner: Box::new(Mutex::new(ManualReaderInner {
inner: Mutex::new(ManualReaderInner {
sdk_producer: None,
is_shutdown: false,
})),
}),
temporality,
}
}
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Pipeline {
pub(crate) resource: Resource,
reader: Box<dyn MetricReader>,
views: Vec<Arc<dyn View>>,
inner: Box<Mutex<PipelineInner>>,
inner: Mutex<PipelineInner>,
}

impl fmt::Debug for Pipeline {
Expand Down
24 changes: 10 additions & 14 deletions opentelemetry-stdout/src/metrics/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,16 @@ fn print_histogram<T: Debug>(histogram: &data::Histogram<T>) {
fn print_data_points<T: Debug>(data_points: &[data::DataPoint<T>]) {
for (i, data_point) in data_points.iter().enumerate() {
println!("\t\tDataPoint #{}", i);
if let Some(start_time) = data_point.start_time {
let datetime: DateTime<Utc> = start_time.into();
println!(
"\t\t\tStartTime : {}",
datetime.format("%Y-%m-%d %H:%M:%S%.6f")
);
}
if let Some(end_time) = data_point.time {
let datetime: DateTime<Utc> = end_time.into();
println!(
"\t\t\tEndTime : {}",
datetime.format("%Y-%m-%d %H:%M:%S%.6f")
);
}
let datetime: DateTime<Utc> = data_point.start_time.into();
println!(
"\t\t\tStartTime : {}",
datetime.format("%Y-%m-%d %H:%M:%S%.6f")
);
let datetime: DateTime<Utc> = data_point.time.into();
println!(
"\t\t\tEndTime : {}",
datetime.format("%Y-%m-%d %H:%M:%S%.6f")
);
println!("\t\t\tValue : {:#?}", data_point.value);
println!("\t\t\tAttributes :");
for kv in data_point.attributes.iter() {
Expand Down
21 changes: 20 additions & 1 deletion scripts/integration_tests.sh
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
cd ./opentelemetry-otlp/tests/integration_test/tests && cargo test -- --ignored
set -e
TEST_DIR="./opentelemetry-otlp/tests/integration_test/tests"

if [ -d "$TEST_DIR" ]; then
cd "$TEST_DIR"
# Run tests with the grpc-tonic feature
cargo test --no-default-features --features "tonic-client" -- --ignored

# Run tests with the reqwest-client feature
cargo test --no-default-features --features "reqwest-client" -- --ignored

# TODO - Uncomment the following lines once the reqwest-blocking-client feature is working.
# cargo test --no-default-features --features "reqwest-blocking-client" -- --ignored

# Run tests with the hyper-client feature
cargo test --no-default-features --features "hyper-client" -- --ignored
else
echo "Directory $TEST_DIR does not exist. Skipping tests."
exit 1
fi

0 comments on commit ce41608

Please sign in to comment.