Skip to content

Commit

Permalink
Revert "ref(spans): Remove the otel spans endpoint (#3973)"
Browse files Browse the repository at this point in the history
This reverts commit 44186da.
  • Loading branch information
jjbayer committed Nov 5, 2024
1 parent d12ff53 commit 5a2d43e
Show file tree
Hide file tree
Showing 11 changed files with 742 additions and 30 deletions.
122 changes: 105 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pin-project-lite = "0.2.12"
pretty-hex = "0.4.1"
priority-queue = "2.0.3"
proc-macro2 = "1.0.8"
prost = "0.11.9"
psl = "2.1.33"
quote = "1.0.2"
r2d2 = "0.8.10"
Expand Down
1 change: 1 addition & 0 deletions relay-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ once_cell = { workspace = true }
papaya = { workspace = true }
pin-project-lite = { workspace = true }
priority-queue = { workspace = true }
prost = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions relay-server/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod nel;
mod project_configs;
mod public_keys;
mod security_report;
mod spans;
mod statics;
mod store;
mod unreal;
Expand Down Expand Up @@ -74,6 +75,7 @@ pub fn routes(config: &Config) -> Router<ServiceState>{
.route("/api/:project_id/minidump/", minidump::route(config))
.route("/api/:project_id/events/:event_id/attachments/", post(attachments::handle))
.route("/api/:project_id/unreal/:sentry_key/", unreal::route(config))
.route("/api/:project_id/spans/", spans::route(config))
// NOTE: If you add a new (non-experimental) route here, please also list it in
// https://github.com/getsentry/sentry-docs/blob/master/docs/product/relay/operating-guidelines.mdx
.route_layer(middlewares::cors());
Expand Down
62 changes: 62 additions & 0 deletions relay-server/src/endpoints/spans.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use axum::extract::{DefaultBodyLimit, Json, Request};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::routing::{post, MethodRouter};
use axum::RequestExt;
use bytes::Bytes;
use prost::Message;
use relay_config::Config;
use relay_dynamic_config::Feature;
use relay_spans::otel_trace::TracesData;

use crate::endpoints::common;
use crate::envelope::{ContentType, Envelope, Item, ItemType};
use crate::extractors::{RawContentType, RequestMeta};
use crate::service::ServiceState;
use crate::utils::ApiErrorResponse;

async fn handle(
state: ServiceState,
content_type: RawContentType,
meta: RequestMeta,
request: Request,
) -> axum::response::Result<impl IntoResponse> {
let trace: TracesData = if content_type.as_ref().starts_with("application/json") {
let Json(trace) = request.extract().await?;
trace
} else if content_type.as_ref().starts_with("application/x-protobuf") {
// let mut bytes: Bytes = Bytes::from_request(req, state).await?;
// let Protobuf(trace) = request.extract().await?;
let mut bytes: Bytes = request.extract().await?;
Message::decode(&mut bytes).map_err(|e| {
(
StatusCode::UNPROCESSABLE_ENTITY,
ApiErrorResponse::from_error(&e),
)
})?
} else {
return Ok(StatusCode::UNSUPPORTED_MEDIA_TYPE);
};

let mut envelope = Envelope::from_request(None, meta);
envelope.require_feature(Feature::OtelEndpoint);
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)
}

pub fn route(config: &Config) -> MethodRouter<ServiceState> {
post(handle).route_layer(DefaultBodyLimit::max(config.max_span_size()))
}
Loading

0 comments on commit 5a2d43e

Please sign in to comment.