Skip to content

Commit 9f409d7

Browse files
committed
Merge remote-tracking branch 'origin/main' into adjust-msrv
2 parents 93e556b + 4b3a383 commit 9f409d7

File tree

28 files changed

+1388
-558
lines changed

28 files changed

+1388
-558
lines changed

examples/metrics-advanced/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ bench = false
1414

1515
[dependencies]
1616
opentelemetry = { path = "../../opentelemetry", features = ["metrics"] }
17-
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["spec_unstable_metrics_views"] }
17+
opentelemetry_sdk = { path = "../../opentelemetry-sdk" }
1818
opentelemetry-stdout = { workspace = true, features = ["metrics"] }
1919
tokio = { workspace = true, features = ["full"] }

examples/metrics-advanced/src/main.rs

Lines changed: 31 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
use opentelemetry::global;
2-
use opentelemetry::Key;
32
use opentelemetry::KeyValue;
4-
use opentelemetry_sdk::metrics::{Aggregation, Instrument, SdkMeterProvider, Stream, Temporality};
3+
use opentelemetry_sdk::metrics::{Instrument, SdkMeterProvider, Stream, Temporality};
54
use opentelemetry_sdk::Resource;
65
use std::error::Error;
76

87
fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
98
// for example 1
109
let my_view_rename_and_unit = |i: &Instrument| {
11-
if i.name == "my_histogram" {
10+
if i.name() == "my_histogram" {
1211
Some(
13-
Stream::new()
14-
.name("my_histogram_renamed")
15-
.unit("milliseconds"),
12+
Stream::builder()
13+
.with_name("my_histogram_renamed")
14+
.with_unit("milliseconds")
15+
.build()
16+
.unwrap(),
1617
)
1718
} else {
1819
None
1920
}
2021
};
2122

2223
// for example 2
23-
let my_view_drop_attributes = |i: &Instrument| {
24-
if i.name == "my_counter" {
25-
Some(Stream::new().allowed_attribute_keys(vec![Key::from("mykey1")]))
26-
} else {
27-
None
28-
}
29-
};
30-
31-
// for example 3
32-
let my_view_change_aggregation = |i: &Instrument| {
33-
if i.name == "my_second_histogram" {
34-
Some(
35-
Stream::new().aggregation(Aggregation::ExplicitBucketHistogram {
36-
boundaries: vec![0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5],
37-
record_min_max: false,
38-
}),
39-
)
24+
let my_view_change_cardinality = |i: &Instrument| {
25+
if i.name() == "my_second_histogram" {
26+
// Note: If Stream is invalid, build() will return an error. By
27+
// calling `.ok()`, any such error is ignored and treated as if the
28+
// view does not match the instrument. If this is not the desired
29+
// behavior, consider handling the error explicitly.
30+
Stream::builder().with_cardinality_limit(2).build().ok()
4031
} else {
4132
None
4233
}
@@ -55,8 +46,7 @@ fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
5546
.with_periodic_exporter(exporter)
5647
.with_resource(resource)
5748
.with_view(my_view_rename_and_unit)
58-
.with_view(my_view_drop_attributes)
59-
.with_view(my_view_change_aggregation)
49+
.with_view(my_view_change_cardinality)
6050
.build();
6151
global::set_meter_provider(provider.clone());
6252
provider
@@ -88,65 +78,31 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8878
],
8979
);
9080

91-
// Example 2 - Drop unwanted attributes using view.
92-
let counter = meter.u64_counter("my_counter").build();
93-
94-
// Record measurements using the Counter instrument.
95-
// Though we are passing 4 attributes here, only 1 will be used
96-
// for aggregation as view is configured to use only "mykey1"
97-
// attribute.
98-
counter.add(
99-
10,
100-
&[
101-
KeyValue::new("mykey1", "myvalue1"),
102-
KeyValue::new("mykey2", "myvalue2"),
103-
KeyValue::new("mykey3", "myvalue3"),
104-
KeyValue::new("mykey4", "myvalue4"),
105-
],
106-
);
107-
108-
// Example 3 - Change Aggregation configuration using View.
109-
// Histograms are by default aggregated using ExplicitBucketHistogram
110-
// with default buckets. The configured view will change the aggregation to
111-
// use a custom set of boundaries, and min/max values will not be recorded.
81+
// Example 2 - Change cardinality using View.
11282
let histogram2 = meter
11383
.f64_histogram("my_second_histogram")
11484
.with_unit("ms")
11585
.with_description("My histogram example description")
11686
.build();
11787

11888
// Record measurements using the histogram instrument.
119-
// The values recorded are in the range of 1.2 to 1.5, warranting
120-
// the change of boundaries.
121-
histogram2.record(
122-
1.5,
123-
&[
124-
KeyValue::new("mykey1", "myvalue1"),
125-
KeyValue::new("mykey2", "myvalue2"),
126-
KeyValue::new("mykey3", "myvalue3"),
127-
KeyValue::new("mykey4", "myvalue4"),
128-
],
129-
);
89+
// This metric will have a cardinality limit of 2,
90+
// as set in the view. Because of this, only the first two
91+
// measurements will be recorded, and the rest will be folded
92+
// into the overflow attribute.
93+
histogram2.record(1.5, &[KeyValue::new("mykey1", "v1")]);
13094

131-
histogram2.record(
132-
1.2,
133-
&[
134-
KeyValue::new("mykey1", "myvalue1"),
135-
KeyValue::new("mykey2", "myvalue2"),
136-
KeyValue::new("mykey3", "myvalue3"),
137-
KeyValue::new("mykey4", "myvalue4"),
138-
],
139-
);
95+
histogram2.record(1.2, &[KeyValue::new("mykey1", "v2")]);
14096

141-
histogram2.record(
142-
1.23,
143-
&[
144-
KeyValue::new("mykey1", "myvalue1"),
145-
KeyValue::new("mykey2", "myvalue2"),
146-
KeyValue::new("mykey3", "myvalue3"),
147-
KeyValue::new("mykey4", "myvalue4"),
148-
],
149-
);
97+
histogram2.record(1.23, &[KeyValue::new("mykey1", "v3")]);
98+
99+
histogram2.record(1.4, &[KeyValue::new("mykey1", "v4")]);
100+
101+
histogram2.record(1.6, &[KeyValue::new("mykey1", "v5")]);
102+
103+
histogram2.record(1.7, &[KeyValue::new("mykey1", "v6")]);
104+
105+
histogram2.record(1.8, &[KeyValue::new("mykey1", "v7")]);
150106

151107
// Metrics are exported by default every 30 seconds when using stdout exporter,
152108
// however shutting down the MeterProvider here instantly flushes

opentelemetry-otlp/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
- Update `tonic` dependency version to 0.13
66
- Re-export `tonic` types under `tonic_types`
77
[2898](https://github.com/open-telemetry/opentelemetry-rust/pull/2898)
8-
- It is now possible to add links to a `Span` via the `SpanRef` that you get from
9-
a `Context`. [2959](https://github.com/open-telemetry/opentelemetry-rust/pull/2959)
8+
- Publicly re-exported `MetricExporterBuilder`, `SpanExporterBuilder`, and
9+
`LogExporterBuilder` types, enabling users to directly reference and use these
10+
builder types for metrics, traces, and logs exporters.
11+
[2966](https://github.com/open-telemetry/opentelemetry-rust/pull/2966)
1012

1113
## 0.29.0
1214

opentelemetry-otlp/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,22 +374,25 @@ pub use crate::exporter::ExporterBuildError;
374374
#[cfg(feature = "trace")]
375375
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
376376
pub use crate::span::{
377-
SpanExporter, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION, OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
378-
OTEL_EXPORTER_OTLP_TRACES_HEADERS, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
377+
SpanExporter, SpanExporterBuilder, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION,
378+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_HEADERS,
379+
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT,
379380
};
380381

381382
#[cfg(feature = "metrics")]
382383
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
383384
pub use crate::metric::{
384-
MetricExporter, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION, OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
385-
OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT,
385+
MetricExporter, MetricExporterBuilder, OTEL_EXPORTER_OTLP_METRICS_COMPRESSION,
386+
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS,
387+
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT,
386388
};
387389

388390
#[cfg(feature = "logs")]
389391
#[cfg(any(feature = "http-proto", feature = "http-json", feature = "grpc-tonic"))]
390392
pub use crate::logs::{
391-
LogExporter, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION, OTEL_EXPORTER_OTLP_LOGS_ENDPOINT,
392-
OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
393+
LogExporter, LogExporterBuilder, OTEL_EXPORTER_OTLP_LOGS_COMPRESSION,
394+
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_HEADERS,
395+
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT,
393396
};
394397

395398
#[cfg(any(feature = "http-proto", feature = "http-json"))]

opentelemetry-otlp/src/logs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ pub const OTEL_EXPORTER_OTLP_LOGS_TIMEOUT: &str = "OTEL_EXPORTER_OTLP_LOGS_TIMEO
3131
/// Note: this is only supported for HTTP.
3232
pub const OTEL_EXPORTER_OTLP_LOGS_HEADERS: &str = "OTEL_EXPORTER_OTLP_LOGS_HEADERS";
3333

34+
/// Builder for creating a new [LogExporter].
3435
#[derive(Debug, Default, Clone)]
3536
pub struct LogExporterBuilder<C> {
3637
client: C,
3738
endpoint: Option<String>,
3839
}
3940

4041
impl LogExporterBuilder<NoExporterBuilderSet> {
42+
/// Create a new [LogExporterBuilder] with default settings.
4143
pub fn new() -> Self {
4244
LogExporterBuilder::default()
4345
}
4446

47+
/// With the gRPC Tonic transport.
4548
#[cfg(feature = "grpc-tonic")]
4649
pub fn with_tonic(self) -> LogExporterBuilder<TonicExporterBuilderSet> {
4750
LogExporterBuilder {
@@ -50,6 +53,7 @@ impl LogExporterBuilder<NoExporterBuilderSet> {
5053
}
5154
}
5255

56+
/// With the HTTP transport.
5357
#[cfg(any(feature = "http-proto", feature = "http-json"))]
5458
pub fn with_http(self) -> LogExporterBuilder<HttpExporterBuilderSet> {
5559
LogExporterBuilder {
@@ -61,6 +65,7 @@ impl LogExporterBuilder<NoExporterBuilderSet> {
6165

6266
#[cfg(feature = "grpc-tonic")]
6367
impl LogExporterBuilder<TonicExporterBuilderSet> {
68+
/// Build the [LogExporter] with the gRPC Tonic transport.
6469
pub fn build(self) -> Result<LogExporter, ExporterBuildError> {
6570
let result = self.client.0.build_log_exporter();
6671
otel_debug!(name: "LogExporterBuilt", result = format!("{:?}", &result));
@@ -70,6 +75,7 @@ impl LogExporterBuilder<TonicExporterBuilderSet> {
7075

7176
#[cfg(any(feature = "http-proto", feature = "http-json"))]
7277
impl LogExporterBuilder<HttpExporterBuilderSet> {
78+
/// Build the [LogExporter] with the HTTP transport.
7379
pub fn build(self) -> Result<LogExporter, ExporterBuildError> {
7480
self.client.0.build_log_exporter()
7581
}

opentelemetry-otlp/src/metric.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,22 @@ pub const OTEL_EXPORTER_OTLP_METRICS_COMPRESSION: &str = "OTEL_EXPORTER_OTLP_MET
3737
/// Note: this is only supported for HTTP.
3838
pub const OTEL_EXPORTER_OTLP_METRICS_HEADERS: &str = "OTEL_EXPORTER_OTLP_METRICS_HEADERS";
3939

40+
/// A builder for creating a new [MetricExporter].
4041
#[derive(Debug, Default, Clone)]
4142
pub struct MetricExporterBuilder<C> {
4243
client: C,
4344
temporality: Temporality,
4445
}
4546

4647
impl MetricExporterBuilder<NoExporterBuilderSet> {
48+
/// Create a new [MetricExporterBuilder] with default settings.
4749
pub fn new() -> Self {
4850
MetricExporterBuilder::default()
4951
}
5052
}
5153

5254
impl<C> MetricExporterBuilder<C> {
55+
/// With the gRPC Tonic transport.
5356
#[cfg(feature = "grpc-tonic")]
5457
pub fn with_tonic(self) -> MetricExporterBuilder<TonicExporterBuilderSet> {
5558
MetricExporterBuilder {
@@ -58,6 +61,7 @@ impl<C> MetricExporterBuilder<C> {
5861
}
5962
}
6063

64+
/// With the HTTP transport.
6165
#[cfg(any(feature = "http-proto", feature = "http-json"))]
6266
pub fn with_http(self) -> MetricExporterBuilder<HttpExporterBuilderSet> {
6367
MetricExporterBuilder {
@@ -66,6 +70,7 @@ impl<C> MetricExporterBuilder<C> {
6670
}
6771
}
6872

73+
/// Set the temporality for the metrics.
6974
pub fn with_temporality(self, temporality: Temporality) -> MetricExporterBuilder<C> {
7075
MetricExporterBuilder {
7176
client: self.client,
@@ -76,6 +81,7 @@ impl<C> MetricExporterBuilder<C> {
7681

7782
#[cfg(feature = "grpc-tonic")]
7883
impl MetricExporterBuilder<TonicExporterBuilderSet> {
84+
/// Build the [MetricExporter] with the gRPC Tonic transport.
7985
pub fn build(self) -> Result<MetricExporter, ExporterBuildError> {
8086
let exporter = self.client.0.build_metrics_exporter(self.temporality)?;
8187
opentelemetry::otel_debug!(name: "MetricExporterBuilt");
@@ -85,6 +91,7 @@ impl MetricExporterBuilder<TonicExporterBuilderSet> {
8591

8692
#[cfg(any(feature = "http-proto", feature = "http-json"))]
8793
impl MetricExporterBuilder<HttpExporterBuilderSet> {
94+
/// Build the [MetricExporter] with the HTTP transport.
8895
pub fn build(self) -> Result<MetricExporter, ExporterBuildError> {
8996
let exporter = self.client.0.build_metrics_exporter(self.temporality)?;
9097
Ok(exporter)

opentelemetry-otlp/src/span.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,27 @@ pub const OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: &str = "OTEL_EXPORTER_OTLP_TRAC
3636
/// Note: this is only supported for HTTP.
3737
pub const OTEL_EXPORTER_OTLP_TRACES_HEADERS: &str = "OTEL_EXPORTER_OTLP_TRACES_HEADERS";
3838

39+
/// OTLP span exporter builder
3940
#[derive(Debug, Default, Clone)]
4041
pub struct SpanExporterBuilder<C> {
4142
client: C,
4243
}
4344

4445
impl SpanExporterBuilder<NoExporterBuilderSet> {
46+
/// Create a new [SpanExporterBuilder] with default settings.
4547
pub fn new() -> Self {
4648
SpanExporterBuilder::default()
4749
}
4850

51+
/// With the gRPC Tonic transport.
4952
#[cfg(feature = "grpc-tonic")]
5053
pub fn with_tonic(self) -> SpanExporterBuilder<TonicExporterBuilderSet> {
5154
SpanExporterBuilder {
5255
client: TonicExporterBuilderSet(TonicExporterBuilder::default()),
5356
}
5457
}
5558

59+
/// With the HTTP transport.
5660
#[cfg(any(feature = "http-proto", feature = "http-json"))]
5761
pub fn with_http(self) -> SpanExporterBuilder<HttpExporterBuilderSet> {
5862
SpanExporterBuilder {
@@ -63,6 +67,7 @@ impl SpanExporterBuilder<NoExporterBuilderSet> {
6367

6468
#[cfg(feature = "grpc-tonic")]
6569
impl SpanExporterBuilder<TonicExporterBuilderSet> {
70+
/// Build the [SpanExporter] with the gRPC Tonic transport.
6671
pub fn build(self) -> Result<SpanExporter, ExporterBuildError> {
6772
let span_exporter = self.client.0.build_span_exporter()?;
6873
opentelemetry::otel_debug!(name: "SpanExporterBuilt");
@@ -72,6 +77,7 @@ impl SpanExporterBuilder<TonicExporterBuilderSet> {
7277

7378
#[cfg(any(feature = "http-proto", feature = "http-json"))]
7479
impl SpanExporterBuilder<HttpExporterBuilderSet> {
80+
/// Build the [SpanExporter] with the HTTP transport.
7581
pub fn build(self) -> Result<SpanExporter, ExporterBuildError> {
7682
let span_exporter = self.client.0.build_span_exporter()?;
7783
Ok(span_exporter)

opentelemetry-proto/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## vNext
44

5+
- **Feature**: Added Rust code generation for profiles protos. [#2979](https://github.com/open-telemetry/opentelemetry-rust/pull/2979)
56
- Update `tonic` dependency version to 0.13
67
- - Update proto definitions to v1.6.0.
78

opentelemetry-proto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ trace = ["opentelemetry/trace", "opentelemetry_sdk/trace"]
4343
metrics = ["opentelemetry/metrics", "opentelemetry_sdk/metrics"]
4444
logs = ["opentelemetry/logs", "opentelemetry_sdk/logs"]
4545
zpages = ["trace"]
46+
profiles = []
4647
testing = ["opentelemetry/testing"]
4748

4849
# add ons

0 commit comments

Comments
 (0)