Skip to content

Commit

Permalink
chore: Update OpenTelemetry Proto Definitions to 0.19.0 (#990)
Browse files Browse the repository at this point in the history
Signed-off-by: Harold Dost <h.dost@criteo.com>
  • Loading branch information
hdost committed Mar 18, 2023
1 parent 6e472f8 commit 57147b1
Show file tree
Hide file tree
Showing 32 changed files with 1,773 additions and 1,777 deletions.
1 change: 1 addition & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

- Improve OTLP exporter environment variable handling #912
- OTLP exporter default endpoint changed to http #912
- Change to export using v0.19.0 protobuf definitions. #989

## v0.11.0

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async-trait = "0.1"
futures = { version = "0.3", default-features = false, features = ["std"] }
futures-util = { version = "0.3", default-features = false, features = ["std"] }

opentelemetry-proto = { version = "0.1", path = "../opentelemetry-proto", default-features = false }
opentelemetry-proto = { version = "0.2", path = "../opentelemetry-proto", default-features = false }

grpcio = { version = "0.12", optional = true}
opentelemetry = { version = "0.18", default-features = false, features = ["trace"], path = "../opentelemetry" }
Expand Down
103 changes: 51 additions & 52 deletions opentelemetry-otlp/src/transform/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ pub(crate) mod tonic {
use opentelemetry::metrics::MetricsError;
use opentelemetry::sdk::export::metrics::{
aggregation::{
Count, Histogram as SdkHistogram, LastValue, Sum as SdkSum, TemporalitySelector,
Count, Histogram as SdkHistogram, LastValue, Max, Min, Sum as SdkSum,
TemporalitySelector,
},
Record,
};
Expand All @@ -23,8 +24,7 @@ pub(crate) mod tonic {
common::v1::KeyValue,
metrics::v1::{
metric::Data, number_data_point, AggregationTemporality, Gauge, Histogram,
HistogramDataPoint, InstrumentationLibraryMetrics, Metric, NumberDataPoint,
ResourceMetrics, Sum,
HistogramDataPoint, Metric, NumberDataPoint, ResourceMetrics, ScopeMetrics, Sum,
},
};

Expand Down Expand Up @@ -87,16 +87,23 @@ pub(crate) mod tonic {
aggregator.as_any().downcast_ref::<HistogramAggregator>()
{
Some({
let (sum, count, buckets) =
(histogram.sum()?, histogram.count()?, histogram.histogram()?);
let (sum, count, min, max, buckets) = (
histogram.sum()?,
histogram.count()?,
histogram.min()?,
histogram.max()?,
histogram.histogram()?,
);
Data::Histogram(Histogram {
data_points: vec![HistogramDataPoint {
flags: DataPointFlags::FlagNone as u32,
attributes,
start_time_unix_nano: to_nanos(*record.start_time()),
time_unix_nano: to_nanos(*record.end_time()),
count,
sum: sum.to_f64(kind),
sum: Some(sum.to_f64(kind)),
min: Some(min.to_f64(kind)),
max: Some(max.to_f64(kind)),
bucket_counts: buckets
.counts()
.iter()
Expand Down Expand Up @@ -169,20 +176,18 @@ pub(crate) mod tonic {
.map(|s| s.to_string())
.unwrap_or_default(),
resource: Some(resource.into()),
instrumentation_library_metrics: metric_map
scope_metrics: metric_map
.into_iter()
.map(
|(instrumentation_library, metrics)| InstrumentationLibraryMetrics {
schema_url: instrumentation_library
.schema_url
.clone()
.unwrap_or_default()
.to_string(),
instrumentation_library: Some(instrumentation_library.into()),
metrics: metrics.into_values().collect::<Vec<Metric>>(), // collect values
},
)
.collect::<Vec<InstrumentationLibraryMetrics>>(),
.map(|(instrumentation_library, metrics)| ScopeMetrics {
schema_url: instrumentation_library
.schema_url
.clone()
.unwrap_or_default()
.to_string(),
scope: Some(instrumentation_library.into()),
metrics: metrics.into_values().collect::<Vec<Metric>>(), // collect values
})
.collect::<Vec<ScopeMetrics>>(),
})
.collect::<Vec<ResourceMetrics>>(),
}
Expand Down Expand Up @@ -252,8 +257,8 @@ mod tests {
use opentelemetry_proto::tonic::{
common::v1::{any_value, AnyValue, KeyValue},
metrics::v1::{
metric::Data, number_data_point, Gauge, Histogram, HistogramDataPoint,
InstrumentationLibraryMetrics, Metric, NumberDataPoint, ResourceMetrics, Sum,
metric::Data, number_data_point, Gauge, Histogram, HistogramDataPoint, Metric,
NumberDataPoint, ResourceMetrics, ScopeMetrics, Sum,
},
Attributes, FromNumber,
};
Expand Down Expand Up @@ -335,13 +340,15 @@ mod tests {
attributes: attributes.0,
dropped_attributes_count: 0,
};
let mut instrumentation_library_metrics = vec![];
let mut scope_metrics = vec![];
for ((instrumentation_name, instrumentation_version), metrics) in data.1 {
instrumentation_library_metrics.push(InstrumentationLibraryMetrics {
instrumentation_library: Some(
opentelemetry_proto::tonic::common::v1::InstrumentationLibrary {
scope_metrics.push(ScopeMetrics {
scope: Some(
opentelemetry_proto::tonic::common::v1::InstrumentationScope {
name: instrumentation_name.to_string(),
attributes: Vec::new(),
version: instrumentation_version.unwrap_or("").to_string(),
dropped_attributes_count: 0,
},
),
schema_url: "".to_string(),
Expand All @@ -354,7 +361,7 @@ mod tests {
ResourceMetrics {
resource: Some(resource),
schema_url: "".to_string(),
instrumentation_library_metrics,
scope_metrics,
}
}

Expand All @@ -364,7 +371,7 @@ mod tests {
//
// Based on current implementation of sink function. There are two parts where the order is unknown.
// The first one is instrumentation_library_metrics in ResourceMetrics.
// The other is metrics in InstrumentationLibraryMetrics.
// The other is metrics in ScopeMetrics.
//
// If we changed the sink function to process the input in parallel, we will have to sort other vectors
// like data points in Metrics.
Expand All @@ -379,23 +386,17 @@ mod tests {
.as_mut()
.map(|r| r.attributes.sort_by_key(|kv| kv.key.to_string()))
);
assert_eq!(
expect.instrumentation_library_metrics.len(),
actual.instrumentation_library_metrics.len()
);
assert_eq!(expect.scope_metrics.len(), actual.scope_metrics.len());
let sort_instrumentation_library =
|metric: &InstrumentationLibraryMetrics,
other_metric: &InstrumentationLibraryMetrics| {
match (
metric.instrumentation_library.as_ref(),
other_metric.instrumentation_library.as_ref(),
) {
(Some(library), Some(other_library)) => library
.name
.cmp(&other_library.name)
.then(library.version.cmp(&other_library.version)),
_ => Ordering::Equal,
}
|metric: &ScopeMetrics, other_metric: &ScopeMetrics| match (
metric.scope.as_ref(),
other_metric.scope.as_ref(),
) {
(Some(library), Some(other_library)) => library
.name
.cmp(&other_library.name)
.then(library.version.cmp(&other_library.version)),
_ => Ordering::Equal,
};
let sort_metrics = |metric: &Metric, other_metric: &Metric| {
metric.name.cmp(&other_metric.name).then(
Expand All @@ -405,17 +406,13 @@ mod tests {
.then(metric.unit.cmp(&other_metric.unit)),
)
};
expect
.instrumentation_library_metrics
.sort_by(sort_instrumentation_library);
actual
.instrumentation_library_metrics
.sort_by(sort_instrumentation_library);
expect.scope_metrics.sort_by(sort_instrumentation_library);
actual.scope_metrics.sort_by(sort_instrumentation_library);

for (mut expect, mut actual) in expect
.instrumentation_library_metrics
.scope_metrics
.into_iter()
.zip(actual.instrumentation_library_metrics.into_iter())
.zip(actual.scope_metrics.into_iter())
{
assert_eq!(expect.metrics.len(), actual.metrics.len());

Expand Down Expand Up @@ -573,7 +570,9 @@ mod tests {
start_time_unix_nano: 1608891000000000000,
time_unix_nano: 1608891030000000000,
count: 3,
sum: 6f64,
sum: Some(6f64),
min: Some(1.0),
max: Some(3.0),
bucket_counts: vec![0, 0, 0, 3],
explicit_bounds: vec![0.1, 0.2, 0.3],
exemplars: vec![],
Expand Down
6 changes: 4 additions & 2 deletions opentelemetry-otlp/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl TraceService for MockServer {
.unwrap()
.try_send(request.into_inner())
.expect("Channel full");
Ok(tonic::Response::new(ExportTraceServiceResponse {}))
Ok(tonic::Response::new(ExportTraceServiceResponse {
partial_success: None,
}))
}
}

Expand Down Expand Up @@ -103,7 +105,7 @@ async fn smoke_tracer() {
.resource_spans
.get(0)
.unwrap()
.instrumentation_library_spans
.scope_spans
.get(0)
.unwrap()
.spans
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-proto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.0

Bump to use the v0.19.0 protobuf definitions. #989

## v0.1.0

Initial crate release.
2 changes: 1 addition & 1 deletion opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentelemetry-proto"
version = "0.1.0"
version = "0.2.0"
authors = ["OpenTelemetry Authors <cncf-opentelemetry-contributors@lists.cncf.io>"]
description = "Protobuf generated files and transmationes"
homepage = "https://github.com/open-telemetry/opentelemetry-rust/tree/main/opentelemetry-proto"
Expand Down
2 changes: 0 additions & 2 deletions opentelemetry-proto/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ pub mod grpcio {
#[cfg(feature = "traces")]
pub mod trace;
#[cfg(feature = "traces")]
pub mod trace_config;
#[cfg(feature = "traces")]
pub mod trace_service;
#[cfg(feature = "traces")]
pub mod trace_service_grpc;
Expand Down
Loading

0 comments on commit 57147b1

Please sign in to comment.