Skip to content

Commit

Permalink
Merge branch 'enhance-integration-tests' of github.com:lalitb/opentel…
Browse files Browse the repository at this point in the history
…emetry-rust into enhance-integration-tests
  • Loading branch information
lalitb committed Jan 23, 2025
2 parents ac1b8e8 + b340aa6 commit 06d6aac
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 142 deletions.
2 changes: 1 addition & 1 deletion opentelemetry-appender-tracing/benches/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::InstrumentationScope;
use opentelemetry_appender_tracing::layer as tracing_layer;
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::LogResult;
use opentelemetry_sdk::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LoggerProvider};
use opentelemetry_sdk::Resource;
use pprof::criterion::{Output, PProfProfiler};
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-appender-tracing/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mod tests {
use opentelemetry::trace::TracerProvider as _;
use opentelemetry::trace::{TraceContextExt, TraceFlags, Tracer};
use opentelemetry::{logs::AnyValue, Key};
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogRecord, LogResult, LoggerProvider};
use opentelemetry_sdk::testing::logs::InMemoryLogExporter;
use opentelemetry_sdk::trace::{Sampler, TracerProvider};
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/src/exporter/http/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use http::{header::CONTENT_TYPE, Method};
use opentelemetry::otel_debug;
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogError, LogResult};

use super::OtlpHttpClient;
Expand Down
9 changes: 6 additions & 3 deletions opentelemetry-otlp/src/exporter/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use opentelemetry_proto::transform::common::tonic::ResourceAttributesWithSchema;
use opentelemetry_proto::transform::logs::tonic::group_logs_by_resource_and_scope;
#[cfg(feature = "trace")]
use opentelemetry_proto::transform::trace::tonic::group_spans_by_resource_and_scope;
#[cfg(feature = "logs")]
use opentelemetry_sdk::export::logs::LogBatch;
#[cfg(feature = "trace")]
use opentelemetry_sdk::export::trace::SpanData;
#[cfg(feature = "logs")]
use opentelemetry_sdk::logs::LogBatch;
use prost::Message;
use std::collections::HashMap;
use std::env;
Expand All @@ -27,6 +27,9 @@ use std::time::Duration;
#[cfg(feature = "metrics")]
mod metrics;

#[cfg(feature = "metrics")]
use opentelemetry_sdk::metrics::data::ResourceMetrics;

#[cfg(feature = "logs")]
pub(crate) mod logs;

Expand Down Expand Up @@ -336,7 +339,7 @@ impl OtlpHttpClient {
#[cfg(feature = "metrics")]
fn build_metrics_export_body(
&self,
metrics: &mut opentelemetry_sdk::metrics::data::ResourceMetrics,
metrics: &mut ResourceMetrics,
) -> opentelemetry_sdk::metrics::MetricResult<(Vec<u8>, &'static str)> {
use opentelemetry_proto::tonic::collector::metrics::v1::ExportMetricsServiceRequest;

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/src/exporter/tonic/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use opentelemetry::otel_debug;
use opentelemetry_proto::tonic::collector::logs::v1::{
logs_service_client::LogsServiceClient, ExportLogsServiceRequest,
};
use opentelemetry_sdk::export::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogBatch, LogExporter};
use opentelemetry_sdk::logs::{LogError, LogResult};
use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Channel, Request};

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::Debug;

use opentelemetry_sdk::logs::LogResult;

use opentelemetry_sdk::export::logs::LogBatch;
use opentelemetry_sdk::logs::LogBatch;

use crate::{HasExportConfig, NoExporterBuilderSet};

Expand Down Expand Up @@ -140,7 +140,7 @@ impl LogExporter {
}
}

