Skip to content

Commit ab81e0f

Browse files
committed
update AnyValue complex variants as Box
1 parent ad990d6 commit ab81e0f

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

opentelemetry-proto/src/transform/logs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub mod tonic {
5050
})
5151
.collect(),
5252
}),
53-
LogsAnyValue::Bytes(v) => Value::BytesValue(v),
53+
54+
LogsAnyValue::Bytes(v) => Value::BytesValue(*v),
5455
}
5556
}
5657
}

opentelemetry-sdk/benches/log.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -100,74 +100,82 @@ fn criterion_benchmark(c: &mut Criterion) {
100100
logger.emit(log_record);
101101
});
102102

103-
let bytes = AnyValue::Bytes(vec![25u8, 30u8, 40u8]);
103+
let bytes = AnyValue::Bytes(Box::new(vec![25u8, 30u8, 40u8]));
104104
log_benchmark_group(c, "simple-log-with-bytes", |logger| {
105105
let mut log_record = logger.create_log_record();
106106
log_record.set_body("simple log".into());
107107
log_record.add_attribute("testbytes", bytes.clone());
108108
logger.emit(log_record);
109109
});
110110

111-
let bytes = AnyValue::Bytes(vec![
111+
let bytes = AnyValue::Bytes(Box::new(vec![
112112
25u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
113113
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8,
114114
40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
115115
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8,
116116
40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
117117
30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8, 30u8, 40u8,
118-
]);
118+
]));
119119
log_benchmark_group(c, "simple-log-with-a-lot-of-bytes", |logger| {
120120
let mut log_record = logger.create_log_record();
121121
log_record.set_body("simple log".into());
122122
log_record.add_attribute("testbytes", bytes.clone());
123123
logger.emit(log_record);
124124
});
125125

126-
let vec_any_values = AnyValue::ListAny(vec![AnyValue::Int(25), "test".into(), true.into()]);
126+
let vec_any_values = AnyValue::ListAny(Box::new(vec![
127+
AnyValue::Int(25),
128+
"test".into(),
129+
true.into(),
130+
]));
127131
log_benchmark_group(c, "simple-log-with-vec-any-value", |logger| {
128132
let mut log_record = logger.create_log_record();
129133
log_record.set_body("simple log".into());
130134
log_record.add_attribute("testvec", vec_any_values.clone());
131135
logger.emit(log_record);
132136
});
133137

134-
let vec_any_values = AnyValue::ListAny(vec![AnyValue::Int(25), "test".into(), true.into()]);
135-
let vec_any_values = AnyValue::ListAny(vec![
138+
let vec_any_values = AnyValue::ListAny(Box::new(vec![
139+
AnyValue::Int(25),
140+
"test".into(),
141+
true.into(),
142+
]));
143+
let vec_any_values = AnyValue::ListAny(Box::new(vec![
136144
AnyValue::Int(25),
137145
"test".into(),
138146
true.into(),
139147
vec_any_values,
140-
]);
148+
]));
141149
log_benchmark_group(c, "simple-log-with-inner-vec-any-value", |logger| {
142150
let mut log_record = logger.create_log_record();
143151
log_record.set_body("simple log".into());
144152
log_record.add_attribute("testvec", vec_any_values.clone());
145153
logger.emit(log_record);
146154
});
147155

148-
let map_any_values = AnyValue::Map(HashMap::from([
156+
let map_any_values = AnyValue::Map(Box::new(HashMap::from([
149157
("testint".into(), 2.into()),
150158
("testdouble".into(), 2.2.into()),
151159
("teststring".into(), "test".into()),
152-
]));
160+
])));
153161
log_benchmark_group(c, "simple-log-with-map-any-value", |logger| {
154162
let mut log_record = logger.create_log_record();
155163
log_record.set_body("simple log".into());
156164
log_record.add_attribute("testmap", map_any_values.clone());
157165
logger.emit(log_record);
158166
});
159167

160-
let map_any_values = AnyValue::Map(HashMap::from([
168+
let map_any_values = AnyValue::Map(Box::new(HashMap::from([
161169
("testint".into(), 2.into()),
162170
("testdouble".into(), 2.2.into()),
163171
("teststring".into(), "test".into()),
164-
]));
165-
let map_any_values = AnyValue::Map(HashMap::from([
172+
])));
173+
let map_any_values = AnyValue::Map(Box::new(HashMap::from([
166174
("testint".into(), 2.into()),
167175
("testdouble".into(), 2.2.into()),
168176
("teststring".into(), "test".into()),
169177
("testmap".into(), map_any_values),
170-
]));
178+
])));
171179
log_benchmark_group(c, "simple-log-with-inner-map-any-value", |logger| {
172180
let mut log_record = logger.create_log_record();
173181
log_record.set_body("simple log".into());

opentelemetry-stdout/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl From<opentelemetry::logs::AnyValue> for Value {
156156
})
157157
.collect(),
158158
),
159-
opentelemetry::logs::AnyValue::Bytes(b) => Value::BytesValue(b),
159+
opentelemetry::logs::AnyValue::Bytes(b) => Value::BytesValue(*b),
160160
}
161161
}
162162
}

opentelemetry/src/logs/record.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ pub enum AnyValue {
5959
/// A boolean value
6060
Boolean(bool),
6161
/// A byte array
62-
Bytes(Vec<u8>),
62+
Bytes(Box<Vec<u8>>),
6363
/// An array of `Any` values
64-
ListAny(Vec<AnyValue>),
64+
ListAny(Box<Vec<AnyValue>>),
6565
/// A map of string keys to `Any` values, arbitrarily nested.
66-
Map(HashMap<Key, AnyValue>),
66+
Map(Box<HashMap<Key, AnyValue>>),
6767
}
6868

6969
macro_rules! impl_trivial_from {
@@ -98,17 +98,17 @@ impl_trivial_from!(bool, AnyValue::Boolean);
9898
impl<T: Into<AnyValue>> FromIterator<T> for AnyValue {
9999
/// Creates an [`AnyValue::ListAny`] value from a sequence of `Into<AnyValue>` values.
100100
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
101-
AnyValue::ListAny(iter.into_iter().map(Into::into).collect())
101+
AnyValue::ListAny(Box::new(iter.into_iter().map(Into::into).collect()))
102102
}
103103
}
104104

105105
impl<K: Into<Key>, V: Into<AnyValue>> FromIterator<(K, V)> for AnyValue {
106106
/// Creates an [`AnyValue::Map`] value from a sequence of key-value pairs
107107
/// that can be converted into a `Key` and `AnyValue` respectively.
108108
fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self {
109-
AnyValue::Map(HashMap::from_iter(
109+
AnyValue::Map(Box::new(HashMap::from_iter(
110110
iter.into_iter().map(|(k, v)| (k.into(), v.into())),
111-
))
111+
)))
112112
}
113113
}
114114

0 commit comments

Comments
 (0)