Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Feb 8, 2024
1 parent f202701 commit 2c9d457
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 88 deletions.
43 changes: 22 additions & 21 deletions relay-server/src/endpoints/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@ where
B::Data: Send + Into<Bytes>,
B::Error: Into<axum::BoxError>,
{
let mut trace = None;
if content_type.as_ref().starts_with("application/json") {
let trace = if content_type.as_ref().starts_with("application/json") {
let json: Json<TracesData> = request.extract().await?;
trace = Some(json.0)
Some(json.0)
} else if content_type.as_ref().starts_with("application/x-protobuf") {
let protobuf: Protobuf<TracesData> = request.extract().await?;
trace = Some(protobuf.0)
}
Some(protobuf.0)
} else {
None
};

if let Some(trace) = trace {
let mut envelope = Envelope::from_request(None, meta);
for resource_span in trace.resource_spans {
for scope_span in resource_span.scope_spans {
for span in scope_span.spans {
let Ok(payload) = serde_json::to_vec(&span) else {
continue;
};
let mut item = Item::new(ItemType::OtelSpan);
item.set_payload(ContentType::Json, payload);
envelope.add_item(item);
}
let Some(trace) = trace else {
return Ok(StatusCode::UNSUPPORTED_MEDIA_TYPE);
};

let mut envelope = Envelope::from_request(None, meta);
for resource_span in trace.resource_spans {
for scope_span in resource_span.scope_spans {
for span in scope_span.spans {
let Ok(payload) = serde_json::to_vec(&span) else {
continue;
};
let mut item = Item::new(ItemType::OtelSpan);
item.set_payload(ContentType::Json, payload);
envelope.add_item(item);
}
}
common::handle_envelope(&state, envelope).await?;
Ok(StatusCode::ACCEPTED)
} else {
Ok(StatusCode::UNSUPPORTED_MEDIA_TYPE)
}
common::handle_envelope(&state, envelope).await?;
Ok(StatusCode::ACCEPTED)
}

pub fn route<B>(config: &Config) -> MethodRouter<ServiceState, B>
Expand Down
1 change: 0 additions & 1 deletion relay-spans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ pub use opentelemetry_proto::tonic::trace::v1 as OtelTrace;
mod otel_to_sentry_tags;
mod span;
mod status_codes;
mod utils;
23 changes: 0 additions & 23 deletions relay-spans/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ impl OtelValueExt for OtelValue {
#[cfg(test)]
mod tests {
use super::*;
use chrono::{DateTime, Utc};
use relay_protocol::{get_path, Annotated};

#[test]
Expand Down Expand Up @@ -299,26 +298,4 @@ mod tests {
let event_span: EventSpan = otel_span.to_sentry_span();
assert_eq!(event_span.exclusive_time, Annotated::new(0.0788));
}

#[ignore = "not supported with the new otel structs"]
#[test]
fn parse_span_with_timestamps_as_strings() {
let json = r#"{
"traceId": "89143b0763095bd9c9955e8175d1fb23",
"spanId": "e342abb1214ca181",
"parentSpanId": "0c7a7dea069bf5a6",
"name": "middleware - fastify -> @fastify/multipart",
"kind": 1,
"startTimeUnixNano": "1697620454980000000",
"endTimeUnixNano": "1697620454980078800"
}"#;
let otel_span: OtelSpan = serde_json::from_str(json).unwrap();
let event_span: EventSpan = otel_span.to_sentry_span();
assert_eq!(
event_span.start_timestamp,
Annotated::new(Timestamp(
DateTime::<Utc>::from_timestamp(1697620454, 980000000).unwrap()
))
);
}
}
43 changes: 0 additions & 43 deletions relay-spans/src/utils.rs

This file was deleted.

0 comments on commit 2c9d457

Please sign in to comment.