Skip to content

Commit

Permalink
feat(core): extract otel_kind from span attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed Oct 17, 2024
1 parent 31a91a5 commit 4790b45
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions query-engine/core/src/telemetry/models.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use opentelemetry::{sdk::export::trace::SpanData, KeyValue, Value};
use opentelemetry::{sdk::export::trace::SpanData, Key, KeyValue, Value};
use serde::Serialize;
use serde_json::json;
use std::{
Expand All @@ -7,7 +7,15 @@ use std::{
time::{Duration, SystemTime},
};

const ACCEPT_ATTRIBUTES: &[&str] = &["db.system", "db.statement", "itx_id"];
const ACCEPT_ATTRIBUTES: &[&str] = &["db.system", "db.statement", "itx_id", "otel.kind"];

#[derive(Serialize, Debug, Clone, PartialEq, Eq)]
pub enum OtelKind {
#[serde(rename = "client")]
Client,
#[serde(rename = "internal")]
Internal,
}

#[derive(Serialize, Debug, Clone, PartialEq, Eq)]
pub struct TraceSpan {
Expand All @@ -23,6 +31,7 @@ pub struct TraceSpan {
pub(super) events: Vec<Event>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub(super) links: Vec<Link>,
pub(super) otel_kind: OtelKind,
}

#[derive(Serialize, Debug, Clone, PartialEq, Eq)]
Expand All @@ -39,6 +48,14 @@ impl TraceSpan {

impl From<SpanData> for TraceSpan {
fn from(span: SpanData) -> Self {
let otel_kind = match span.attributes.get(&Key::from_static_str("otel.kind")) {
Some(Value::String(kind)) => match kind {

Check failure on line 52 in query-engine/core/src/telemetry/models.rs

View workflow job for this annotation

GitHub Actions / clippy linting

this `match` can be collapsed into the outer `match`
Cow::Borrowed("client") => OtelKind::Client,
_ => OtelKind::Internal,
},
_ => OtelKind::Internal,
};

let attributes: HashMap<String, serde_json::Value> =
span.attributes
.iter()
Expand Down Expand Up @@ -105,6 +122,7 @@ impl From<SpanData> for TraceSpan {
attributes,
links,
events,
otel_kind,
}
}
}
Expand Down

0 comments on commit 4790b45

Please sign in to comment.