Skip to content

Commit ed039ae

Browse files
committed
rework
1 parent b017c7b commit ed039ae

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

opentelemetry-proto/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ testing = ["opentelemetry/testing"]
4646
# add ons
4747
internal-logs = ["tracing"]
4848
with-schemars = ["schemars"]
49-
with-serde = ["serde", "hex"]
49+
with-serde = ["serde", "hex", "base64"]
5050

5151
[dependencies]
5252
tonic = { workspace = true, optional = true, features = ["codegen", "prost"] }
@@ -57,6 +57,7 @@ schemars = { version = "0.8", optional = true }
5757
serde = { workspace = true, optional = true, features = ["serde_derive"] }
5858
hex = { version = "0.4.3", optional = true }
5959
tracing = {workspace = true, optional = true} # optional for opentelemetry internal logging
60+
base64 = { version = "0.22.1", optional = true }
6061

6162
[dev-dependencies]
6263
opentelemetry = { features = ["testing"], path = "../opentelemetry" }

opentelemetry-proto/src/proto.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pub(crate) mod serializers {
5656
map.serialize_entry("intValue", &i.to_string());
5757
map.end()
5858
}
59+
Some(Value::BytesValue(b)) => {
60+
let mut map = serializer.serialize_map(Some(1))?;
61+
map.serialize_entry("bytesValue", &base64::encode(b));
62+
map.end()
63+
}
5964
Some(value) => value.serialize(serializer),
6065
None => serializer.serialize_none(),
6166
}
@@ -127,8 +132,10 @@ pub(crate) mod serializers {
127132
value = Some(any_value::Value::KvlistValue(kv));
128133
}
129134
"bytesValue" => {
130-
let bytes = map.next_value()?;
131-
value = Some(any_value::Value::BytesValue(bytes));
135+
let base64: String = map.next_value()?;
136+
let decoded = base64::decode(base64.as_bytes())
137+
.map_err(|e| de::Error::custom(e))?;
138+
value = Some(any_value::Value::BytesValue(decoded));
132139
}
133140
_ => {
134141
//skip unknown keys, and handle error later.

opentelemetry-proto/tests/json_serde.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,20 @@ mod json_serde {
274274
kind: 2,
275275
start_time_unix_nano: 1544712660000000000,
276276
end_time_unix_nano: 1544712661000000000,
277-
attributes: vec![KeyValue {
277+
attributes: vec![
278+
KeyValue {
278279
key: String::from("my.span.attr"),
279280
value: Some(AnyValue {
280281
value: Some(Value::StringValue(String::from("some value"))),
281282
}),
282-
}],
283+
},
284+
KeyValue {
285+
key: String::from("my.span.bytes.attr"),
286+
value: Some(AnyValue {
287+
value: Some(Value::BytesValue(vec![0x80, 0x80, 0x80])),
288+
}),
289+
},
290+
],
283291
dropped_attributes_count: 1,
284292
events: vec![Event {
285293
time_unix_nano: 1544712660500000000,
@@ -369,6 +377,12 @@ mod json_serde {
369377
"value": {
370378
"stringValue": "some value"
371379
}
380+
},
381+
{
382+
"key": "my.span.bytes.attr",
383+
"value": {
384+
"bytesValue": "gICA"
385+
}
372386
}
373387
],
374388
"droppedAttributesCount": 1,

0 commit comments

Comments
 (0)