Skip to content

Commit

Permalink
Remove custom AttributeValue
Browse files Browse the repository at this point in the history
  • Loading branch information
hatchan committed Aug 28, 2024
1 parent 0d6eddf commit eb15d81
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 45 deletions.
49 changes: 5 additions & 44 deletions fpx-lib/src/api/models/otel.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use opentelemetry_proto::tonic::common::v1::{any_value, KeyValueList};
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
use opentelemetry_proto::tonic::common::v1::{AnyValue, KeyValue, KeyValueList};
use opentelemetry_proto::tonic::trace::v1::span::{Event, Link};
use opentelemetry_proto::tonic::trace::v1::status::StatusCode;
use opentelemetry_proto::tonic::trace::v1::{span, Status};
use opentelemetry_proto::tonic::{
collector::trace::v1::ExportTraceServiceRequest, common::v1::KeyValue,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -231,7 +229,7 @@ impl From<StatusCode> for SpanStatusCode {
}

#[derive(Clone, Debug, Serialize, Deserialize, Default, PartialEq)]
pub struct AttributeMap(pub BTreeMap<String, Option<AttributeValue>>);
pub struct AttributeMap(pub BTreeMap<String, Option<AnyValue>>);

impl From<KeyValueList> for AttributeMap {
fn from(value: KeyValueList) -> Self {
Expand All @@ -241,52 +239,15 @@ impl From<KeyValueList> for AttributeMap {

impl From<Vec<KeyValue>> for AttributeMap {
fn from(attributes: Vec<KeyValue>) -> Self {
let result: BTreeMap<String, Option<AttributeValue>> = attributes
let result: BTreeMap<String, Option<AnyValue>> = attributes
.into_iter()
.map(|kv| {
(
kv.key,
kv.value.and_then(|value| value.value.map(Into::into)),
)
})
.map(|kv| (kv.key, kv.value))
.collect();

AttributeMap(result)
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum AttributeValue {
String(String),
Bool(bool),
Int(i64),
Double(f64),
Array(Vec<AttributeValue>),
KeyValueList(AttributeMap),
Bytes(Vec<u8>),
}

impl From<any_value::Value> for AttributeValue {
fn from(value: any_value::Value) -> Self {
match value {
any_value::Value::StringValue(val) => AttributeValue::String(val),
any_value::Value::BoolValue(val) => AttributeValue::Bool(val),
any_value::Value::IntValue(val) => AttributeValue::Int(val),
any_value::Value::DoubleValue(val) => AttributeValue::Double(val),
any_value::Value::BytesValue(val) => AttributeValue::Bytes(val),
any_value::Value::ArrayValue(val) => {
let val: Vec<_> = val
.values
.into_iter()
.flat_map(|value| value.value.map(|value| value.into()))
.collect();
AttributeValue::Array(val)
}
any_value::Value::KvlistValue(val) => AttributeValue::KeyValueList(val.values.into()),
}
}
}

/// A trace contains a summary of its traces.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct TraceSummary {
Expand Down
1 change: 1 addition & 0 deletions fpx-lib/src/data/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ mod tests {
)
}

#[cfg(target_family = "wasm")]
#[cfg(feature = "wasm-bindgen")]
#[test]
fn timestamp_serialize_wasm_bindgen() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/otel_collector/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ service:
pipelines:
traces:
receivers: [otlp]
exporters: [debug, otlphttp/fpx-workers]
exporters: [debug, otlphttp]

telemetry:
logs:
Expand Down

0 comments on commit eb15d81

Please sign in to comment.