Skip to content

Commit

Permalink
Capture logs at the beginning of a transaction on successful Tx start
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Jan 17, 2023
1 parent 7048670 commit fb1e2b0
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions query-engine/query-engine/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,7 @@ async fn transaction_start_handler(state: State, req: Request<Body>) -> Result<R
};

match result {
Ok(tx_id) => {
let result = json!({ "id": tx_id.to_string() });
let result_bytes = serde_json::to_vec(&result).unwrap();

let res = Response::builder()
.status(StatusCode::OK)
.header(CONTENT_TYPE, "application/json")
.body(Body::from(result_bytes))
.unwrap();

Ok(res)
}
Ok(tx_id) => Ok(tx_id_to_http_resp(tx_id, telemetry)),
Err(err) => Ok(err_to_http_resp(err, telemetry)),
}
}
Expand Down Expand Up @@ -369,6 +358,24 @@ impl<'a> Extractor for HeaderExtractor<'a> {
}
}

fn tx_id_to_http_resp(
tx_id: TxId,
captured_telemetry: Option<telemetry::capturing::storage::Storage>,
) -> Response<Body> {
let result = if let Some(telemetry) = captured_telemetry {
json!({ "id": tx_id.to_string(), "extensions": { "logs": json!(telemetry.logs), "traces": json!(telemetry.traces) } })
} else {
json!({ "id": tx_id.to_string() })
};
let result_bytes = serde_json::to_vec(&result).unwrap();

Response::builder()
.status(StatusCode::OK)
.header(CONTENT_TYPE, "application/json")
.body(dbg!(Body::from(result_bytes)))
.unwrap()
}

fn err_to_http_resp(
err: query_core::CoreError,
captured_telemetry: Option<telemetry::capturing::storage::Storage>,
Expand Down

0 comments on commit fb1e2b0

Please sign in to comment.