Skip to content

Commit 648710e

Browse files
authored
Move Views under feature flag (#2298)
1 parent 47d5016 commit 648710e

File tree

7 files changed

+25
-2
lines changed

7 files changed

+25
-2
lines changed

examples/metrics-advanced/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77

88
[dependencies]
99
opentelemetry = { path = "../../opentelemetry", features = ["metrics"] }
10-
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["metrics", "rt-tokio"] }
10+
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["spec_unstable_metrics_views", "rt-tokio"] }
1111
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["metrics"] }
1212
tokio = { workspace = true, features = ["full"] }
1313
serde_json = { workspace = true }

opentelemetry-sdk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
- **BREAKING**: `Temporality` enum moved from `opentelemetry_sdk::metrics::data::Temporality` to `opentelemetry_sdk::metrics::Temporality`.
5151

52+
- **BREAKING**: `Views` are now an opt-in ONLY feature. Please include the feature `spec_unstable_metrics_views` to enable `Views`. It will be stabilized post 1.0 stable release of the SDK. [#2295](https://github.com/open-telemetry/opentelemetry-rust/issues/2295)
53+
5254
- Added a new `PeriodicReader` implementation (`PeriodicReaderWithOwnThread`)
5355
that does not rely on an async runtime, and instead creates own Thread. This
5456
is under feature flag "experimental_metrics_periodic_reader_no_runtime". The

opentelemetry-sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ rt-tokio-current-thread = ["tokio", "tokio-stream"]
5454
rt-async-std = ["async-std"]
5555
internal-logs = ["tracing"]
5656
experimental_metrics_periodic_reader_no_runtime = ["metrics"]
57+
spec_unstable_metrics_views = ["metrics"]
5758

5859
[[bench]]
5960
name = "context"

opentelemetry-sdk/src/metrics/instrument.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl InstrumentKind {
8383
/// ```
8484
#[derive(Clone, Default, Debug, PartialEq)]
8585
#[non_exhaustive]
86+
#[allow(unreachable_pub)]
8687
pub struct Instrument {
8788
/// The human-readable identifier of the instrument.
8889
pub name: Cow<'static, str>,
@@ -96,6 +97,7 @@ pub struct Instrument {
9697
pub scope: InstrumentationScope,
9798
}
9899

100+
#[cfg(feature = "spec_unstable_metrics_views")]
99101
impl Instrument {
100102
/// Create a new instrument with default values
101103
pub fn new() -> Self {
@@ -185,6 +187,7 @@ impl Instrument {
185187
/// ```
186188
#[derive(Default, Debug)]
187189
#[non_exhaustive]
190+
#[allow(unreachable_pub)]
188191
pub struct Stream {
189192
/// The human-readable identifier of the stream.
190193
pub name: Cow<'static, str>,
@@ -202,6 +205,7 @@ pub struct Stream {
202205
pub allowed_attribute_keys: Option<Arc<HashSet<Key>>>,
203206
}
204207

208+
#[cfg(feature = "spec_unstable_metrics_views")]
205209
impl Stream {
206210
/// Create a new stream with empty values.
207211
pub fn new() -> Self {

opentelemetry-sdk/src/metrics/meter_provider.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ impl MeterProviderBuilder {
215215
self
216216
}
217217

218+
#[cfg(feature = "spec_unstable_metrics_views")]
218219
/// Associates a [View] with a [MeterProvider].
219220
///
220221
/// [View]s are appended to existing ones in a [MeterProvider] if this option is

opentelemetry-sdk/src/metrics/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,24 @@ pub(crate) mod view;
5858

5959
pub use aggregation::*;
6060
pub use error::{MetricError, MetricResult};
61-
pub use instrument::*;
6261
pub use manual_reader::*;
6362
pub use meter_provider::*;
6463
pub use periodic_reader::*;
6564
#[cfg(feature = "experimental_metrics_periodic_reader_no_runtime")]
6665
pub use periodic_reader_with_own_thread::*;
6766
pub use pipeline::Pipeline;
67+
68+
pub use instrument::InstrumentKind;
69+
70+
#[cfg(feature = "spec_unstable_metrics_views")]
71+
pub use instrument::*;
72+
// #[cfg(not(feature = "spec_unstable_metrics_views"))]
73+
// pub(crate) use instrument::*;
74+
75+
#[cfg(feature = "spec_unstable_metrics_views")]
6876
pub use view::*;
77+
// #[cfg(not(feature = "spec_unstable_metrics_views"))]
78+
// pub(crate) use view::*;
6979

7080
use std::collections::hash_map::DefaultHasher;
7181
use std::collections::HashSet;

opentelemetry-sdk/src/metrics/view.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use super::instrument::{Instrument, Stream};
2+
#[cfg(feature = "spec_unstable_metrics_views")]
23
use crate::metrics::{MetricError, MetricResult};
4+
#[cfg(feature = "spec_unstable_metrics_views")]
35
use glob::Pattern;
46

7+
#[cfg(feature = "spec_unstable_metrics_views")]
58
fn empty_view(_inst: &Instrument) -> Option<Stream> {
69
None
710
}
@@ -42,6 +45,7 @@ fn empty_view(_inst: &Instrument) -> Option<Stream> {
4245
/// let provider = SdkMeterProvider::builder().with_view(my_view).build();
4346
/// # drop(provider)
4447
/// ```
48+
#[allow(unreachable_pub)]
4549
pub trait View: Send + Sync + 'static {
4650
/// Defines how data should be collected for certain instruments.
4751
///
@@ -65,6 +69,7 @@ impl View for Box<dyn View> {
6569
}
6670
}
6771

72+
#[cfg(feature = "spec_unstable_metrics_views")]
6873
/// Creates a [View] that applies the [Stream] mask for all instruments that
6974
/// match criteria.
7075
///

0 commit comments

Comments
 (0)