Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/otel/otel_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ pub fn insert_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue])

pub fn convert_epoch_nano_to_timestamp(epoch_ns: i64) -> String {
let dt = DateTime::from_timestamp_nanos(epoch_ns).naive_utc();
dt.format("%Y-%m-%dT%H:%M:%S%.6fZ").to_string()
dt.format("%Y-%m-%dT%H:%M:%S%.9fZ").to_string()
}
21 changes: 19 additions & 2 deletions src/otel/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*/
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
use opentelemetry_proto::tonic::common::v1::KeyValue;
use opentelemetry_proto::tonic::trace::v1::ScopeSpans;
use opentelemetry_proto::tonic::trace::v1::Span;
use opentelemetry_proto::tonic::trace::v1::Status;
Expand All @@ -24,6 +25,8 @@ use opentelemetry_proto::tonic::trace::v1::span::Event;
use opentelemetry_proto::tonic::trace::v1::span::Link;
use serde_json::{Map, Value};

use crate::otel::otel_utils::flatten_attributes;

use super::otel_utils::convert_epoch_nano_to_timestamp;
use super::otel_utils::insert_attributes;

Expand Down Expand Up @@ -197,7 +200,7 @@ fn flatten_events(events: &[Event], span_start_time_unix_nano: u64) -> Vec<Map<S
),
);

insert_attributes(&mut event_json, &event.attributes);
insert_events_attributes(&mut event_json, &event.attributes);
event_json.insert(
"event_dropped_attributes_count".to_string(),
Value::Number(event.dropped_attributes_count.into()),
Expand All @@ -224,7 +227,7 @@ fn flatten_links(links: &[Link]) -> Vec<Map<String, Value>> {
Value::String(hex::encode(&link.trace_id)),
);

insert_attributes(&mut link_json, &link.attributes);
insert_links_attributes(&mut link_json, &link.attributes);
link_json.insert(
"link_dropped_attributes_count".to_string(),
Value::Number(link.dropped_attributes_count.into()),
Expand Down Expand Up @@ -397,6 +400,20 @@ fn flatten_span_record(span_record: &Span) -> Vec<Map<String, Value>> {
span_records_json
}

pub fn insert_events_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
let attributes_json = flatten_attributes(attributes);
for (key, value) in attributes_json {
map.insert(format!("event_{}", key), value);
}
}

pub fn insert_links_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
let attributes_json = flatten_attributes(attributes);
for (key, value) in attributes_json {
map.insert(format!("link_{}", key), value);
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading