Skip to content

Commit 58d1501

Browse files
committed
Move Views under feature flag
1 parent b833118 commit 58d1501

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-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/Cargo.toml

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

5758
[[bench]]
5859
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
@@ -56,12 +56,22 @@ pub(crate) mod view;
5656

5757
pub use aggregation::*;
5858
pub use error::{MetricError, MetricResult};
59-
pub use instrument::*;
6059
pub use manual_reader::*;
6160
pub use meter_provider::*;
6261
pub use periodic_reader::*;
6362
pub use pipeline::Pipeline;
63+
64+
pub use instrument::InstrumentKind;
65+
66+
#[cfg(feature = "spec_unstable_metrics_views")]
67+
pub use instrument::*;
68+
// #[cfg(not(feature = "spec_unstable_metrics_views"))]
69+
// pub(crate) use instrument::*;
70+
71+
#[cfg(feature = "spec_unstable_metrics_views")]
6472
pub use view::*;
73+
// #[cfg(not(feature = "spec_unstable_metrics_views"))]
74+
// pub(crate) use view::*;
6575

6676
use std::collections::hash_map::DefaultHasher;
6777
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)