Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion engine/packages/api-builder/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{net::SocketAddr, time::Instant};
use anyhow::Result;
use axum::{
body::{Body, HttpBody},
extract::{ConnectInfo, State},
extract::{ConnectInfo, MatchedPath, State},
http::{Request, StatusCode},
middleware::Next,
response::Response,
Expand Down Expand Up @@ -67,6 +67,11 @@ pub async fn http_logging_middleware(
ray_id = %request_ids.ray_id,
req_id = %request_ids.req_id,
);
req_span.set_attribute("http.request.method", req.method().to_string());
req_span.set_attribute("http.path", req.uri().to_string());
if let Some(path) = req.extensions().get::<MatchedPath>() {
req_span.set_attribute("http.route", path.as_str().to_string());
}
req_span.add_link(current_span_ctx);

// Extract headers for logging
Expand Down Expand Up @@ -122,6 +127,8 @@ pub async fn http_logging_middleware(
let status = response.status();
let status_code = status.as_u16();

tracing::Span::current().set_attribute("http.response.status_code", status_code as i64);

let error = response.extensions().get::<ErrorExt>();

// Log based on status
Expand Down
1 change: 1 addition & 0 deletions engine/packages/guard-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ serde.workspace = true
tokio-rustls.workspace = true
tokio-tungstenite.workspace = true
tokio.workspace = true
tracing-opentelemetry.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing.workspace = true
url.workspace = true
Expand Down
13 changes: 10 additions & 3 deletions engine/packages/guard-core/src/proxy_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rivet_api_builder::{RequestIds, X_RIVET_RAY_ID};
use rivet_error::{INTERNAL_ERROR, RivetError};
use rivet_util::Id;
use serde_json;
use tracing_opentelemetry::OpenTelemetrySpanExt;

use rivet_runner_protocol as protocol;
use std::{
Expand Down Expand Up @@ -2009,9 +2010,10 @@ impl ProxyService {
let request_ids = RequestIds::new(self.state.config.dc_label());
req.extensions_mut().insert(request_ids);

tracing::Span::current()
.record("req_id", request_ids.req_id.to_string())
.record("ray_id", request_ids.ray_id.to_string());
let current_span = tracing::Span::current();

current_span.record("req_id", request_ids.req_id.to_string());
current_span.record("ray_id", request_ids.ray_id.to_string());

// Extract request information for logging and analytics before consuming the request
let incoming_ray_id = req
Expand All @@ -2033,6 +2035,9 @@ impl ProxyService {
.unwrap_or_else(|| req.uri().path().to_string());
let method = req.method().clone();

current_span.set_attribute("http.request.method", method.to_string());
current_span.set_attribute("http.path", uri_string.clone());

let user_agent = req
.headers()
.get(hyper::header::USER_AGENT)
Expand Down Expand Up @@ -2213,6 +2218,8 @@ impl ProxyService {

let status = res.status().as_u16();

current_span.set_attribute("http.response.status_code", status as i64);

let content_length = res
.headers()
.get(hyper::header::CONTENT_LENGTH)
Expand Down
Loading