Skip to content

Commit c47ba1c

Browse files
authored
Merge branch 'main' into cijothomas/metric-doc1
2 parents 67770ea + 8c29ca7 commit c47ba1c

File tree

58 files changed

+2504
-843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2504
-843
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[resolver]
2+
# https://doc.rust-lang.org/cargo/reference/config.html#resolverincompatible-rust-versions
3+
incompatible-rust-versions = "fallback"

.github/workflows/ci.yml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
external-types:
8686
strategy:
8787
matrix:
88-
example: [opentelemetry, opentelemetry-sdk, opentelemetry-otlp, opentelemetry-zipkin]
88+
member: [opentelemetry, opentelemetry-sdk, opentelemetry-otlp, opentelemetry-zipkin]
8989
runs-on: ubuntu-latest # TODO: Check if this could be covered for Windows. The step used currently fails on Windows.
9090
steps:
9191
- name: Harden the runner (Audit all outbound calls)
@@ -96,20 +96,20 @@ jobs:
9696
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
9797
- uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
9898
with:
99-
toolchain: nightly-2024-06-30
99+
# Rust version should be kept in sync with the one the release was tested with
100+
# https://github.com/awslabs/cargo-check-external-types/releases
101+
toolchain: nightly-2025-05-04
100102
components: rustfmt
101-
- name: Patch dependencies versions
102-
run: bash ./scripts/patch_dependencies.sh
103+
- uses: taiki-e/install-action@33734a118689b0b418824fb78ea2bf18e970b43b # v2.50.4
104+
with:
105+
103106
- name: external-type-check
104-
run: |
105-
cargo install [email protected]
106-
cd ${{ matrix.example }}
107-
cargo check-external-types --all-features --config allowed-external-types.toml
107+
working-directory: ${{ matrix.member }}
108+
run: cargo check-external-types --all-features --config allowed-external-types.toml
108109
msrv:
109110
strategy:
110111
matrix:
111112
os: [windows-latest, ubuntu-latest]
112-
rust: [1.75.0]
113113
runs-on: ${{ matrix.os }}
114114
continue-on-error: true
115115
steps:
@@ -121,14 +121,17 @@ jobs:
121121
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
122122
with:
123123
submodules: true
124-
- name: Set up Rust ${{ matrix.rust }}
125-
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
124+
- uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b
125+
with:
126+
toolchain: stable
127+
- uses: taiki-e/install-action@33734a118689b0b418824fb78ea2bf18e970b43b # v2.50.4
128+
with:
129+
tool: cargo-msrv
130+
- uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
126131
with:
127-
toolchain: ${{ matrix.rust }}
128-
- name: Patch dependencies versions
129-
run: bash ./scripts/patch_dependencies.sh
132+
repo-token: ${{ secrets.GITHUB_TOKEN }}
130133
- name: Check MSRV for all crates
131-
run: bash ./scripts/msrv.sh ${{ matrix.rust }}
134+
run: bash ./scripts/msrv.sh
132135
cargo-deny:
133136
runs-on: ubuntu-latest # This uses the step `EmbarkStudios/cargo-deny-action@v1` which is only supported on Linux
134137
continue-on-error: true # Prevent sudden announcement of a new advisory from failing ci
@@ -220,11 +223,11 @@ jobs:
220223
build-examples:
221224
runs-on: ubuntu-latest
222225
steps:
223-
- uses: actions/checkout@v4
224-
- uses: dtolnay/rust-toolchain@stable
226+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
227+
- uses: dtolnay/rust-toolchain@4305c38b25d97ef35a8ad1f985ccf2d2242004f2 # stable
225228
with:
226229
components: rustfmt
227-
- uses: arduino/setup-protoc@v3
230+
- uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
228231
with:
229232
repo-token: ${{ secrets.GITHUB_TOKEN }}
230233
- name: Build examples

examples/logs-basic/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "logs-basic"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
6+
rust-version = "1.75.0"
67
publish = false
78
autobenches = false
89

examples/metrics-advanced/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "metrics-advanced"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
6+
rust-version = "1.75.0"
67
publish = false
78
autobenches = false
89

@@ -13,6 +14,6 @@ bench = false
1314

1415
[dependencies]
1516
opentelemetry = { path = "../../opentelemetry", features = ["metrics"] }
16-
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["spec_unstable_metrics_views"] }
17+
opentelemetry_sdk = { path = "../../opentelemetry-sdk" }
1718
opentelemetry-stdout = { workspace = true, features = ["metrics"] }
1819
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

examples/metrics-basic/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "metrics-basic"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
6+
rust-version = "1.75.0"
67
publish = false
78
autobenches = false
89

examples/tracing-grpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "tracing-grpc"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
6+
rust-version = "1.75.0"
67
publish = false
78
autobenches = false
89

examples/tracing-http-propagator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "tracing-http-propagator"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
6+
rust-version = "1.75.0"
67
publish = false
78
autobenches = false
89

examples/tracing-http-propagator/src/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use opentelemetry_sdk::{
1919
};
2020
use opentelemetry_semantic_conventions::trace;
2121
use opentelemetry_stdout::{LogExporter, SpanExporter};
22+
use std::time::Duration;
2223
use std::{convert::Infallible, net::SocketAddr, sync::OnceLock};
2324
use tokio::net::TcpListener;
2425
use tracing::info;
@@ -131,7 +132,7 @@ impl SpanProcessor for EnrichWithBaggageSpanProcessor {
131132
Ok(())
132133
}
133134

134-
fn shutdown(&self) -> OTelSdkResult {
135+
fn shutdown_with_timeout(&self, _timeout: Duration) -> OTelSdkResult {
135136
Ok(())
136137
}
137138

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

0 commit comments

Comments
 (0)