Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions opentelemetry-sdk/src/propagation/baggage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use opentelemetry::{
baggage::{BaggageExt, KeyValueMetadata},
baggage::{BaggageExt, BaggageMetadata},
otel_warn,
propagation::{text_map_propagator::FieldIter, Extractor, Injector, TextMapPropagator},
Context,
Context, Key, StringValue,
};
use percent_encoding::{percent_decode_str, utf8_percent_encode, AsciiSet, CONTROLS};
use std::iter;
Expand Down Expand Up @@ -122,10 +122,10 @@ impl TextMapPropagator for BaggagePropagator {
.collect::<Vec<String>>()
.join(";"); // join with ; because we deleted all ; when calling split above

Some(KeyValueMetadata::new(
name.trim().to_owned(),
value.trim().to_string(),
decoded_props.as_str(),
Some((
Key::from(name.trim().to_owned()),
StringValue::from(value.trim().to_owned()),
BaggageMetadata::from(decoded_props.as_str()),
))
} else {
otel_warn!(
Expand Down Expand Up @@ -238,13 +238,14 @@ mod tests {
}

#[rustfmt::skip]
fn valid_inject_data_metadata() -> Vec<(Vec<KeyValueMetadata>, Vec<&'static str>)> {
#[allow(clippy::type_complexity)]
fn valid_inject_data_metadata() -> Vec<(Vec<(KeyValue, BaggageMetadata)>, Vec<&'static str>)> {
vec![
(
vec![
KeyValueMetadata::new("key1", "val1", "prop1"),
KeyValue::new("key2", "val2").into(),
KeyValueMetadata::new("key3", "val3", "anykey=anyvalue"),
(KeyValue::new("key1", "val1"), BaggageMetadata::from("prop1")),
(KeyValue::new("key2", "val2"), BaggageMetadata::default()),
(KeyValue::new("key3", "val3"), BaggageMetadata::from("anykey=anyvalue")),
],
vec![
"key1=val1;prop1",
Expand Down
1 change: 1 addition & 0 deletions opentelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Align `Baggage.remove()` signature with `.get()` to take the key as a reference
- `Baggage` can't be retrieved from the `Context` directly anymore and needs to be accessed via `context.baggage()`
- `with_baggage()` and `current_with_baggage()` override any existing `Baggage` in the `Context`
- `opentelemetry::baggage::KeyValueMetadata` is now private use instead `opentelemetry::KeyValue` with `opentelemetry::baggage::BaggageMetadata`
- 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).
- Added additional `name: Option<&str>` parameter to the `event_enabled` method
on the `Logger` trait. This allows implementations (SDK, processor, exporters)
Expand Down
36 changes: 20 additions & 16 deletions opentelemetry/src/baggage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl fmt::Display for BaggageMetadata {

/// [`Baggage`] name/value pairs with their associated metadata.
#[derive(Clone, Debug, PartialEq)]
pub struct KeyValueMetadata {
struct KeyValueMetadata {
/// Dimension or event key
pub key: Key,
/// Dimension or event value
Expand All @@ -448,28 +448,32 @@ pub struct KeyValueMetadata {
pub metadata: BaggageMetadata,
}

impl KeyValueMetadata {
/// Create a new `KeyValue` pair with metadata
pub fn new<K, V, S>(key: K, value: V, metadata: S) -> Self
where
K: Into<Key>,
V: Into<StringValue>,
S: Into<BaggageMetadata>,
{
impl From<KeyValue> for KeyValueMetadata {
fn from(kv: KeyValue) -> Self {
KeyValueMetadata {
key: key.into(),
value: value.into(),
metadata: metadata.into(),
key: kv.key,
value: kv.value.into(),
metadata: BaggageMetadata::default(),
}
}
}

impl From<KeyValue> for KeyValueMetadata {
fn from(kv: KeyValue) -> Self {
KeyValueMetadata {
impl From<(KeyValue, BaggageMetadata)> for KeyValueMetadata {
fn from((kv, metadata): (KeyValue, BaggageMetadata)) -> Self {
Self {
key: kv.key,
value: kv.value.into(),
metadata: BaggageMetadata::default(),
metadata,
}
}
}

impl From<(Key, StringValue, BaggageMetadata)> for KeyValueMetadata {
fn from((key, value, metadata): (Key, StringValue, BaggageMetadata)) -> Self {
Self {
key,
value,
metadata,
}
}
}
Expand Down