Skip to content

Commit a7dd2fd

Browse files
committed
Add protobuf support for onlyspans ingestion
* use official `prost` and `serde` compatible structs from `opentelemetry-proto` * use `axum-extra` with the `protobuf` feature for the protobuf extractor
1 parent 90fa749 commit a7dd2fd

File tree

5 files changed

+193
-9
lines changed

5 files changed

+193
-9
lines changed

Cargo.lock

+166-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

relay-server/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ tower-http = { version = "0.4.0", default-features = false, features = [
124124
url = { workspace = true, features = ["serde"] }
125125
uuid = { workspace = true, features = ["v5"] }
126126
zstd = { version = "0.12.3", optional = true }
127+
axum-extra = { version = "0.7.7", features = ["protobuf"] }
127128

128129
[dev-dependencies]
129130
tokio = { workspace = true, features = ['test-util'] }

relay-server/src/endpoints/spans.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
use axum::extract::{DefaultBodyLimit, Json};
2-
use axum::http::StatusCode;
2+
use axum::http::{Request, StatusCode};
33
use axum::response::IntoResponse;
44
use axum::routing::{post, MethodRouter};
5+
use axum::RequestExt;
6+
use axum_extra::protobuf::Protobuf;
57
use bytes::Bytes;
68

79
use relay_config::Config;
8-
use relay_spans::TracesData;
10+
use relay_spans::Otlp;
911

10-
use crate::endpoints::common::{self, BadStoreRequest};
12+
use crate::endpoints::common;
1113
use crate::envelope::{ContentType, Envelope, Item, ItemType};
12-
use crate::extractors::RequestMeta;
14+
use crate::extractors::{RawContentType, RequestMeta};
1315
use crate::service::ServiceState;
1416

15-
async fn handle(
17+
async fn handle<B>(
1618
state: ServiceState,
19+
content_type: RawContentType,
1720
meta: RequestMeta,
18-
Json(trace): Json<TracesData>,
19-
) -> Result<impl IntoResponse, BadStoreRequest> {
21+
request: Request<B>,
22+
) -> axum::response::Result<impl IntoResponse>
23+
where
24+
B: axum::body::HttpBody + Send + 'static,
25+
B::Data: Send + Into<Bytes>,
26+
B::Error: Into<axum::BoxError>,
27+
{
28+
let trace = if content_type.as_ref().starts_with("application/json") {
29+
let json: Json<Otlp::TracesData> = request.extract().await?;
30+
json.0
31+
} else {
32+
let protobuf: Protobuf<Otlp::TracesData> = request.extract().await?;
33+
protobuf.0
34+
};
35+
2036
let mut envelope = Envelope::from_request(None, meta);
2137
for resource_span in trace.resource_spans {
2238
for scope_span in resource_span.scope_spans {

relay-spans/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ publish = false
1313
chrono.workspace = true
1414
enumset = "1.0.4"
1515
once_cell.workspace = true
16+
opentelemetry-proto = { version = "0.4.0", features = ["gen-tonic", "with-serde", "trace"] }
1617
relay-event-schema = { path = "../relay-event-schema" }
1718
relay-protocol = { path = "../relay-protocol" }
1819
serde.workspace = true

relay-spans/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
pub use crate::span::OtelSpan;
1010
pub use crate::trace::TracesData;
1111

12+
pub use opentelemetry_proto::tonic::trace::v1 as Otlp;
13+
1214
mod otel_to_sentry_tags;
1315
mod span;
1416
mod status_codes;

0 commit comments

Comments
 (0)