Skip to content

Commit 0eea773

Browse files
committed
make baggage::KeyValueMetadata private
1 parent b33f0cc commit 0eea773

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

opentelemetry-sdk/src/propagation/baggage.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use opentelemetry::{
2-
baggage::{BaggageExt, KeyValueMetadata},
2+
baggage::{BaggageExt, BaggageMetadata},
33
otel_warn,
44
propagation::{text_map_propagator::FieldIter, Extractor, Injector, TextMapPropagator},
5-
Context,
5+
Context, Key, StringValue,
66
};
77
use percent_encoding::{percent_decode_str, utf8_percent_encode, AsciiSet, CONTROLS};
88
use std::iter;
@@ -122,10 +122,10 @@ impl TextMapPropagator for BaggagePropagator {
122122
.collect::<Vec<String>>()
123123
.join(";"); // join with ; because we deleted all ; when calling split above
124124

125-
Some(KeyValueMetadata::new(
126-
name.trim().to_owned(),
127-
value.trim().to_string(),
128-
decoded_props.as_str(),
125+
Some((
126+
Key::from(name.trim().to_owned()),
127+
StringValue::from(value.trim().to_owned()),
128+
BaggageMetadata::from(decoded_props.as_str()),
129129
))
130130
} else {
131131
otel_warn!(
@@ -238,13 +238,14 @@ mod tests {
238238
}
239239

240240
#[rustfmt::skip]
241-
fn valid_inject_data_metadata() -> Vec<(Vec<KeyValueMetadata>, Vec<&'static str>)> {
241+
#[allow(clippy::type_complexity)]
242+
fn valid_inject_data_metadata() -> Vec<(Vec<(KeyValue, BaggageMetadata)>, Vec<&'static str>)> {
242243
vec![
243244
(
244245
vec![
245-
KeyValueMetadata::new("key1", "val1", "prop1"),
246-
KeyValue::new("key2", "val2").into(),
247-
KeyValueMetadata::new("key3", "val3", "anykey=anyvalue"),
246+
(KeyValue::new("key1", "val1"), BaggageMetadata::from("prop1")),
247+
(KeyValue::new("key2", "val2"), BaggageMetadata::default()),
248+
(KeyValue::new("key3", "val3"), BaggageMetadata::from("anykey=anyvalue")),
248249
],
249250
vec![
250251
"key1=val1;prop1",

opentelemetry/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Align `Baggage.remove()` signature with `.get()` to take the key as a reference
1414
- `Baggage` can't be retrieved from the `Context` directly anymore and needs to be accessed via `context.baggage()`
1515
- `with_baggage()` and `current_with_baggage()` override any existing `Baggage` in the `Context`
16+
- `opentelemetry::baggage::KeyValueMetadata` is now private use instead `opentelemetry::KeyValue` with `opentelemetry::baggage::BaggageMetadata`
1617
- 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).
1718
- Added additional `name: Option<&str>` parameter to the `event_enabled` method
1819
on the `Logger` trait. This allows implementations (SDK, processor, exporters)

opentelemetry/src/baggage.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl fmt::Display for BaggageMetadata {
439439

440440
/// [`Baggage`] name/value pairs with their associated metadata.
441441
#[derive(Clone, Debug, PartialEq)]
442-
pub struct KeyValueMetadata {
442+
struct KeyValueMetadata {
443443
/// Dimension or event key
444444
pub key: Key,
445445
/// Dimension or event value
@@ -448,28 +448,32 @@ pub struct KeyValueMetadata {
448448
pub metadata: BaggageMetadata,
449449
}
450450

451-
impl KeyValueMetadata {
452-
/// Create a new `KeyValue` pair with metadata
453-
pub fn new<K, V, S>(key: K, value: V, metadata: S) -> Self
454-
where
455-
K: Into<Key>,
456-
V: Into<StringValue>,
457-
S: Into<BaggageMetadata>,
458-
{
451+
impl From<KeyValue> for KeyValueMetadata {
452+
fn from(kv: KeyValue) -> Self {
459453
KeyValueMetadata {
460-
key: key.into(),
461-
value: value.into(),
462-
metadata: metadata.into(),
454+
key: kv.key,
455+
value: kv.value.into(),
456+
metadata: BaggageMetadata::default(),
463457
}
464458
}
465459
}
466460

467-
impl From<KeyValue> for KeyValueMetadata {
468-
fn from(kv: KeyValue) -> Self {
469-
KeyValueMetadata {
461+
impl From<(KeyValue, BaggageMetadata)> for KeyValueMetadata {
462+
fn from((kv, metadata): (KeyValue, BaggageMetadata)) -> Self {
463+
Self {
470464
key: kv.key,
471465
value: kv.value.into(),
472-
metadata: BaggageMetadata::default(),
466+
metadata,
467+
}
468+
}
469+
}
470+
471+
impl From<(Key, StringValue, BaggageMetadata)> for KeyValueMetadata {
472+
fn from((key, value, metadata): (Key, StringValue, BaggageMetadata)) -> Self {
473+
Self {
474+
key,
475+
value,
476+
metadata,
473477
}
474478
}
475479
}

0 commit comments

Comments
 (0)