Commit 35e991c9 authored by Daniel Willmann's avatar Daniel Willmann
Browse files

Populate Span and event with Attrs

parent 9c640388
......@@ -470,6 +470,7 @@ dependencies = [
"nom_locate",
"opentelemetry",
"opentelemetry-jaeger",
"opentelemetry-semantic-conventions",
"tracing",
"tracing-opentelemetry",
"tracing-subscriber",
......@@ -690,6 +691,15 @@ dependencies = [
"thrift",
]
[[package]]
name = "opentelemetry-semantic-conventions"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3839dd2c931dc1aabcf964623ad74478fa97b3a88ad073d9e107aea36520c21d"
dependencies = [
"opentelemetry",
]
[[package]]
name = "ordered-float"
version = "1.1.1"
......
......@@ -18,4 +18,5 @@ tracing-subscriber = "0.2.15"
async-std = { version = "1.8.0", features = ["attributes"] }
opentelemetry = { version = "0.11.2", features = ["async-std"] }
opentelemetry-jaeger = { version = "0.10.0", features = ["async-std"] }
opentelemetry-semantic-conventions = "0.3.0"
......@@ -99,7 +99,7 @@ async fn main() -> Result<()> {
match otrace {
trace::OsmoTrace::EnterFunc(attrs) => {
let frame = Frame {
name: attrs.common.name,
name: attrs.common.name.clone(),
fsm: String::new(),
};
......@@ -113,6 +113,8 @@ async fn main() -> Result<()> {
let ctx = opentelemetry::Context::new().with_span(parent.clone());
span = span.with_parent_context(ctx);
}
let attrs = attrs.span_attrs();
span = span.with_attributes(attrs);
let span = span.start(&peer.tracer);
info!("Entering function {}", &frame.name);
peer.callstack.push((frame, span));
......@@ -137,8 +139,8 @@ async fn main() -> Result<()> {
trace::OsmoTrace::SetAttr(_) => {}
trace::OsmoTrace::Event(event) => {
if let Some((_frame, span)) = &peer.callstack.get(peer.callstack.len() - 1) {
// FIXME: Set attributes!
span.add_event_with_timestamp(event.msg, event.common.timestamp, Vec::new());
let attrs = event.span_attrs();
span.add_event_with_timestamp(event.msg, event.common.timestamp, attrs);
} else {
warn!("Got event without span: {:?}", &event);
}
......
......@@ -214,6 +214,24 @@ pub struct TraceCommon {
pub src: SrcInfo,
}
impl TraceCommon {
pub fn span_attrs(&self) -> Vec<opentelemetry::KeyValue> {
use opentelemetry_semantic_conventions::resource::*;
use opentelemetry_semantic_conventions::trace::*;
use opentelemetry::KeyValue;
let mut attrs = Vec::new();
attrs.push(KeyValue::new(PROCESS_PID, self.pid as i64));
attrs.push(KeyValue::new(PROCESS_EXECUTABLE_NAME, self.proc_name.clone()));
attrs.push(KeyValue::new(SERVICE_NAME, self.proc_name.clone()));
attrs.push(KeyValue::new(CODE_FILEPATH, self.src.file.clone()));
attrs.push(KeyValue::new(CODE_FUNCTION, self.name.clone()));
attrs.push(KeyValue::new(CODE_LINENO, self.src.line as i64));
attrs.push(KeyValue::new("level", self.level as i64));
attrs.push(KeyValue::new("subsystem", self.subsys.clone()));
attrs
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TraceAttrs {
pub common: TraceCommon,
......@@ -226,6 +244,14 @@ impl TraceAttrs {
common, attrs
}
}
pub fn span_attrs(&self) -> Vec<opentelemetry::KeyValue> {
use opentelemetry::KeyValue;
let mut span_attrs = self.common.span_attrs();
for (key, value) in self.attrs.iter() {
span_attrs.push(KeyValue::new(key.clone(), value.clone()));
}
span_attrs
}
}
#[derive(Debug, Clone, PartialEq)]
......@@ -255,6 +281,9 @@ impl TraceEvent {
common, msg
}
}
pub fn span_attrs(&self) -> Vec<opentelemetry::KeyValue> {
self.common.span_attrs()
}
}
#[derive(Debug, Clone, PartialEq)]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment