Skip to content

Commit

Permalink
Revert "DataDog traces enabled (#38)" (#41)
Browse files Browse the repository at this point in the history
This reverts commit 1ea9b9c.
  • Loading branch information
michalstruck authored Dec 17, 2024
1 parent 1ea9b9c commit ae70b24
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 669 deletions.
570 changes: 17 additions & 553 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ tokio = { version = "1.41.0", features = ["full"] }
chrono = { version = "0.4.38", features = ["serde"] }
reqwest = { version = "0.12.8", features = ["json"] }
serde = { version = "1.0.213", features = ["derive"] }
tower-http = { version = "0.6.1", features = [
"trace",
"timeout",
"cors"
] }
tower-http = { version = "0.6.1", features = ["cors"] }
axum-jsonschema = { version = "0.8.0", features = ["aide"] }
schemars = { version = "0.8.21", features = ["chrono", "url"] }
aide = { version = "0.13.4", features = ["axum", "macros", "scalar"] }
tracing-subscriber = "0.3.19"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
ruint = { version = "1.12.3", default-features = false, features = [
"num-traits",
] }
Expand All @@ -53,8 +49,6 @@ sqlx = { version = "0.8.2", features = [
"tls-rustls",
"runtime-tokio",
], default-features = false }
tracing-opentelemetry = "0.17.4"
telemetry-batteries = { git = "https://github.com/worldcoin/telemetry-batteries", rev = "901ea26" }


[build-dependencies]
Expand Down
22 changes: 5 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ mod types;
mod utils;
mod verify;

use telemetry_batteries::tracing::{
datadog::DatadogBattery, stdout::StdoutBattery, TracingShutdownHandle,
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();

let _tracing_shutdown_handle = init_telemetry();
tracing_subscriber::fmt()
.json()
.with_target(false)
.flatten_event(true)
.init();

tracing::info!("👩 Server started");

Expand All @@ -27,15 +27,3 @@ async fn main() -> anyhow::Result<()> {

server::start(config).await
}

fn init_telemetry() -> TracingShutdownHandle {
let traces_endpoint = Some("http://localhost:8126".to_string());

traces_endpoint
.as_ref()
.map_or_else(StdoutBattery::init, |traces_endpoint| {
let handle = DatadogBattery::init(Some(traces_endpoint), "wld-usernames", None, true);

handle
})
}
1 change: 0 additions & 1 deletion src/routes/api/v1/query_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{
types::{ErrorResponse, Name, QueryAddressesPayload, UsernameRecord},
};

#[tracing::instrument(skip_all)]
pub async fn query_multiple(
Extension(db): Extension<Db>,
Json(payload): Json<QueryAddressesPayload>,
Expand Down
11 changes: 0 additions & 11 deletions src/routes/api/v1/query_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@ use crate::{
types::{ErrorResponse, MovedRecord, Name, UsernameRecord},
};

#[tracing::instrument(skip(db))]
pub async fn query_single(
Extension(db): Extension<Db>,
Path(name_or_address): Path<String>,
) -> Result<Response, ErrorResponse> {
let query_names_span = tracing::span!(
tracing::Level::INFO,
"names_table",
query_type = "SELECT"
);
let _names_enter = query_names_span.enter();
if let Some(name) = sqlx::query_as!(
Name,
"SELECT * FROM names WHERE username = $1 OR address = $1",
Expand All @@ -34,10 +27,7 @@ pub async fn query_single(
{
return Ok(Json(UsernameRecord::from(name)).into_response());
};
drop(_names_enter);

let moved_span = tracing::span!(tracing::Level::INFO, "old_names_table", query_type = "SELECT");
let _moved_enter = moved_span.enter();
if let Some(moved) = sqlx::query_as!(
MovedRecord,
"SELECT * FROM old_names WHERE old_username = $1",
Expand All @@ -48,7 +38,6 @@ pub async fn query_single(
{
return Ok(Redirect::permanent(&format!("/api/v1/{}", moved.new_username)).into_response());
}
drop(_moved_enter);

Err(ErrorResponse::not_found("Record not found.".to_string()))
}
Expand Down
18 changes: 0 additions & 18 deletions src/routes/api/v1/register_username.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
verify,
};

#[tracing::instrument(skip_all)]
#[allow(dependency_on_unit_never_type_fallback)]
pub async fn register_username(
Extension(config): ConfigExt,
Expand Down Expand Up @@ -63,13 +62,6 @@ pub async fn register_username(
.ensure_valid(&payload.username)
.map_err(|e| ErrorResponse::validation_error(e.to_string()))?;

let uniqueness_span = tracing::span!(
tracing::Level::INFO,
"query_uniqueness_check",
query_type = "SELECT",
username = %payload.username
);
let _uniqueness_enter = uniqueness_span.enter();
let uniqueness_check = sqlx::query!(
"SELECT
EXISTS(SELECT 1 FROM names WHERE nullifier_hash = $2) AS world_id,
Expand All @@ -79,7 +71,6 @@ pub async fn register_username(
)
.fetch_one(&db.read_write)
.await?;
drop(_uniqueness_enter);

if uniqueness_check.username.unwrap_or_default() {
return Err(ErrorResponse::validation_error(
Expand All @@ -93,14 +84,6 @@ pub async fn register_username(
));
}

let insert_span = tracing::span!(
parent: None,
tracing::Level::INFO,
"insert_new_name",
query_type = "INSERT",
username = %payload.username
);
let _insert_enter = insert_span.enter();
Name::new(
payload.username,
&payload.address,
Expand All @@ -110,7 +93,6 @@ pub async fn register_username(
)
.insert(&db.read_write, "names")
.await?;
drop(_insert_enter);

Ok(StatusCode::CREATED)
}
Expand Down
37 changes: 0 additions & 37 deletions src/routes/api/v1/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,13 @@ use crate::{
verify,
};

#[tracing::instrument(
skip(config, db, blocklist),
fields(
old_username = %payload.old_username,
new_username = %payload.new_username
)
)]
#[allow(dependency_on_unit_never_type_fallback)]
pub async fn rename(
Extension(config): ConfigExt,
Extension(db): Extension<Db>,
Extension(blocklist): BlocklistExt,
Json(payload): Json<RenamePayload>,
) -> Result<StatusCode, ErrorResponse> {
// Add span for initial record lookup
let lookup_span = tracing::span!(
parent: None,
tracing::Level::INFO,
"query_initial_lookup",
query_type = "SELECT",
username = %payload.old_username
);
let _lookup_enter = lookup_span.enter();
let Some(record) = sqlx::query_as!(
Name,
"SELECT * FROM names WHERE username = $1",
Expand All @@ -43,7 +27,6 @@ pub async fn rename(
else {
return Err(ErrorResponse::not_found("Username not found".to_string()));
};
drop(_lookup_enter);

if record.nullifier_hash != payload.nullifier_hash {
return Err(ErrorResponse::unauthorized(
Expand Down Expand Up @@ -96,15 +79,6 @@ pub async fn rename(
.ensure_valid(&payload.new_username)
.map_err(|e| ErrorResponse::validation_error(e.to_string()))?;

let uniqueness_span = tracing::span!(
parent: None,
tracing::Level::INFO,
"query_uniqueness_check",
query_type = "SELECT",
old_username = %payload.old_username,
new_username = %payload.new_username
);
let _uniqueness_enter = uniqueness_span.enter();
let uniqueness_check = sqlx::query!(
"SELECT
EXISTS(SELECT 1 FROM old_names where new_username = $1) AS has_old_username,
Expand All @@ -115,23 +89,13 @@ pub async fn rename(
)
.fetch_one(&db.read_write)
.await?;
drop(_uniqueness_enter);

if uniqueness_check.username.unwrap_or_default() {
return Err(ErrorResponse::validation_error(
"Username is already taken".to_string(),
));
};

let transaction_span = tracing::span!(
parent: None,
tracing::Level::INFO,
"rename_transaction",
query_type = "TRANSACTION",
old_username = %payload.old_username,
new_username = %payload.new_username
);
let _transaction_enter = transaction_span.enter();
let mut tx = db.read_write.begin().await?;

if uniqueness_check.has_old_username.unwrap_or_default() {
Expand Down Expand Up @@ -160,7 +124,6 @@ pub async fn rename(
.await?;

tx.commit().await?;
drop(_transaction_enter);

Ok(StatusCode::OK)
}
Expand Down
2 changes: 0 additions & 2 deletions src/routes/api/v1/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use axum::{
};
use axum_jsonschema::Json;

#[tracing::instrument(skip_all)]
pub async fn search(
Extension(db): Extension<Db>,
Path(username): Path<String>,
Expand Down Expand Up @@ -40,7 +39,6 @@ pub async fn search(
.into_response());
}

#[tracing::instrument(skip_all)]
pub fn docs(op: aide::transform::TransformOperation) -> aide::transform::TransformOperation {
op.description("Search for up to 10 usernames. Accepts 1 to 14, only valid username characters to search with.")
.response::<200, Json<Vec<UsernameRecord>>>()
Expand Down
24 changes: 3 additions & 21 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
use aide::openapi::{self, OpenApi};
use anyhow::Result;
use axum::Extension;
use std::{env, net::SocketAddr, time::Duration};
use std::{env, net::SocketAddr};
use tokio::{net::TcpListener, signal};
use tower_http::{
timeout::TimeoutLayer,
trace::{DefaultMakeSpan, TraceLayer},
};

use crate::{config::Config, routes};

#[must_use]
pub fn get_timeout_layer(timeout: Option<u64>) -> TimeoutLayer {
let timeout = timeout.map_or(Duration::from_secs(20), Duration::from_secs);
TimeoutLayer::new(timeout)
}

pub async fn start(mut config: Config) -> Result<()> {
let mut openapi = OpenApi {
info: openapi::Info {
Expand All @@ -31,21 +21,15 @@ pub async fn start(mut config: Config) -> Result<()> {
.layer(Extension(openapi))
.layer(config.db_extension())
.layer(config.blocklist_extension())
.layer(config.extension())
.layer(
TraceLayer::new_for_http().make_span_with(DefaultMakeSpan::new().include_headers(true)),
)
.layer(get_timeout_layer(None));

tracing::info!("✅ preflight done. all services initialized...");
.layer(config.extension());

let addr = SocketAddr::from((
[0, 0, 0, 0],
env::var("PORT").map_or(Ok(8000), |p| p.parse())?,
));
let listener = TcpListener::bind(&addr).await?;

tracing::info!("🚀 started server on {addr}...");
tracing::info!("Starting server on {addr}...");

axum::serve(listener, router.into_make_service())
.with_graceful_shutdown(shutdown_signal())
Expand All @@ -59,7 +43,6 @@ async fn shutdown_signal() {
signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
tracing::warn!("⚠️ received termination signal...");
};

#[cfg(unix)]
Expand All @@ -68,7 +51,6 @@ async fn shutdown_signal() {
.expect("failed to install signal handler")
.recv()
.await;
tracing::warn!("⚠️ received termination signal...");
};

#[cfg(not(unix))]
Expand Down
1 change: 0 additions & 1 deletion src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct VerificationRequest {
/// # Errors
///
/// Errors if the proof is invalid (`Error::Verification`), or if there's an error validating the proof.
#[tracing::instrument(skip(proof, signal, developer_portal_url))]
pub async fn dev_portal_verify_proof<V: alloy::sol_types::SolValue + Send>(
proof: Proof,
app_id: String,
Expand Down

0 comments on commit ae70b24

Please sign in to comment.