impl opentelemetry_sdk::export::logs::LogExporter for LogExporter {
impl opentelemetry_sdk::logs::LogExporter for LogExporter {
#[allow(clippy::manual_async_fn)]
fn export(
&self,
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-proto/src/transform/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod tonic {
transform::common::{to_nanos, tonic::ResourceAttributesWithSchema},
};
use opentelemetry::logs::{AnyValue as LogsAnyValue, Severity};
use opentelemetry_sdk::export::logs::LogBatch;
use opentelemetry_sdk::logs::LogBatch;
use std::borrow::Cow;
use std::collections::HashMap;

Expand Down Expand Up @@ -222,7 +222,7 @@ mod tests {
use crate::transform::common::tonic::ResourceAttributesWithSchema;
use opentelemetry::logs::LogRecord as _;
use opentelemetry::InstrumentationScope;
use opentelemetry_sdk::{export::logs::LogBatch, logs::LogRecord, Resource};
use opentelemetry_sdk::{logs::LogBatch, logs::LogRecord, Resource};
use std::time::SystemTime;

fn create_test_log_data(
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 @@ -10,8 +10,8 @@ pub mod tonic {

use opentelemetry::{otel_debug, Key, Value};
use opentelemetry_sdk::metrics::data::{
self, Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram,
Gauge as SdkGauge, Histogram as SdkHistogram, Metric as SdkMetric,
Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram,
Gauge as SdkGauge, Histogram as SdkHistogram, Metric as SdkMetric, ResourceMetrics,
ScopeMetrics as SdkScopeMetrics, Sum as SdkSum,
};
use opentelemetry_sdk::metrics::Temporality;
Expand Down Expand Up @@ -110,8 +110,8 @@ pub mod tonic {
}
}

impl From<&data::ResourceMetrics> for ExportMetricsServiceRequest {
fn from(rm: &data::ResourceMetrics) -> Self {
impl From<&ResourceMetrics> for ExportMetricsServiceRequest {
fn from(rm: &ResourceMetrics) -> Self {
ExportMetricsServiceRequest {
resource_metrics: vec![TonicResourceMetrics {
resource: Some((&rm.resource).into()),
Expand Down
33 changes: 23 additions & 10 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- *Feature*: Add `ResourceBuilder` for an easy way to create new `Resource`s
- *Breaking*: Remove `Resource::{new,empty,from_detectors,new_with_defaults,from_schema_url,merge,default}` from public api. To create Resources you should only use `Resource::builder()` or `Resource::builder_empty()`. See [#2322](https://github.com/open-telemetry/opentelemetry-rust/pull/2322) for a migration guide.
Example Usage:

```rust
// old
Resource::default().with_attributes([
Expand All @@ -30,6 +31,7 @@
.with_attribute(KeyValue::new("key", "value"))
.build();
```

- *Breaking* The LogExporter::export() method no longer requires a mutable reference to self.:
Before:
async fn export(&mut self, _batch: LogBatch<'_>) -> LogResult<()>
Expand Down Expand Up @@ -61,15 +63,18 @@
1. *Default Implementation, requires no async runtime* (**Recommended**) The
new default implementation does not require a runtime argument. Replace the
builder method accordingly:
- *Before:*
```rust
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter, runtime::Tokio).build();
```
- *After:*
```rust
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter).build();
*Before:*

```rust
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter, runtime::Tokio).build();
```

*After:*

```rust
let reader = opentelemetry_sdk::metrics::PeriodicReader::builder(exporter).build();
```

The new PeriodicReader can be used with OTLP Exporter, and supports
following exporter features:
- `grpc-tonic`: This requires `MeterProvider` to be created within a tokio
Expand Down Expand Up @@ -250,11 +255,11 @@ metadata, a feature introduced in version 0.1.40. [#2418](https://github.com/ope
equal signs (`"="`). [#2120](https://github.com/open-telemetry/opentelemetry-rust/pull/2120)

- **Breaking** Introduced `experimental_async_runtime` feature for runtime-specific traits.
- Runtime-specific features (`rt-tokio`, `rt-tokio-current-thread`, and `rt-async-std`)
- Runtime-specific features (`rt-tokio`, `rt-tokio-current-thread`, and `rt-async-std`)
now depend on the `experimental_async_runtime` feature.
- For most users, no action is required. Enabling runtime features such as `rt-tokio`, `rt-tokio-current-thread`,
- For most users, no action is required. Enabling runtime features such as `rt-tokio`, `rt-tokio-current-thread`,
or `rt-async-std` will automatically enable the `experimental_async_runtime` feature.
- If you're implementing a custom runtime, you must explicitly enable the experimental_async_runtime` feature in your
- If you're implementing a custom runtime, you must explicitly enable the experimental_async_runtime` feature in your
Cargo.toml and implement the required `Runtime` traits.

- Removed Metrics Cardinality Limit feature. This was originally introduced in
Expand All @@ -263,6 +268,12 @@ hardcoded limit of 2000 and no ability to change it. This feature will be
re-introduced in a future date, along with the ability to change the cardinality
limit.

- *Breaking (Affects custom LogExporter, LogProcessor authors only)*: Rename namespaces
before:
`opentelemetry_sdk::export::logs::{ExportResult, LogBatch, LogExporter};`
now:
`opentelemetry_sdk::logs::{ExportResult, LogBatch, LogExporter};`

## 0.27.1

Released 2024-Nov-27
Expand All @@ -271,6 +282,7 @@ Released 2024-Nov-27
- `trace::Config` methods are moving onto `TracerProvider` Builder to be consistent with other signals. See https://github.com/open-telemetry/opentelemetry-rust/pull/2303 for migration guide.
`trace::Config` is scheduled to be removed from public API in `v0.28.0`.
example:

```rust
// old
let tracer_provider: TracerProvider = TracerProvider::builder()
Expand All @@ -282,6 +294,7 @@ Released 2024-Nov-27
.with_resource(Resource::empty())
.build();
```

- `logs::LogData` struct is deprecated, and scheduled to be removed from public API in `v0.28.0`.
- Bug fix: Empty Meter names are retained as-is instead of replacing with
"rust.opentelemetry.io/sdk/meter"
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/benches/log_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use opentelemetry::logs::{LogRecord as _, Logger as _, LoggerProvider as _, Seve
use opentelemetry_sdk::logs::LogResult;

use opentelemetry::InstrumentationScope;
use opentelemetry_sdk::export::logs::LogBatch;
use opentelemetry_sdk::logs::LogBatch;
use opentelemetry_sdk::logs::LogProcessor;
use opentelemetry_sdk::logs::LogRecord;
use opentelemetry_sdk::logs::LoggerProvider;
Expand Down
4 changes: 0 additions & 4 deletions opentelemetry-sdk/src/export/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
//! Telemetry Export
#[cfg(feature = "logs")]
#[cfg_attr(docsrs, doc(cfg(feature = "logs")))]
pub mod logs;

#[cfg(feature = "trace")]
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
pub mod trace;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{BatchLogProcessor, LogProcessor, LogRecord, SimpleLogProcessor, TraceContext};
use crate::{export::logs::LogExporter, Resource};
use crate::{logs::LogError, logs::LogResult};
use crate::logs::{LogError, LogExporter, LogResult};
use crate::Resource;
use opentelemetry::{otel_debug, otel_info, trace::TraceContextExt, Context, InstrumentationScope};

#[cfg(feature = "spec_unstable_logs_enabled")]
Expand Down
9 changes: 3 additions & 6 deletions opentelemetry-sdk/src/logs/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
//! ```
use crate::{
export::logs::{ExportResult, LogBatch, LogExporter},
logs::{LogError, LogRecord, LogResult},
logs::{ExportResult, LogBatch, LogError, LogExporter, LogRecord, LogResult},
Resource,
};
use std::sync::mpsc::{self, RecvTimeoutError, SyncSender};
Expand Down Expand Up @@ -121,9 +120,8 @@ pub trait LogProcessor: Send + Sync + Debug {
/// ### Using a SimpleLogProcessor
///
/// ```rust
/// use opentelemetry_sdk::logs::{SimpleLogProcessor, LoggerProvider};
/// use opentelemetry_sdk::logs::{SimpleLogProcessor, LoggerProvider, LogExporter};
/// use opentelemetry::global;
/// use opentelemetry_sdk::export::logs::LogExporter;
/// use opentelemetry_sdk::testing::logs::InMemoryLogExporter;
///
/// let exporter = InMemoryLogExporter::default(); // Replace with an actual exporter
Expand Down Expand Up @@ -818,9 +816,8 @@ mod tests {
BatchLogProcessor, OTEL_BLRP_EXPORT_TIMEOUT, OTEL_BLRP_MAX_EXPORT_BATCH_SIZE,
OTEL_BLRP_MAX_QUEUE_SIZE, OTEL_BLRP_SCHEDULE_DELAY,
};
use crate::export::logs::{LogBatch, LogExporter};
use crate::logs::LogRecord;
use crate::logs::LogResult;
use crate::logs::{LogBatch, LogExporter, LogRecord};
use crate::testing::logs::InMemoryLogExporterBuilder;
use crate::{
logs::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
export::logs::{ExportResult, LogBatch, LogExporter},
logs::{LogError, LogRecord, LogResult},
logs::{ExportResult, LogBatch, LogError, LogExporter, LogRecord, LogResult},
Resource,
};

Expand Down Expand Up @@ -282,14 +281,14 @@ where

#[cfg(all(test, feature = "testing", feature = "logs"))]
mod tests {
use crate::export::logs::{LogBatch, LogExporter};
use crate::logs::log_processor::{
OTEL_BLRP_EXPORT_TIMEOUT, OTEL_BLRP_MAX_EXPORT_BATCH_SIZE, OTEL_BLRP_MAX_QUEUE_SIZE,
OTEL_BLRP_SCHEDULE_DELAY,
};
use crate::logs::log_processor_with_async_runtime::BatchLogProcessor;
use crate::logs::LogRecord;
use crate::logs::LogResult;
use crate::logs::{LogBatch, LogExporter};
use crate::runtime;
use crate::testing::logs::InMemoryLogExporterBuilder;
use crate::{
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-sdk/src/logs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! # OpenTelemetry Log SDK
mod error;
mod export;
mod log_emitter;
mod log_processor;
pub(crate) mod record;

pub use error::{LogError, LogResult};
pub use export::{ExportResult, LogBatch, LogExporter};
pub use log_emitter::{Builder, Logger, LoggerProvider};
pub use log_processor::{
BatchConfig, BatchConfigBuilder, BatchLogProcessor, BatchLogProcessorBuilder, LogProcessor,
Expand Down
23 changes: 12 additions & 11 deletions opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use opentelemetry::{otel_debug, KeyValue};
use std::sync::OnceLock;

use crate::metrics::{
data::{self, Aggregation},
data::{self, Aggregation, ExponentialHistogram},
Temporality,
};

Expand Down Expand Up @@ -386,7 +386,7 @@ impl<T: Number> ExpoHistogram<T> {
fn delta(&self, dest: Option<&mut dyn Aggregation>) -> (usize, Option<Box<dyn Aggregation>>) {
let time = self.init_time.delta();

let h = dest.and_then(|d| d.as_mut().downcast_mut::<data::ExponentialHistogram<T>>());
let h = dest.and_then(|d| d.as_mut().downcast_mut::<ExponentialHistogram<T>>());
let mut new_agg = if h.is_none() {
Some(data::ExponentialHistogram {
data_points: vec![],
Expand Down Expand Up @@ -443,7 +443,7 @@ impl<T: Number> ExpoHistogram<T> {
) -> (usize, Option<Box<dyn Aggregation>>) {
let time = self.init_time.cumulative();

let h = dest.and_then(|d| d.as_mut().downcast_mut::<data::ExponentialHistogram<T>>());
let h = dest.and_then(|d| d.as_mut().downcast_mut::<ExponentialHistogram<T>>());
let mut new_agg = if h.is_none() {
Some(data::ExponentialHistogram {
data_points: vec![],
Expand Down Expand Up @@ -528,6 +528,7 @@ where
mod tests {
use std::{ops::Neg, time::SystemTime};

use data::{ExponentialHistogram, Gauge, Histogram, Sum};
use tests::internal::AggregateFns;

use crate::metrics::internal::{self, AggregateBuilder};
Expand Down Expand Up @@ -1468,8 +1469,8 @@ mod tests {
test_name
);

if let Some(a) = a.as_any().downcast_ref::<data::Gauge<T>>() {
let b = b.as_any().downcast_ref::<data::Gauge<T>>().unwrap();
if let Some(a) = a.as_any().downcast_ref::<Gauge<T>>() {
let b = b.as_any().downcast_ref::<Gauge<T>>().unwrap();
assert_eq!(
a.data_points.len(),
b.data_points.len(),
Expand All @@ -1479,8 +1480,8 @@ mod tests {
for (a, b) in a.data_points.iter().zip(b.data_points.iter()) {
assert_gauge_data_points_eq(a, b, "mismatching gauge data points", test_name);
}
} else if let Some(a) = a.as_any().downcast_ref::<data::Sum<T>>() {
let b = b.as_any().downcast_ref::<data::Sum<T>>().unwrap();
} else if let Some(a) = a.as_any().downcast_ref::<Sum<T>>() {
let b = b.as_any().downcast_ref::<Sum<T>>().unwrap();
assert_eq!(
a.temporality, b.temporality,
"{} mismatching sum temporality",
Expand All @@ -1500,8 +1501,8 @@ mod tests {
for (a, b) in a.data_points.iter().zip(b.data_points.iter()) {
assert_sum_data_points_eq(a, b, "mismatching sum data points", test_name);
}
} else if let Some(a) = a.as_any().downcast_ref::<data::Histogram<T>>() {
let b = b.as_any().downcast_ref::<data::Histogram<T>>().unwrap();
} else if let Some(a) = a.as_any().downcast_ref::<Histogram<T>>() {
let b = b.as_any().downcast_ref::<Histogram<T>>().unwrap();
assert_eq!(
a.temporality, b.temporality,
"{}: mismatching hist temporality",
Expand All @@ -1516,10 +1517,10 @@ mod tests {
for (a, b) in a.data_points.iter().zip(b.data_points.iter()) {
assert_hist_data_points_eq(a, b, "mismatching hist data points", test_name);
}
} else if let Some(a) = a.as_any().downcast_ref::<data::ExponentialHistogram<T>>() {
} else if let Some(a) = a.as_any().downcast_ref::<ExponentialHistogram<T>>() {
let b = b
.as_any()
.downcast_ref::<data::ExponentialHistogram<T>>()
.downcast_ref::<ExponentialHistogram<T>>()
.unwrap();
assert_eq!(
a.temporality, b.temporality,
Expand Down
Loading

0 comments on commit 06d6aac

Please sign in to comment.