Skip to content

Commit 82a6d3d

Browse files
authored
Merge branch 'main' into protocol-display-fromstr
2 parents e6711a2 + b33f0cc commit 82a6d3d

File tree

8 files changed

+99
-54
lines changed

8 files changed

+99
-54
lines changed

opentelemetry-appender-tracing/benches/log-attributes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,11 @@ fn create_benchmark(c: &mut Criterion, num_attributes: usize) {
248248
}
249249

250250
fn criterion_benchmark(c: &mut Criterion) {
251+
create_benchmark(c, 2);
251252
// Run benchmarks for 0 to 12 attributes
252-
for num_attributes in 0..=12 {
253-
create_benchmark(c, num_attributes);
254-
}
253+
// for num_attributes in 0..=12 {
254+
// create_benchmark(c, 2);
255+
// }
255256
}
256257

257258
#[cfg(not(target_os = "windows"))]

opentelemetry-appender-tracing/benches/logs.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
| noop_layer_disabled | 12 ns |
1111
| noop_layer_enabled | 25 ns |
1212
| ot_layer_disabled | 19 ns |
13-
| ot_layer_enabled | 196 ns |
13+
| ot_layer_enabled | 167 ns |
14+
15+
Hardware: Apple M4 Pro
16+
Total Number of Cores: 14 (10 performance and 4 efficiency)
17+
| Test | Average time|
18+
|-----------------------------|-------------|
19+
| log_no_subscriber | 285 ps |
20+
| noop_layer_disabled | 8 ns |
21+
| noop_layer_enabled | 14 ns |
22+
| ot_layer_disabled | 12 ns |
23+
| ot_layer_enabled | 186 ns |
1424
*/
1525

