Skip to content

Commit

Permalink
Merge branch 'main' into remove-global-error-handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 28, 2024
2 parents f35e0ec + a736604 commit 699124c
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 138 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ you're more than welcome to participate!
* [Harold Dost](https://github.com/hdost)
* [Julian Tescher](https://github.com/jtescher)
* [Lalit Kumar Bhasin](https://github.com/lalitb)
* [Utkarsh Umesan Pillai](https://github.com/utpilla)
* [Zhongyang Wu](https://github.com/TommyCpp)

### Approvers

* [Shaun Cox](https://github.com/shaun-cox)
* [Utkarsh Umesan Pillai](https://github.com/utpilla)

### Emeritus

Expand Down
2 changes: 1 addition & 1 deletion examples/metrics-advanced/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
};

// Build exporter using Delta Temporality.
let exporter = opentelemetry_stdout::MetricsExporterBuilder::default()
let exporter = opentelemetry_stdout::MetricExporterBuilder::default()
.with_temporality(Temporality::Delta)
.build();

Expand Down
2 changes: 1 addition & 1 deletion examples/metrics-basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::error::Error;
use std::vec;

fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
let exporter = opentelemetry_stdout::MetricsExporterBuilder::default()
let exporter = opentelemetry_stdout::MetricExporterBuilder::default()
// Build exporter using Delta Temporality (Defaults to Temporality::Cumulative)
// .with_temporality(data::Temporality::Delta)
.build();
Expand Down
4 changes: 2 additions & 2 deletions examples/self-diagnostics/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use opentelemetry::global::{self, set_error_handler, Error as OtelError};
use opentelemetry::KeyValue;
use opentelemetry_appender_tracing::layer;
use opentelemetry_otlp::{LogExporter, MetricsExporter, WithExportConfig};
use opentelemetry_otlp::{LogExporter, MetricExporter, WithExportConfig};
use opentelemetry_sdk::metrics::PeriodicReader;
use tracing_subscriber::filter::{EnvFilter, LevelFilter};
use tracing_subscriber::fmt;
Expand Down Expand Up @@ -109,7 +109,7 @@ fn init_logger_provider() -> opentelemetry_sdk::logs::LoggerProvider {
}

fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
let exporter = MetricsExporter::builder()
let exporter = MetricExporter::builder()
.with_http()
.with_endpoint("http://localhost:4318/v1/metrics")
.build()
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Released 2024-Sep-30
.build()?,
).build();
```
- **Renamed**
- ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types.
- `MetricsExporter` -> `MetricExporter`
- `MetricsExporterBuilder` -> `MetricExporterBuilder`

## v0.25.0

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use opentelemetry::{
};
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_otlp::{LogExporter, MetricsExporter, Protocol, SpanExporter};
use opentelemetry_otlp::{LogExporter, MetricExporter, Protocol, SpanExporter};
use opentelemetry_sdk::{
logs::LoggerProvider,
metrics::{PeriodicReader, SdkMeterProvider},
Expand Down Expand Up @@ -66,7 +66,7 @@ fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
}

fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, MetricError> {
let exporter = MetricsExporter::builder()
let exporter = MetricExporter::builder()
.with_http()
.with_protocol(Protocol::HttpBinary) //can be changed to `Protocol::HttpJson` to export in JSON format
.with_endpoint("http://localhost:4318/v1/metrics")
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ SpanEvent #0
### Metric

```text
2024-05-22T20:25:42.908Z info MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "logging", "resource metrics": 1, "metrics": 1, "data points": 1}
2024-05-22T20:25:42.908Z info MetricExporter {"kind": "exporter", "data_type": "metrics", "name": "logging", "resource metrics": 1, "metrics": 1, "data points": 1}
2024-05-22T20:25:42.908Z info ResourceMetrics #0
Resource SchemaURL:
Resource attributes:
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use opentelemetry::trace::{TraceContextExt, TraceError, Tracer};
use opentelemetry::KeyValue;
use opentelemetry::{global, InstrumentationScope};
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
use opentelemetry_otlp::{LogExporter, MetricsExporter, SpanExporter, WithExportConfig};
use opentelemetry_otlp::{LogExporter, MetricExporter, SpanExporter, WithExportConfig};
use opentelemetry_sdk::logs::LoggerProvider;
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider};
use opentelemetry_sdk::trace::Config;
Expand Down Expand Up @@ -34,7 +34,7 @@ fn init_tracer_provider() -> Result<sdktrace::TracerProvider, TraceError> {
}

fn init_metrics() -> Result<opentelemetry_sdk::metrics::SdkMeterProvider, MetricError> {
let exporter = MetricsExporter::builder().with_tonic().build()?;
let exporter = MetricExporter::builder().with_tonic().build()?;

let reader = PeriodicReader::builder(exporter, runtime::Tokio).build();

Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-otlp/src/exporter/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Default for HttpConfig {
///
/// // Create a metrics exporter you can use when configuring meter providers
/// # #[cfg(feature="metrics")]
/// let metrics_exporter = opentelemetry_otlp::MetricsExporter::builder()
/// let metrics_exporter = opentelemetry_otlp::MetricExporter::builder()
/// .with_http()
/// .with_temporality(Temporality::default())
/// .build()?;
Expand Down Expand Up @@ -221,7 +221,7 @@ impl HttpExporterBuilder {
pub fn build_metrics_exporter(
mut self,
temporality: opentelemetry_sdk::metrics::data::Temporality,
) -> opentelemetry::metrics::MetricResult<crate::MetricsExporter> {
) -> opentelemetry::metrics::MetricResult<crate::MetricExporter> {
use crate::{
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS,
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT,
Expand All @@ -234,7 +234,7 @@ impl HttpExporterBuilder {
OTEL_EXPORTER_OTLP_METRICS_HEADERS,
)?;

Ok(crate::MetricsExporter::new(client, temporality))
Ok(crate::MetricExporter::new(client, temporality))
}
}

Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-otlp/src/exporter/tonic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl TryFrom<Compression> for tonic::codec::CompressionEncoding {
///
/// // Create a metric exporter you can use when configuring meter providers
/// # #[cfg(feature="metrics")]
/// let metric_exporter = opentelemetry_otlp::MetricsExporter::builder()
/// let metric_exporter = opentelemetry_otlp::MetricExporter::builder()
/// .with_tonic()
/// .with_temporality(Temporality::default())
/// .build()?;
Expand Down Expand Up @@ -274,8 +274,8 @@ impl TonicExporterBuilder {
pub(crate) fn build_metrics_exporter(
self,
temporality: opentelemetry_sdk::metrics::data::Temporality,
) -> opentelemetry::metrics::MetricResult<crate::MetricsExporter> {
use crate::MetricsExporter;
) -> opentelemetry::metrics::MetricResult<crate::MetricExporter> {
use crate::MetricExporter;
use metrics::TonicMetricsClient;

let (channel, interceptor, compression) = self.build_channel(
Expand All @@ -287,7 +287,7 @@ impl TonicExporterBuilder {

let client = TonicMetricsClient::new(channel, interceptor, compression);

Ok(MetricsExporter::new(client, temporality))
Ok(MetricExporter::new(client, temporality))
}

/// Build a new tonic span exporter
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-otlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! telemetry.
//!
//! You will have to build a OTLP exporter first. Create the correct exporter based on the signal
//! you are looking to export `SpanExporter::builder()`, `MetricsExporter::builder()`,
//! you are looking to export `SpanExporter::builder()`, `MetricExporter::builder()`,
//! `LogExporter::builder()` respectively for traces, metrics, and logs.
//!
//! Once you have the exporter, you can create your `Provider` by starting with `TracerProvider::builder()`,
Expand Down Expand Up @@ -124,7 +124,7 @@
//!
//! Generally there are two parts of configuration. One is the exporter, the other is the provider.
//! Users can configure the exporter using [SpanExporter::builder()] for traces,
//! and [MetricsExporter::builder()] + [opentelemetry_sdk::metrics::PeriodicReader::builder()] for metrics.
//! and [MetricExporter::builder()] + [opentelemetry_sdk::metrics::PeriodicReader::builder()] for metrics.
//! Once you have an exporter, you can add it to either a [opentelemetry_sdk::trace::TracerProvider::builder()] for traces,
//! or [opentelemetry_sdk::metrics::SdkMeterProvider::builder()] for metrics.
//!
Expand Down Expand Up @@ -171,7 +171,7 @@
//!
//! # #[cfg(all(feature = "metrics", feature = "grpc-tonic"))]
//! # {
//! let exporter = opentelemetry_otlp::MetricsExporter::builder()
//! let exporter = opentelemetry_otlp::MetricExporter::builder()
//! .with_tonic()
//! .with_endpoint("http://localhost:4318/v1/metrics")
//! .with_protocol(Protocol::Grpc)
Expand Down Expand Up @@ -240,7 +240,7 @@ pub use crate::span::{
#[cfg(feature = "metrics")]
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
pub use crate::metric::{
MetricsExporter, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
MetricExporter, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT,
};

Expand Down
60 changes: 30 additions & 30 deletions opentelemetry-otlp/src/metric.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! OTEL metric exporter
//!
//! Defines a [MetricsExporter] to send metric data to backend via OTLP protocol.
//! Defines a [MetricExporter] to send metric data to backend via OTLP protocol.
//!
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
Expand All @@ -20,7 +20,7 @@ use opentelemetry::metrics::MetricResult;

use opentelemetry_sdk::metrics::{
data::{ResourceMetrics, Temporality},
exporter::PushMetricsExporter,
exporter::PushMetricExporter,
};
use std::fmt::{Debug, Formatter};

Expand All @@ -39,81 +39,81 @@ pub const OTEL_EXPORTER_OTLP_METRICS_COMPRESSION: &str = "OTEL_EXPORTER_OTLP_MET
pub const OTEL_EXPORTER_OTLP_METRICS_HEADERS: &str = "OTEL_EXPORTER_OTLP_METRICS_HEADERS";

#[derive(Debug, Default, Clone)]
pub struct MetricsExporterBuilder<C> {
pub struct MetricExporterBuilder<C> {
client: C,
temporality: Temporality,
}

impl MetricsExporterBuilder<NoExporterBuilderSet> {
impl MetricExporterBuilder<NoExporterBuilderSet> {
pub fn new() -> Self {
MetricsExporterBuilder::default()
MetricExporterBuilder::default()
}
}

impl<C> MetricsExporterBuilder<C> {
impl<C> MetricExporterBuilder<C> {
#[cfg(feature = "grpc-tonic")]
pub fn with_tonic(self) -> MetricsExporterBuilder<TonicExporterBuilderSet> {
MetricsExporterBuilder {
pub fn with_tonic(self) -> MetricExporterBuilder<TonicExporterBuilderSet> {
MetricExporterBuilder {
client: TonicExporterBuilderSet(TonicExporterBuilder::default()),
temporality: self.temporality,
}
}

#[cfg(any(feature = "http-proto", feature = "http-json"))]
pub fn with_http(self) -> MetricsExporterBuilder<HttpExporterBuilderSet> {
MetricsExporterBuilder {
pub fn with_http(self) -> MetricExporterBuilder<HttpExporterBuilderSet> {
MetricExporterBuilder {
client: HttpExporterBuilderSet(HttpExporterBuilder::default()),
temporality: self.temporality,
}
}

pub fn with_temporality(self, temporality: Temporality) -> MetricsExporterBuilder<C> {
MetricsExporterBuilder {
pub fn with_temporality(self, temporality: Temporality) -> MetricExporterBuilder<C> {
MetricExporterBuilder {
client: self.client,
temporality,
}
}
}

#[cfg(feature = "grpc-tonic")]
impl MetricsExporterBuilder<TonicExporterBuilderSet> {
pub fn build(self) -> MetricResult<MetricsExporter> {
impl MetricExporterBuilder<TonicExporterBuilderSet> {
pub fn build(self) -> MetricResult<MetricExporter> {
let exporter = self.client.0.build_metrics_exporter(self.temporality)?;
Ok(exporter)
}
}

#[cfg(any(feature = "http-proto", feature = "http-json"))]
impl MetricsExporterBuilder<HttpExporterBuilderSet> {
pub fn build(self) -> MetricResult<MetricsExporter> {
impl MetricExporterBuilder<HttpExporterBuilderSet> {
pub fn build(self) -> MetricResult<MetricExporter> {
let exporter = self.client.0.build_metrics_exporter(self.temporality)?;
Ok(exporter)
}
}

#[cfg(feature = "grpc-tonic")]
impl HasExportConfig for MetricsExporterBuilder<TonicExporterBuilderSet> {
impl HasExportConfig for MetricExporterBuilder<TonicExporterBuilderSet> {
fn export_config(&mut self) -> &mut crate::ExportConfig {
&mut self.client.0.exporter_config
}
}

#[cfg(any(feature = "http-proto", feature = "http-json"))]
impl HasExportConfig for MetricsExporterBuilder<HttpExporterBuilderSet> {
impl HasExportConfig for MetricExporterBuilder<HttpExporterBuilderSet> {
fn export_config(&mut self) -> &mut crate::ExportConfig {
&mut self.client.0.exporter_config
}
}

#[cfg(feature = "grpc-tonic")]
impl HasTonicConfig for MetricsExporterBuilder<TonicExporterBuilderSet> {
impl HasTonicConfig for MetricExporterBuilder<TonicExporterBuilderSet> {
fn tonic_config(&mut self) -> &mut crate::TonicConfig {
&mut self.client.0.tonic_config
}
}

#[cfg(any(feature = "http-proto", feature = "http-json"))]
impl HasHttpConfig for MetricsExporterBuilder<HttpExporterBuilderSet> {
impl HasHttpConfig for MetricExporterBuilder<HttpExporterBuilderSet> {
fn http_client_config(&mut self) -> &mut crate::exporter::http::HttpConfig {
&mut self.client.0.http_config
}
Expand All @@ -127,19 +127,19 @@ pub trait MetricsClient: fmt::Debug + Send + Sync + 'static {
}

/// Export metrics in OTEL format.
pub struct MetricsExporter {
pub struct MetricExporter {
client: Box<dyn MetricsClient>,
temporality: Temporality,
}

impl Debug for MetricsExporter {
impl Debug for MetricExporter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("MetricsExporter").finish()
f.debug_struct("MetricExporter").finish()
}
}

#[async_trait]
impl PushMetricsExporter for MetricsExporter {
impl PushMetricExporter for MetricExporter {
async fn export(&self, metrics: &mut ResourceMetrics) -> MetricResult<()> {
self.client.export(metrics).await
}
Expand All @@ -158,15 +158,15 @@ impl PushMetricsExporter for MetricsExporter {
}
}

impl MetricsExporter {
/// Obtain a builder to configure a [MetricsExporter].
pub fn builder() -> MetricsExporterBuilder<NoExporterBuilderSet> {
MetricsExporterBuilder::default()
impl MetricExporter {
/// Obtain a builder to configure a [MetricExporter].
pub fn builder() -> MetricExporterBuilder<NoExporterBuilderSet> {
MetricExporterBuilder::default()
}

/// Create a new metrics exporter
pub fn new(client: impl MetricsClient, temporality: Temporality) -> MetricsExporter {
MetricsExporter {
pub fn new(client: impl MetricsClient, temporality: Temporality) -> MetricExporter {
MetricExporter {
client: Box::new(client),
temporality,
}
Expand Down
30 changes: 17 additions & 13 deletions opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@
- Bump MSRV to 1.70 [#2179](https://github.com/open-telemetry/opentelemetry-rust/pull/2179)
- Implement `LogRecord::set_trace_context` for `LogRecord`. Respect any trace context set on a `LogRecord` when emitting through a `Logger`.
- Improved `LoggerProvider` shutdown handling to prevent redundant shutdown calls when `drop` is invoked. [#2195](https://github.com/open-telemetry/opentelemetry-rust/pull/2195)
- **BREAKING**: [#2217](https://github.com/open-telemetry/opentelemetry-rust/pull/2217)
- **Replaced**: Removed `{Delta,Cumulative}TemporalitySelector::new()` in favor of directly using `Temporality` enum to simplify the configuration of MetricsExporterBuilder with different temporalities.
- When creating new metric instruments, SDK would return a no-op instrument if the validation fails. [#2166](https://github.com/open-telemetry/opentelemetry-rust/pull/2166)
- **Breaking change for Metrics users:** The `init` method used to create instruments has been renamed to `build`.

Before:
```rust
let counter = meter.u64_counter("my_counter").init();
```

Now:
```rust
let counter = meter.u64_counter("my_counter").build();
```
- **BREAKING for Metrics users**:
- **Replaced**
- ([#2217](https://github.com/open-telemetry/opentelemetry-rust/pull/2217)): Removed `{Delta,Cumulative}TemporalitySelector::new()` in favor of directly using `Temporality` enum to simplify the configuration of MetricsExporterBuilder with different temporalities.
- **Renamed**
- ([#2232](https://github.com/open-telemetry/opentelemetry-rust/pull/2232)): The `init` method used to create instruments has been renamed to `build`.
Before:
```rust
let counter = meter.u64_counter("my_counter").init();
```
Now:
```rust
let counter = meter.u64_counter("my_counter").build();
```
- ([#2255](https://github.com/open-telemetry/opentelemetry-rust/pull/2255)): de-pluralize Metric types.
- `PushMetricsExporter` -> `PushMetricExporter`
- `InMemoryMetricsExporter` -> `InMemoryMetricExporter`
- `InMemoryMetricsExporterBuilder` -> `InMemoryMetricExporterBuilder`
- **BREAKING**: [#2220](https://github.com/open-telemetry/opentelemetry-rust/pull/2220)
- Removed `InstrumentationLibrary` re-export and its `Scope` alias, use `opentelemetry::InstrumentationLibrary` instead.
- Unified builders across signals
Expand Down
Loading

0 comments on commit 699124c

Please sign in to comment.