Skip to content

Commit 247d84e

Browse files
authored
Merge branch 'main' into self-diagnostics
2 parents d042cad + 9356106 commit 247d84e

File tree

14 files changed

+2430
-1270
lines changed

14 files changed

+2430
-1270
lines changed

.github/workflows/semver.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
with:
2020
components: rustfmt
2121
- name: cargo-semver-checks
22-
uses: obi1kenobi/cargo-semver-checks-action@v2.3
22+
uses: obi1kenobi/cargo-semver-checks-action@v2.4

opentelemetry-sdk/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
- `SpanData` doesn't have the resource attributes. The `SpanExporter::export()` method needs to merge it
4242
with the earlier preserved resource before export.
4343

44-
- **Breaking** [1836](https://github.com/open-telemetry/opentelemetry-rust/pull/1836) `SpanProcessor::shutdown` now takes an immutable reference to self. Any reference can call shutdown on the processor. After the first call to `shutdown` the processor will not process any new spans.
44+
- **Breaking** [1836](https://github.com/open-telemetry/opentelemetry-rust/pull/1836) `SpanProcessor::shutdown` now takes an immutable reference to self. Any reference can call shutdown on the processor. After the first call to `shutdown` the processor will not process any new spans.
45+
46+
- **Breaking** [1850] (https://github.com/open-telemetry/opentelemetry-rust/pull/1850) `LoggerProvider::log_processors()` and `LoggerProvider::resource()` are not public methods anymore. They are only used within the `opentelemetry-sdk` crate.
4547

4648
## v0.23.0
4749

opentelemetry-sdk/benches/attribute_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use opentelemetry::KeyValue;
33
use opentelemetry_sdk::metrics::AttributeSet;
44

55
// Run this benchmark with:
6-
// cargo bench --bench attribute_set --features=metrics
6+
// cargo bench --bench attribute_set
77

88
fn criterion_benchmark(c: &mut Criterion) {
99
attribute_set(c);

opentelemetry-sdk/benches/log.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! run with `$ cargo bench --bench log --features=logs -- --exact <test_name>` to run specific test for logs
2-
//! So to run test named "full-log-with-attributes/with-context" you would run `$ cargo bench --bench log --features=logs -- --exact full-log-with-attributes/with-context`
3-
//! To run all tests for logs you would run `$ cargo bench --bench log --features=logs`
1+
//! run with `$ cargo bench --bench log -- --exact <test_name>` to run specific test for logs
2+
//! So to run test named "full-log-with-attributes/with-context" you would run `$ cargo bench --bench log -- --exact full-log-with-attributes/with-context`
3+
//! To run all tests for logs you would run `$ cargo bench --bench log`
44
//!
55
66
use std::collections::HashMap;

opentelemetry-sdk/benches/metric_counter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ thread_local! {
3030
}
3131

3232
// Run this benchmark with:
33-
// cargo bench --bench metric_counter --features=metrics
33+
// cargo bench --bench metric_counter
3434
fn create_counter() -> Counter<u64> {
3535
let meter_provider: SdkMeterProvider = SdkMeterProvider::builder()
3636
.with_reader(ManualReader::builder().build())

opentelemetry-sdk/src/logs/log_emitter.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@ impl LoggerProvider {
9090
Builder::default()
9191
}
9292

93-
/// Resource associated with this provider.
94-
pub fn resource(&self) -> &Resource {
95-
&self.inner.resource
93+
pub(crate) fn log_processors(&self) -> &[Box<dyn LogProcessor>] {
94+
&self.inner.processors
9695
}
9796

98-
/// Log processors associated with this provider.
99-
pub fn log_processors(&self) -> &[Box<dyn LogProcessor>] {
100-
&self.inner.processors
97+
pub(crate) fn resource(&self) -> &Resource {
98+
&self.inner.resource
10199
}
102100

103101
/// Force flush all remaining logs in log processors and return results.
@@ -196,17 +194,20 @@ impl Builder {
196194
/// Create a new provider from this configuration.
197195
pub fn build(self) -> LoggerProvider {
198196
let resource = self.resource.unwrap_or_default();
199-
// invoke set_resource on all the processors
200-
for processor in &self.processors {
201-
processor.set_resource(&resource);
202-
}
203-
LoggerProvider {
197+
198+
let logger_provider = LoggerProvider {
204199
inner: Arc::new(LoggerProviderInner {
205200
processors: self.processors,
206201
resource,
207202
}),
208203
is_shutdown: Arc::new(AtomicBool::new(false)),
204+
};
205+
206+
// invoke set_resource on all the processors
207+
for processor in logger_provider.log_processors() {
208+
processor.set_resource(logger_provider.resource());
209209
}
210+
logger_provider
210211
}
211212
}
212213

@@ -511,7 +512,7 @@ mod tests {
511512

512513
#[test]
513514
fn global_shutdown_test() {
514-
// cargo test shutdown_test --features=logs
515+
// cargo test global_shutdown_test --features=testing
515516

516517
// Arrange
517518
let shutdown_called = Arc::new(Mutex::new(false));

opentelemetry-sdk/src/logs/log_processor.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ mod tests {
536536

537537
#[derive(Debug, Clone)]
538538
struct MockLogExporter {
539-
resource: Arc<Option<Resource>>,
539+
resource: Arc<Mutex<Option<Resource>>>,
540540
}
541541

542542
#[async_trait]
@@ -548,15 +548,19 @@ mod tests {
548548
fn shutdown(&mut self) {}
549549

550550
fn set_resource(&mut self, resource: &Resource) {
551-
let res = Arc::make_mut(&mut self.resource);
552-
*res = Some(resource.clone());
551+
self.resource
552+
.lock()
553+
.map(|mut res_opt| {
554+
res_opt.replace(resource.clone());
555+
})
556+
.expect("mock log exporter shouldn't error when setting resource");
553557
}
554558
}
555559

556560
// Implementation specific to the MockLogExporter, not part of the LogExporter trait
557561
impl MockLogExporter {
558562
fn get_resource(&self) -> Option<Resource> {
559-
(*self.resource).clone()
563+
(*self.resource).lock().unwrap().clone()
560564
}
561565
}
562566

@@ -713,7 +717,7 @@ mod tests {
713717
#[test]
714718
fn test_set_resource_simple_processor() {
715719
let exporter = MockLogExporter {
716-
resource: Arc::new(Some(Resource::default())),
720+
resource: Arc::new(Mutex::new(None)),
717721
};
718722
let processor = SimpleLogProcessor::new(Box::new(exporter.clone()));
719723
let _ = LoggerProvider::builder()
@@ -723,15 +727,16 @@ mod tests {
723727
KeyValue::new("k2", "v3"),
724728
KeyValue::new("k3", "v3"),
725729
KeyValue::new("k4", "v4"),
730+
KeyValue::new("k5", "v5"),
726731
]))
727732
.build();
728-
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 4);
733+
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
729734
}
730735

731736
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
732737
async fn test_set_resource_batch_processor() {
733738
let exporter = MockLogExporter {
734-
resource: Arc::new(Some(Resource::default())),
739+
resource: Arc::new(Mutex::new(None)),
735740
};
736741
let processor = BatchLogProcessor::new(
737742
Box::new(exporter.clone()),
@@ -745,9 +750,11 @@ mod tests {
745750
KeyValue::new("k2", "v3"),
746751
KeyValue::new("k3", "v3"),
747752
KeyValue::new("k4", "v4"),
753+
KeyValue::new("k5", "v5"),
748754
]))
749755
.build();
750-
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 4);
756+
tokio::time::sleep(Duration::from_secs(2)).await; // set resource in batch span processor is not blocking. Should we make it blocking?
757+
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
751758
let _ = provider.shutdown();
752759
}
753760

opentelemetry-sdk/src/metrics/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod tests {
153153
use std::thread;
154154

155155
// Run all tests in this mod
156-
// cargo test metrics::tests --features=metrics,testing
156+
// cargo test metrics::tests --features=testing
157157
// Note for all tests from this point onwards in this mod:
158158
// "multi_thread" tokio flavor must be used else flush won't
159159
// be able to make progress!
@@ -190,49 +190,49 @@ mod tests {
190190
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
191191
async fn counter_aggregation_cumulative() {
192192
// Run this test with stdout enabled to see output.
193-
// cargo test counter_aggregation_cumulative --features=metrics,testing -- --nocapture
193+
// cargo test counter_aggregation_cumulative --features=testing -- --nocapture
194194
counter_aggregation_helper(Temporality::Cumulative);
195195
}
196196

197197
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
198198
async fn counter_aggregation_delta() {
199199
// Run this test with stdout enabled to see output.
200-
// cargo test counter_aggregation_delta --features=metrics,testing -- --nocapture
200+
// cargo test counter_aggregation_delta --features=testing -- --nocapture
201201
counter_aggregation_helper(Temporality::Delta);
202202
}
203203

204204
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
205205
async fn histogram_aggregation_cumulative() {
206206
// Run this test with stdout enabled to see output.
207-
// cargo test histogram_aggregation_cumulative --features=metrics,testing -- --nocapture
207+
// cargo test histogram_aggregation_cumulative --features=testing -- --nocapture
208208
histogram_aggregation_helper(Temporality::Cumulative);
209209
}
210210

211211
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
212212
async fn histogram_aggregation_delta() {
213213
// Run this test with stdout enabled to see output.
214-
// cargo test histogram_aggregation_delta --features=metrics,testing -- --nocapture
214+
// cargo test histogram_aggregation_delta --features=testing -- --nocapture
215215
histogram_aggregation_helper(Temporality::Delta);
216216
}
217217

218218
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
219219
async fn updown_counter_aggregation_cumulative() {
220220
// Run this test with stdout enabled to see output.
221-
// cargo test updown_counter_aggregation_cumulative --features=metrics,testing -- --nocapture
221+
// cargo test updown_counter_aggregation_cumulative --features=testing -- --nocapture
222222
updown_counter_aggregation_helper(Temporality::Cumulative);
223223
}
224224

225225
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
226226
async fn updown_counter_aggregation_delta() {
227227
// Run this test with stdout enabled to see output.
228-
// cargo test updown_counter_aggregation_delta --features=metrics,testing -- --nocapture
228+
// cargo test updown_counter_aggregation_delta --features=testing -- --nocapture
229229
updown_counter_aggregation_helper(Temporality::Delta);
230230
}
231231

232232
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
233233
async fn gauge_aggregation() {
234234
// Run this test with stdout enabled to see output.
235-
// cargo test gauge_aggregation --features=metrics,testing -- --nocapture
235+
// cargo test gauge_aggregation --features=testing -- --nocapture
236236

237237
// Gauge should use last value aggregation regardless of the aggregation temporality used.
238238
gauge_aggregation_helper(Temporality::Delta);
@@ -553,7 +553,7 @@ mod tests {
553553
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
554554
async fn histogram_aggregation_with_invalid_aggregation_should_proceed_as_if_view_not_exist() {
555555
// Run this test with stdout enabled to see output.
556-
// cargo test histogram_aggregation_with_invalid_aggregation_should_proceed_as_if_view_not_exist --features=metrics,testing -- --nocapture
556+
// cargo test histogram_aggregation_with_invalid_aggregation_should_proceed_as_if_view_not_exist --features=testing -- --nocapture
557557

558558
// Arrange
559559
let exporter = InMemoryMetricsExporter::default();
@@ -602,7 +602,7 @@ mod tests {
602602

603603
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
604604
async fn spatial_aggregation_when_view_drops_attributes_observable_counter() {
605-
// cargo test spatial_aggregation_when_view_drops_attributes_observable_counter --features=metrics,testing
605+
// cargo test spatial_aggregation_when_view_drops_attributes_observable_counter --features=testing
606606

607607
// Arrange
608608
let exporter = InMemoryMetricsExporter::default();
@@ -677,7 +677,7 @@ mod tests {
677677

678678
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
679679
async fn spatial_aggregation_when_view_drops_attributes_counter() {
680-
// cargo test spatial_aggregation_when_view_drops_attributes_counter --features=metrics,testing
680+
// cargo test spatial_aggregation_when_view_drops_attributes_counter --features=testing
681681

682682
// Arrange
683683
let exporter = InMemoryMetricsExporter::default();
@@ -754,7 +754,7 @@ mod tests {
754754
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
755755
async fn counter_aggregation_attribute_order() {
756756
// Run this test with stdout enabled to see output.
757-
// cargo test counter_aggregation_attribute_order --features=metrics,testing -- --nocapture
757+
// cargo test counter_aggregation_attribute_order --features=testing -- --nocapture
758758

759759
// Arrange
760760
let mut test_context = TestContext::new(Temporality::Delta);
@@ -987,7 +987,7 @@ mod tests {
987987
#[ignore = "Known bug: https://github.com/open-telemetry/opentelemetry-rust/issues/1598"]
988988
async fn delta_memory_efficiency_test() {
989989
// Run this test with stdout enabled to see output.
990-
// cargo test delta_memory_efficiency_test --features=metrics,testing -- --nocapture
990+
// cargo test delta_memory_efficiency_test --features=testing -- --nocapture
991991

992992
// Arrange
993993
let mut test_context = TestContext::new(Temporality::Delta);
@@ -1036,7 +1036,7 @@ mod tests {
10361036
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
10371037
async fn counter_multithreaded() {
10381038
// Run this test with stdout enabled to see output.
1039-
// cargo test counter_multithreaded --features=metrics,testing -- --nocapture
1039+
// cargo test counter_multithreaded --features=testing -- --nocapture
10401040

10411041
counter_multithreaded_aggregation_helper(Temporality::Delta);
10421042
counter_multithreaded_aggregation_helper(Temporality::Cumulative);

opentelemetry-sdk/src/trace/span_processor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ where
683683

684684
#[cfg(all(test, feature = "testing", feature = "trace"))]
685685
mod tests {
686-
// cargo test trace::span_processor::tests:: --features=trace,testing
686+
// cargo test trace::span_processor::tests:: --features=testing
687687
use super::{
688688
BatchSpanProcessor, SimpleSpanProcessor, SpanProcessor, OTEL_BSP_EXPORT_TIMEOUT,
689689
OTEL_BSP_MAX_EXPORT_BATCH_SIZE, OTEL_BSP_MAX_QUEUE_SIZE, OTEL_BSP_MAX_QUEUE_SIZE_DEFAULT,

opentelemetry-semantic-conventions/scripts/generate-consts-from-spec.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
55
CRATE_DIR="${SCRIPT_DIR}/../"
66

77
# freeze the spec version and generator version to make generation reproducible
8-
SPEC_VERSION=1.25.0
8+
SPEC_VERSION=1.26.0
99
SEMCOVGEN_VERSION=0.24.0
1010

1111
cd "$CRATE_DIR"
@@ -53,4 +53,14 @@ fi
5353
# handle doc generation failures
5454
"${SED[@]}" 's/\[2\]\.$//' src/resource.rs src/trace.rs # remove trailing [2] from few of the doc comments
5555

56+
# Remove the messaging.client_id definition along with its comments from the generated files
57+
# - semconv "messaging.client_id" is deprecated
58+
# - semconv "messaging.client.id" is to be used instead
59+
# - Now because we use:
60+
# pub const {{attribute.fqn | to_const_name}}: &str = "{{attribute.fqn}}";
61+
# to generate the consts, where to_const_name replaces '.' with '_', we need to remove the old definition
62+
# to avoid conflicts with the new one. Refer - https://github.com/open-telemetry/semantic-conventions/issues/1031
63+
"${SED[@]}" '/\/\/\/ Deprecated, use `messaging.client.id` instead\./{N;N;N;N;d;}' src/trace.rs src/resource.rs
64+
"${SED[@]}" '/pub const MESSAGING_CLIENT_ID: &str = "messaging.client_id";/{N;d;}' src/trace.rs src/resource.rs
65+
5666
cargo fmt

opentelemetry-semantic-conventions/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ pub mod trace;
2020

2121
/// The schema URL that matches the version of the semantic conventions that
2222
/// this crate defines.
23-
pub const SCHEMA_URL: &str = "https://opentelemetry.io/schemas/1.25.0";
23+
pub const SCHEMA_URL: &str = "https://opentelemetry.io/schemas/1.26.0";

0 commit comments

Comments
 (0)