1626
use criterion::{criterion_group, criterion_main, Criterion};
@@ -94,7 +104,7 @@ fn benchmark_no_subscriber(c: &mut Criterion) {
94104
c.bench_function("log_no_subscriber", |b| {
95105
b.iter(|| {
96106
error!(
97-
name = "CheckoutFailed",
107+
name : "CheckoutFailed",
98108
book_id = "12345",
99109
book_title = "Rust Programming Adventures",
100110
message = "Unable to process checkout."
@@ -120,7 +130,7 @@ fn benchmark_with_ot_layer(c: &mut Criterion, enabled: bool, bench_name: &str) {
120130
c.bench_function(bench_name, |b| {
121131
b.iter(|| {
122132
error!(
123-
name = "CheckoutFailed",
133+
name : "CheckoutFailed",
124134
book_id = "12345",
125135
book_title = "Rust Programming Adventures",
126136
message = "Unable to process checkout."
@@ -137,10 +147,10 @@ fn benchmark_with_noop_layer(c: &mut Criterion, enabled: bool, bench_name: &str)
137147
c.bench_function(bench_name, |b| {
138148
b.iter(|| {
139149
error!(
140-
name = "CheckoutFailed",
150+
name : "CheckoutFailed",
141151
book_id = "12345",
142152
book_title = "Rust Programming Adventures",
143-
"Unable to process checkout."
153+
message = "Unable to process checkout."
144154
);
145155
});
146156
});

opentelemetry-otlp/tests/integration_test/tests/metrics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ mod metrictests {
6969
);
7070

7171
// In tokio::current_thread flavor, shutdown must be done in a separate thread
72-
let shutdown_resut = Handle::current()
72+
let shutdown_result = Handle::current()
7373
.spawn_blocking(move || meter_provider.shutdown())
7474
.await
7575
.unwrap();
76-
assert!(shutdown_resut.is_ok());
76+
assert!(shutdown_result.is_ok());
7777
// We still need to sleep, to give otel-collector a chance to flush to disk
7878
std::thread::sleep(SLEEP_DURATION);
7979

@@ -102,8 +102,8 @@ mod metrictests {
102102
],
103103
);
104104

105-
let shutdown_resut = meter_provider.shutdown();
106-
assert!(shutdown_resut.is_ok());
105+
let shutdown_result = meter_provider.shutdown();
106+
assert!(shutdown_result.is_ok());
107107
// We still need to sleep, to give otel-collector a chance to flush to disk
108108
std::thread::sleep(SLEEP_DURATION);
109109

@@ -129,8 +129,8 @@ mod metrictests {
129129
],
130130
);
131131

132-
let shutdown_resut = meter_provider.shutdown();
133-
assert!(shutdown_resut.is_ok());
132+
let shutdown_result = meter_provider.shutdown();
133+
assert!(shutdown_result.is_ok());
134134
// We still need to sleep, to give otel-collector a chance to flush to disk
135135
std::thread::sleep(SLEEP_DURATION);
136136

opentelemetry-sdk/src/propagation/baggage.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn baggage_fields() -> &'static [String; 1] {
3030
/// # Examples
3131
///
3232
/// ```
33-
/// use opentelemetry::{baggage::BaggageExt, KeyValue, propagation::TextMapPropagator};
33+
/// use opentelemetry::{baggage::{Baggage, BaggageExt}, propagation::TextMapPropagator};
3434
/// use opentelemetry_sdk::propagation::BaggagePropagator;
3535
/// use std::collections::HashMap;
3636
///
@@ -48,14 +48,17 @@ fn baggage_fields() -> &'static [String; 1] {
4848
/// }
4949
///
5050
/// // Add new baggage
51-
/// let cx_with_additions = cx.with_baggage(vec![KeyValue::new("server_id", 42)]);
51+
/// let mut baggage = Baggage::new();
52+
/// let _ = baggage.insert("server_id", "42");
53+
///
54+
/// let cx_with_additions = cx.with_baggage(baggage);
5255
///
5356
/// // Inject baggage into http request
5457
/// propagator.inject_context(&cx_with_additions, &mut headers);
5558
///
5659
/// let header_value = headers.get("baggage").expect("header is injected");
57-
/// assert!(header_value.contains("user_id=1"), "still contains previous name-value");
58-
/// assert!(header_value.contains("server_id=42"), "contains new name-value pair");
60+
/// assert!(!header_value.contains("user_id=1"), "still contains previous name-value");
61+
/// assert!(header_value.contains("server_id=42"), "does not contain new name-value pair");
5962
/// ```
6063
///
6164
/// [W3C Baggage]: https://w3c.github.io/baggage
@@ -98,7 +101,7 @@ impl TextMapPropagator for BaggagePropagator {
98101
/// Extracts a `Context` with baggage values from a `Extractor`.
99102
fn extract_with_context(&self, cx: &Context, extractor: &dyn Extractor) -> Context {
100103
if let Some(header_value) = extractor.get(BAGGAGE_HEADER) {
101-
let baggage = header_value.split(',').flat_map(|context_value| {
104+
let baggage = header_value.split(',').filter_map(|context_value| {
102105
if let Some((name_and_value, props)) = context_value
103106
.split(';')
104107
.collect::<Vec<&str>>()

opentelemetry/CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
- *Breaking* Moved `TraceResult` type alias from `opentelemetry::trace::TraceResult` to `opentelemetry_sdk::trace::TraceResult`
88
- {PLACEHOLDER} - Remove the above completely. // TODO fill this when changes are actually in.
99
- Bug Fix: `InstrumentationScope` implementation for `PartialEq` and `Hash` fixed to include Attributes also.
10-
- *Breaking* Changed value type of `Baggage` from `Value` to `StringValue`
11-
- Updated `Baggage` constants to reflect latest standard (`MAX_KEY_VALUE_PAIRS` - 180 -> 64, `MAX_BYTES_FOR_ONE_PAIR` - removed) and increased insert performance see #[2284](https://github.com/open-telemetry/opentelemetry-rust/pull/2284).
12-
- *Breaking* Align `Baggage.remove()` signature with `.get()` to take the key as a reference
10+
- **Breaking changes for baggage users**: [#2717](https://github.com/open-telemetry/opentelemetry-rust/issues/2717)
11+
- Changed value type of `Baggage` from `Value` to `StringValue`
12+
- Updated `Baggage` constants to reflect latest standard (`MAX_KEY_VALUE_PAIRS` - 180 -> 64, `MAX_BYTES_FOR_ONE_PAIR` - removed) and increased insert performance see #[2284](https://github.com/open-telemetry/opentelemetry-rust/pull/2284).
13+
- Align `Baggage.remove()` signature with `.get()` to take the key as a reference
14+
- `Baggage` can't be retrieved from the `Context` directly anymore and needs to be accessed via `context.baggage()`
15+
- `with_baggage()` and `current_with_baggage()` override any existing `Baggage` in the `Context`
1316
- Changed `Context` to use a stack to properly handle out of order dropping of `ContextGuard`. This imposes a limit of `65535` nested contexts on a single thread. See #[2378](https://github.com/open-telemetry/opentelemetry-rust/pull/2284) and #[1887](https://github.com/open-telemetry/opentelemetry-rust/issues/1887).
14-
1517
- Added additional `name: Option<&str>` parameter to the `event_enabled` method
1618
on the `Logger` trait. This allows implementations (SDK, processor, exporters)
1719
to leverage this additional information to determine if an event is enabled.

opentelemetry/src/baggage.rs

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ impl FromIterator<KeyValueMetadata> for Baggage {
273273
}
274274
}
275275

276+
impl<I> From<I> for Baggage
277+
where
278+
I: IntoIterator,
279+
I::Item: Into<KeyValueMetadata>,
280+
{
281+
fn from(value: I) -> Self {
282+
value.into_iter().map(Into::into).collect()
283+
}
284+
}
285+
276286
fn encode(s: &str) -> String {
277287
let mut encoded_string = String::with_capacity(s.len());
278288

@@ -312,39 +322,46 @@ pub trait BaggageExt {
312322
/// # Examples
313323
///
314324
/// ```
315-
/// use opentelemetry::{baggage::BaggageExt, Context, KeyValue, StringValue};
325+
/// use opentelemetry::{baggage::{Baggage, BaggageExt}, Context, KeyValue, StringValue};
326+
///
327+
/// // Explicit `Baggage` creation
328+
/// let mut baggage = Baggage::new();
329+
/// let _ = baggage.insert("my-name", "my-value");
330+
///
331+
/// let cx = Context::map_current(|cx| {
332+
/// cx.with_baggage(baggage)
333+
/// });
316334
///
335+
/// // Passing an iterator
317336
/// let cx = Context::map_current(|cx| {
318-
/// cx.with_baggage(vec![KeyValue::new("my-name", "my-value")])
337+
/// cx.with_baggage([KeyValue::new("my-name", "my-value")])
319338
/// });
320339
///
321340
/// assert_eq!(
322341
/// cx.baggage().get("my-name"),
323342
/// Some(&StringValue::from("my-value")),
324343
/// )
325344
/// ```
326-
fn with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>(
327-
&self,
328-
baggage: T,
329-
) -> Self;
345+
fn with_baggage<T: Into<Baggage>>(&self, baggage: T) -> Self;
330346

331347
/// Returns a clone of the current context with the included name/value pairs.
332348
///
333349
/// # Examples
334350
///
335351
/// ```
336-
/// use opentelemetry::{baggage::BaggageExt, Context, KeyValue, StringValue};
352+
/// use opentelemetry::{baggage::{Baggage, BaggageExt}, Context, StringValue};
337353
///
338-
/// let cx = Context::current_with_baggage(vec![KeyValue::new("my-name", "my-value")]);
354+
/// let mut baggage = Baggage::new();
355+
/// let _ = baggage.insert("my-name", "my-value");
356+
///
357+
/// let cx = Context::current_with_baggage(baggage);
339358
///
340359
/// assert_eq!(
341360
/// cx.baggage().get("my-name"),
342361
/// Some(&StringValue::from("my-value")),
343362
/// )
344363
/// ```
345-
fn current_with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>(
346-
baggage: T,
347-
) -> Self;
364+
fn current_with_baggage<T: Into<Baggage>>(baggage: T) -> Self;
348365

349366
/// Returns a clone of the given context with no baggage.
350367
///
@@ -364,33 +381,26 @@ pub trait BaggageExt {
364381
fn baggage(&self) -> &Baggage;
365382
}
366383

367-
impl BaggageExt for Context {
368-
fn with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>(
369-
&self,
370-
baggage: T,
371-
) -> Self {
372-
let old = self.baggage();
373-
let mut merged = Baggage {
374-
inner: old.inner.clone(),
375-
kv_content_len: old.kv_content_len,
376-
};
377-
for kvm in baggage.into_iter().map(|kv| kv.into()) {
378-
merged.insert_with_metadata(kvm.key, kvm.value, kvm.metadata);
379-
}
384+
/// Solely used to store `Baggage` in the `Context` without allowing direct access
385+
#[derive(Debug)]
386+
struct BaggageContextValue(Baggage);
380387

381-
self.with_value(merged)
388+
impl BaggageExt for Context {
389+
fn with_baggage<T: Into<Baggage>>(&self, baggage: T) -> Self {
390+
self.with_value(BaggageContextValue(baggage.into()))
382391
}
383392

384-
fn current_with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>(kvs: T) -> Self {
385-
Context::map_current(|cx| cx.with_baggage(kvs))
393+
fn current_with_baggage<T: Into<Baggage>>(baggage: T) -> Self {
394+
Context::map_current(|cx| cx.with_baggage(baggage))
386395
}
387396

388397
fn with_cleared_baggage(&self) -> Self {
389398
self.with_value(Baggage::new())
390399
}
391400

392401
fn baggage(&self) -> &Baggage {
393-
self.get::<Baggage>().unwrap_or(get_default_baggage())
402+
self.get::<BaggageContextValue>()
403+
.map_or(get_default_baggage(), |b| &b.0)
394404
}
395405
}
396406

stress/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lazy_static = { workspace = true }
4545
num_cpus = { workspace = true }
4646
opentelemetry = { path = "../opentelemetry", features = ["metrics", "logs", "trace", "spec_unstable_logs_enabled"] }
4747
opentelemetry_sdk = { path = "../opentelemetry-sdk", features = ["metrics", "logs", "trace", "spec_unstable_logs_enabled"] }
48-
opentelemetry-appender-tracing = { workspace = true }
48+
opentelemetry-appender-tracing = { workspace = true, features = ["spec_unstable_logs_enabled"] }
4949
rand = { workspace = true, features = ["small_rng", "os_rng"] }
5050
tracing = { workspace = true, features = ["std"]}
5151
tracing-subscriber = { workspace = true, features = ["registry", "std"] }

stress/src/logs.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
~31 M/sec
77
88
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
9-
~40 M /sec
9+
~44 M /sec
10+
11+
Hardware: Apple M4 Pro
12+
Total Number of Cores: 14 (10 performance and 4 efficiency)
13+
~50 M/sec
14+
~1.1 B/sec (when disabled)
1015
*/
1116

1217
use opentelemetry::InstrumentationScope;
@@ -32,6 +37,7 @@ impl LogExporter for MockLogExporter {
3237
#[derive(Debug)]
3338
pub struct MockLogProcessor {
3439
exporter: MockLogExporter,
40+
enabled: bool,
3541
}
3642

3743
impl LogProcessor for MockLogProcessor {
@@ -51,13 +57,26 @@ impl LogProcessor for MockLogProcessor {
5157
fn shutdown(&self) -> OTelSdkResult {
5258
Ok(())
5359
}
60+
61+
fn event_enabled(
62+
&self,
63+
_level: opentelemetry::logs::Severity,
64+
_target: &str,
65+
_name: Option<&str>,
66+
) -> bool {
67+
self.enabled
68+
}
5469
}
5570

5671
fn main() {
72+
// change this to false to test the throughput when enabled is false.
73+
let enabled = true;
74+
5775
// LoggerProvider with a no-op processor.
5876
let provider: SdkLoggerProvider = SdkLoggerProvider::builder()
5977
.with_log_processor(MockLogProcessor {
6078
exporter: MockLogExporter {},
79+
enabled,
6180
})
6281
.build();
6382

@@ -69,7 +88,7 @@ fn main() {
6988

7089
fn test_log() {
7190
error!(
72-
name = "CheckoutFailed",
91+
name : "CheckoutFailed",
7392
book_id = "12345",
7493
book_title = "Rust Programming Adventures",
7594
message = "Unable to process checkout."

0 commit comments

Comments
 (0)