diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs --- a/services/identity/src/client_service.rs +++ b/services/identity/src/client_service.rs @@ -13,7 +13,10 @@ // Workspace crate imports use crate::config::CONFIG; -use crate::constants::request_metadata; +use crate::constants::{ + request_metadata, + GENERIC_DB_LOG_ERROR_TYPE, +}; use crate::database::{ DBDeviceTypeInt, DatabaseClient, DeviceType, KeyPayload, }; @@ -1099,7 +1102,10 @@ tonic::Status::invalid_argument("invalid device list update") } e => { - error!("Encountered an unexpected error: {}", e); + error!( + errorType = GENERIC_DB_LOG_ERROR_TYPE, + "Encountered an unexpected error: {}", e + ); tonic::Status::failed_precondition("unexpected error") } } diff --git a/services/identity/src/constants.rs b/services/identity/src/constants.rs --- a/services/identity/src/constants.rs +++ b/services/identity/src/constants.rs @@ -191,6 +191,20 @@ pub const IDENTITY_SEARCH_INDEX: &str = "users"; pub const IDENTITY_SEARCH_RESULT_SIZE: u32 = 20; +// Log Error Types + +pub const GENERIC_DB_LOG_ERROR_TYPE: &str = "DB Error"; +pub const OTK_DB_LOG_ERROR_TYPE: &str = "One-time Key DB Error"; +pub const DEVICE_LIST_DB_LOG_ERROR_TYPE: &str = "Device List DB Error"; +pub const TOKEN_DB_LOG_ERROR_TYPE: &str = "Token DB Error"; +pub const FARCASTER_DB_LOG_ERROR_TYPE: &str = "Farcaster DB Error"; + +pub const SYNC_LOG_ERROR_TYPE: &str = "Sync Error"; +pub const SEARCH_LOG_ERROR_TYPE: &str = "Search Error"; +pub const SIWE_LOG_ERROR_TYPE: &str = "SIWE Error"; +pub const GRPC_SERVICES_LOG_ERROR_TYPE: &str = "gRPC Services Error"; +pub const TUNNELBROKER_LOG_ERROR_TYPE: &str = "Tunnelbroker Error"; + // Tunnelbroker pub const TUNNELBROKER_GRPC_ENDPOINT: &str = "TUNNELBROKER_GRPC_ENDPOINT"; pub const DEFAULT_TUNNELBROKER_ENDPOINT: &str = "http://localhost:50051"; diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs --- a/services/identity/src/database.rs +++ b/services/identity/src/database.rs @@ -18,6 +18,7 @@ pub use crate::database::device_list::DeviceIDAttribute; pub use crate::database::one_time_keys::OTKRow; use crate::{ + constants::GENERIC_DB_LOG_ERROR_TYPE, constants::USERS_TABLE_SOCIAL_PROOF_ATTRIBUTE_NAME, ddb_utils::EthereumIdentity, reserved_users::UserDetail, siwe::SocialProof, }; @@ -474,7 +475,10 @@ Ok(out) } Err(e) => { - error!("DynamoDB client failed to delete user {}", user_id); + error!( + errorType = GENERIC_DB_LOG_ERROR_TYPE, + "DynamoDB client failed to delete user {}", user_id + ); Err(Error::AwsSdk(e.into())) } } @@ -582,8 +586,11 @@ } Err(e) => { error!( + errorType = GENERIC_DB_LOG_ERROR_TYPE, "DynamoDB client failed to get user from {} {}: {}", - attribute_name, user_info, e + attribute_name, + user_info, + e ); Err(Error::AwsSdk(e.into())) } @@ -670,8 +677,10 @@ } Err(e) => { error!( + errorType = GENERIC_DB_LOG_ERROR_TYPE, "DynamoDB client failed to get registration data for user {}: {}", - username, e + username, + e ); Err(e) } @@ -726,7 +735,11 @@ .map(Identifier::try_from) .transpose() .map_err(|e| { - error!(user_id, "Database item is missing an identifier"); + error!( + user_id, + errorType = GENERIC_DB_LOG_ERROR_TYPE, + "Database item is missing an identifier" + ); e }) } @@ -961,7 +974,7 @@ Ok(out) } Err(e) => { - error!("DynamoDB client failed to delete username {} from reserved usernames table", username); + error!(errorType=GENERIC_DB_LOG_ERROR_TYPE, "DynamoDB client failed to delete username {} from reserved usernames table", username); Err(Error::AwsSdk(e.into())) } } @@ -1041,7 +1054,7 @@ attribute = attribute_name, value = ?attribute_value, error_type = "IncorrectType", - "Unexpected attribute type when parsing map attribute" + errorType=GENERIC_DB_LOG_ERROR_TYPE, "Unexpected attribute type when parsing map attribute" ); Err(DBItemError::new( attribute_name.to_string(), @@ -1053,6 +1066,7 @@ error!( attribute = attribute_name, error_type = "Missing", + errorType = GENERIC_DB_LOG_ERROR_TYPE, "Attribute is missing" ); Err(DBItemError::new( diff --git a/services/identity/src/database/device_list.rs b/services/identity/src/database/device_list.rs --- a/services/identity/src/database/device_list.rs +++ b/services/identity/src/database/device_list.rs @@ -20,8 +20,8 @@ client_service::FlattenedDeviceKeyUpload, constants::{ devices_table::{self, *}, - USERS_TABLE, USERS_TABLE_DEVICELIST_TIMESTAMP_ATTRIBUTE_NAME, - USERS_TABLE_PARTITION_KEY, + DEVICE_LIST_DB_LOG_ERROR_TYPE, USERS_TABLE, + USERS_TABLE_DEVICELIST_TIMESTAMP_ATTRIBUTE_NAME, USERS_TABLE_PARTITION_KEY, }, error::{DeviceListError, Error}, grpc_services::protos::{self, unauth::DeviceType}, @@ -86,7 +86,10 @@ if !is_valid_olm_key(&upload.content_prekey) || !is_valid_olm_key(&upload.notif_prekey) { - error!("Invalid prekey format"); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Invalid prekey format" + ); return Err(Error::InvalidFormat); } let device_row = Self { @@ -429,7 +432,10 @@ .send() .await .map_err(|e| { - error!("Failed to get current devices: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to get current devices: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -473,7 +479,10 @@ .send() .await .map_err(|e| { - error!("Failed to query device list updates by index: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to query device list updates by index: {:?}", e + ); Error::AwsSdk(e.into()) })? .items @@ -483,7 +492,10 @@ .send() .await .map_err(|e| { - error!("Failed to query device list updates (all): {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to query device list updates (all): {:?}", e + ); Error::AwsSdk(e.into()) })? .items @@ -523,7 +535,10 @@ if !is_valid_olm_key(&content_prekey.prekey) || !is_valid_olm_key(¬if_prekey.prekey) { - error!("Invalid prekey format"); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Invalid prekey format" + ); return Err(Error::InvalidFormat); } self @@ -547,7 +562,10 @@ .send() .await .map_err(|e| { - error!("Failed to update device prekeys: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to update device prekeys: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -572,7 +590,10 @@ .send() .await .map_err(|e| { - error!("Failed to check if device exists: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to check if device exists: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -594,7 +615,10 @@ .send() .await .map_err(|e| { - error!("Failed to fetch device data: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to fetch device data: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -617,7 +641,11 @@ .as_ref() .and_then(|list| list.device_ids.first()) else { - error!(user_id, "Device list is empty. Cannot fetch primary device"); + error!( + user_id, + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Device list is empty. Cannot fetch primary device" + ); return Err(Error::DeviceList(DeviceListError::DeviceNotFound)); }; @@ -626,8 +654,8 @@ .await? .ok_or_else(|| { error!( - "Corrupt database. Missing primary device data for user {}", - user_id + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Corrupt database. Missing primary device data for user {}", user_id ); Error::MissingItem }) @@ -661,7 +689,10 @@ .send() .await .map_err(|e| { - error!("Failed to update device login time: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to update device login time: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -691,7 +722,10 @@ .send() .await .map_err(|e| { - error!("Failed to query device list updates by index: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to query device list updates by index: {:?}", e + ); Error::AwsSdk(e.into()) })? .items @@ -731,7 +765,10 @@ .send() .await .map_err(|e| { - error!("Failed to put device data: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to put device data: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -977,7 +1014,10 @@ Error::DeviceList(DeviceListError::ConcurrentUpdateError) } other => { - error!("Device list update transaction failed: {:?}", other); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Device list update transaction failed: {:?}", other + ); Error::AwsSdk(other) } })?; @@ -1011,7 +1051,10 @@ .send() .await .map_err(|e| { - error!("Failed to list user's items in devices table: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to list user's items in devices table: {:?}", e + ); Error::AwsSdk(e.into()) })? .items @@ -1034,7 +1077,10 @@ .send() .await .map_err(|e| { - error!("Failed to batch delete items from devices table: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to batch delete items from devices table: {:?}", e + ); Error::AwsSdk(e.into()) })?; } @@ -1061,7 +1107,10 @@ .send() .await .map_err(|e| { - error!("Failed to get user's device list timestamp: {:?}", e); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Failed to get user's device list timestamp: {:?}", e + ); Error::AwsSdk(e.into()) })?; @@ -1157,7 +1206,10 @@ devices_data: &[DeviceRow], ) { if !verify_device_list_match(list, devices_data) { - error!("Found corrupt device list for user (userID={})!", user_id); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Found corrupt device list for user (userID={})!", user_id + ); return; } @@ -1184,8 +1236,8 @@ list.iter().position(|id| id == &primary_device.device_id) else { error!( - "Primary device not found in device list (userID={})", - user_id + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Primary device not found in device list (userID={})", user_id ); return; }; @@ -1200,7 +1252,10 @@ devices_data: &[DeviceRow], ) -> bool { if list.len() != devices_data.len() { - error!("Device list length mismatch!"); + error!( + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Device list length mismatch!" + ); return false; } @@ -1216,8 +1271,8 @@ .next() { error!( - "Device list is corrupt (unknown deviceID={})", - corrupt_device_id + errorType = DEVICE_LIST_DB_LOG_ERROR_TYPE, + "Device list is corrupt (unknown deviceID={})", corrupt_device_id ); return false; } diff --git a/services/identity/src/database/farcaster.rs b/services/identity/src/database/farcaster.rs --- a/services/identity/src/database/farcaster.rs +++ b/services/identity/src/database/farcaster.rs @@ -7,6 +7,7 @@ use comm_lib::database::Value; use tracing::error; +use crate::constants::FARCASTER_DB_LOG_ERROR_TYPE; use crate::constants::USERS_TABLE; use crate::constants::USERS_TABLE_FARCASTER_ID_ATTRIBUTE_NAME; use crate::constants::USERS_TABLE_FARCASTER_ID_INDEX; @@ -42,7 +43,10 @@ .send() .await .map_err(|e| { - error!("Failed to query users by farcasterID: {:?}", e); + error!( + errorType = FARCASTER_DB_LOG_ERROR_TYPE, + "Failed to query users by farcasterID: {:?}", e + ); Error::AwsSdk(e.into()) })? .items diff --git a/services/identity/src/database/one_time_keys.rs b/services/identity/src/database/one_time_keys.rs --- a/services/identity/src/database/one_time_keys.rs +++ b/services/identity/src/database/one_time_keys.rs @@ -17,7 +17,10 @@ use tracing::{debug, error, info}; use crate::{ - constants::{MAX_ONE_TIME_KEYS, ONE_TIME_KEY_UPLOAD_LIMIT_PER_ACCOUNT}, + constants::{ + MAX_ONE_TIME_KEYS, ONE_TIME_KEY_UPLOAD_LIMIT_PER_ACCOUNT, + OTK_DB_LOG_ERROR_TYPE, + }, database::DeviceIDAttribute, ddb_utils::{ create_one_time_key_partition_key, into_one_time_put_requests, @@ -145,6 +148,7 @@ info!("Encountered transaction conflict while retrieving one-time key - retrying"); } else { error!( + errorType = OTK_DB_LOG_ERROR_TYPE, "One-time key retrieval transaction failed: {:?}", dynamo_db_error ); @@ -197,7 +201,10 @@ if let Some(limit) = num_keys { if otk_rows.len() != limit { - error!("There are fewer one-time keys than the number requested"); + error!( + errorType = OTK_DB_LOG_ERROR_TYPE, + "There are fewer one-time keys than the number requested" + ); return Err(Error::NotEnoughOneTimeKeys); } } @@ -325,8 +332,8 @@ info!("Encountered transaction conflict while uploading one-time keys - retrying"); } else { error!( - "One-time key upload transaction failed: {:?}", - dynamo_db_error + errorType = OTK_DB_LOG_ERROR_TYPE, + "One-time key upload transaction failed: {:?}", dynamo_db_error ); return Err(Error::AwsSdk(dynamo_db_error)); } @@ -367,7 +374,10 @@ .send() .await .map_err(|e| { - error!("Failed to get user's OTK count: {:?}", e); + error!( + errorType = OTK_DB_LOG_ERROR_TYPE, + "Failed to get user's OTK count: {:?}", e + ); Error::AwsSdk(e.into()) })?; diff --git a/services/identity/src/database/token.rs b/services/identity/src/database/token.rs --- a/services/identity/src/database/token.rs +++ b/services/identity/src/database/token.rs @@ -15,6 +15,7 @@ use tracing::{error, info}; use crate::{ + constants::TOKEN_DB_LOG_ERROR_TYPE, error::Error, token::{AccessTokenData, AuthType}, }; @@ -72,7 +73,7 @@ } Err(e) => { error!( - "DynamoDB client failed to get token for user {} with signing public key {}: {}", + errorType=TOKEN_DB_LOG_ERROR_TYPE, "DynamoDB client failed to get token for user {} with signing public key {}: {}", user_id, signing_public_key, e ); Err(Error::AwsSdk(e.into())) @@ -187,7 +188,10 @@ .send() .await .map_err(|e| { - error!("Failed to list user's items in tokens table: {:?}", e); + error!( + errorType = TOKEN_DB_LOG_ERROR_TYPE, + "Failed to list user's items in tokens table: {:?}", e + ); Error::AwsSdk(e.into()) })? .items diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs --- a/services/identity/src/grpc_services/authenticated.rs +++ b/services/identity/src/grpc_services/authenticated.rs @@ -4,7 +4,7 @@ use crate::database::{DeviceListRow, DeviceListUpdate}; use crate::{ client_service::{handle_db_error, UpdateState, WorkflowInProgress}, - constants::request_metadata, + constants::{request_metadata, GRPC_SERVICES_LOG_ERROR_TYPE}, database::DatabaseClient, ddb_utils::DateTimeExt, grpc_services::shared::get_value, @@ -504,13 +504,20 @@ warn!(user_id, "User has no device list, skipping!"); } Ok((user_id, Err(err))) => { - error!(user_id, "Failed fetching device list: {err}"); + error!( + user_id, + errorType = GRPC_SERVICES_LOG_ERROR_TYPE, + "Failed fetching device list: {err}" + ); // abort fetching other users fetch_tasks.abort_all(); return Err(handle_db_error(err)); } Err(join_error) => { - error!("Failed to join device list task: {join_error}"); + error!( + errorType = GRPC_SERVICES_LOG_ERROR_TYPE, + "Failed to join device list task: {join_error}" + ); fetch_tasks.abort_all(); return Err(Status::aborted("unexpected error")); } @@ -562,7 +569,10 @@ .map_err(handle_db_error)?; if get_farcaster_users_response.len() > 1 { - error!("multiple users associated with the same Farcaster ID"); + error!( + errorType = GRPC_SERVICES_LOG_ERROR_TYPE, + "multiple users associated with the same Farcaster ID" + ); return Err(Status::failed_precondition("cannot link Farcaster ID")); } @@ -661,7 +671,10 @@ /// Serialize (and sign in the future) a [`RawDeviceList`] fn try_from_raw(raw: RawDeviceList) -> Result { let stringified_list = serde_json::to_string(&raw).map_err(|err| { - error!("Failed to serialize raw device list: {}", err); + error!( + errorType = GRPC_SERVICES_LOG_ERROR_TYPE, + "Failed to serialize raw device list: {}", err + ); tonic::Status::failed_precondition("unexpected error") })?; @@ -685,7 +698,10 @@ /// Serializes the signed device list to a JSON string fn as_json_string(&self) -> Result { serde_json::to_string(self).map_err(|err| { - error!("Failed to serialize device list updates: {}", err); + error!( + errorType = GRPC_SERVICES_LOG_ERROR_TYPE, + "Failed to serialize device list updates: {}", err + ); tonic::Status::failed_precondition("unexpected error") }) } @@ -710,7 +726,10 @@ } = signed_list.as_raw()?; let timestamp = DateTime::::from_utc_timestamp_millis(raw_timestamp) .ok_or_else(|| { - error!("Failed to parse RawDeviceList timestamp!"); + error!( + errorType = GRPC_SERVICES_LOG_ERROR_TYPE, + "Failed to parse RawDeviceList timestamp!" + ); tonic::Status::invalid_argument("invalid timestamp") })?; Ok(DeviceListUpdate::new(devices, timestamp)) diff --git a/services/identity/src/siwe.rs b/services/identity/src/siwe.rs --- a/services/identity/src/siwe.rs +++ b/services/identity/src/siwe.rs @@ -11,7 +11,8 @@ use tracing::error; use crate::constants::{ - SOCIAL_PROOF_MESSAGE_ATTRIBUTE, SOCIAL_PROOF_SIGNATURE_ATTRIBUTE, + SIWE_LOG_ERROR_TYPE, SOCIAL_PROOF_MESSAGE_ATTRIBUTE, + SOCIAL_PROOF_SIGNATURE_ATTRIBUTE, }; pub fn parse_and_verify_siwe_message( @@ -19,25 +20,37 @@ siwe_signature: &str, ) -> Result { let siwe_message: Message = siwe_message.parse().map_err(|e| { - error!("Failed to parse SIWE message: {}", e); + error!( + errorType = SIWE_LOG_ERROR_TYPE, + "Failed to parse SIWE message: {}", e + ); Status::invalid_argument("invalid message") })?; let decoded_signature = hex::decode(siwe_signature.trim_start_matches("0x")) .map_err(|e| { - error!("Failed to decode SIWE signature: {}", e); + error!( + errorType = SIWE_LOG_ERROR_TYPE, + "Failed to decode SIWE signature: {}", e + ); Status::invalid_argument("invalid signature") })?; let signature = decoded_signature.try_into().map_err(|e| { - error!("Conversion to SIWE signature failed: {:?}", e); + error!( + errorType = SIWE_LOG_ERROR_TYPE, + "Conversion to SIWE signature failed: {:?}", e + ); Status::invalid_argument("invalid message") })?; siwe_message .verify(signature, None, None, Some(&Utc::now())) .map_err(|e| { - error!("Signature verification failed: {}", e); + error!( + errorType = SIWE_LOG_ERROR_TYPE, + "Signature verification failed: {}", e + ); Status::unauthenticated("message not authenticated") })?; diff --git a/services/identity/src/sync_identity_search.rs b/services/identity/src/sync_identity_search.rs --- a/services/identity/src/sync_identity_search.rs +++ b/services/identity/src/sync_identity_search.rs @@ -1,5 +1,5 @@ use crate::config::CONFIG; -use crate::constants::IDENTITY_SEARCH_INDEX; +use crate::constants::{IDENTITY_SEARCH_INDEX, SYNC_LOG_ERROR_TYPE}; use crate::database::DatabaseClient; use crate::error; use identity_search_messages::IdentitySearchUser; @@ -60,7 +60,7 @@ .expect("Failed to send clear index request"); if !response.status().is_success() { - error!("Sync Error: Failed to clear index"); + error!(errorType = SYNC_LOG_ERROR_TYPE, "Failed to clear index"); } Ok(()) @@ -98,7 +98,7 @@ .expect("Failed to send restore index request"); if !response.status().is_success() { - error!("Sync Error: Failed to restore index"); + error!(errorType = SYNC_LOG_ERROR_TYPE, "Failed to restore index"); } Ok(()) diff --git a/services/identity/src/tunnelbroker.rs b/services/identity/src/tunnelbroker.rs --- a/services/identity/src/tunnelbroker.rs +++ b/services/identity/src/tunnelbroker.rs @@ -9,6 +9,7 @@ use tracing::error; use tunnelbroker_messages as messages; +use crate::constants::TUNNELBROKER_LOG_ERROR_TYPE; use crate::error::Error; pub async fn create_tunnelbroker_client( @@ -16,7 +17,10 @@ shared_tb_client(&CONFIG.tunnelbroker_endpoint) .await .map_err(|e| { - error!("Unable able to connect to tunnelbroker: {:?}", e); + error!( + errorType = TUNNELBROKER_LOG_ERROR_TYPE, + "Unable able to connect to tunnelbroker: {:?}", e + ); Error::Status(Status::invalid_argument(format!("{}", e))) }) } diff --git a/services/identity/src/websockets/auth.rs b/services/identity/src/websockets/auth.rs --- a/services/identity/src/websockets/auth.rs +++ b/services/identity/src/websockets/auth.rs @@ -6,7 +6,7 @@ use identity_search_messages::IdentitySearchAuthMessage; use tracing::{debug, error}; -use crate::constants::DEFAULT_IDENTITY_ENDPOINT; +use crate::constants::{DEFAULT_IDENTITY_ENDPOINT, SEARCH_LOG_ERROR_TYPE}; use crate::websockets::errors::WebsocketError; const PLACEHOLDER_CODE_VERSION: u64 = 0; @@ -28,7 +28,10 @@ let mut grpc_client = match grpc_client { Ok(grpc_client) => grpc_client, Err(e) => { - error!("Failed to get unauthenticated client: {}", e); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Failed to get unauthenticated client: {}", e + ); return Err(WebsocketError::AuthError); } }; @@ -43,7 +46,10 @@ let response = match grpc_client.verify_user_access_token(request).await { Ok(response) => response, Err(_) => { - error!("Failed to verify user access token"); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Failed to verify user access token" + ); return Err(WebsocketError::AuthError); } }; @@ -58,7 +64,10 @@ let auth_message: IdentitySearchAuthMessage = match auth_message { Ok(auth_message) => auth_message, Err(_) => { - error!("Failed to parse auth message"); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Failed to parse auth message" + ); return Err(WebsocketError::InvalidMessage); } }; diff --git a/services/identity/src/websockets/errors.rs b/services/identity/src/websockets/errors.rs --- a/services/identity/src/websockets/errors.rs +++ b/services/identity/src/websockets/errors.rs @@ -1,3 +1,5 @@ +use crate::constants::SEARCH_LOG_ERROR_TYPE; + pub type BoxedError = Box; #[derive( @@ -13,14 +15,22 @@ impl From for WebsocketError { fn from(err: serde_json::Error) -> Self { - tracing::error!("Error serializing: {}", err); + tracing::error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Error serializing: {}", + err + ); WebsocketError::SerializationError } } impl From for WebsocketError { fn from(err: reqwest::Error) -> Self { - tracing::error!("Error with search request: {}", err); + tracing::error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Error with search request: {}", + err + ); WebsocketError::SearchError } } diff --git a/services/identity/src/websockets/mod.rs b/services/identity/src/websockets/mod.rs --- a/services/identity/src/websockets/mod.rs +++ b/services/identity/src/websockets/mod.rs @@ -24,7 +24,8 @@ use crate::config::CONFIG; use crate::constants::{ IDENTITY_SEARCH_INDEX, IDENTITY_SEARCH_RESULT_SIZE, - IDENTITY_SERVICE_WEBSOCKET_ADDR, SOCKET_HEARTBEAT_TIMEOUT, + IDENTITY_SERVICE_WEBSOCKET_ADDR, SEARCH_LOG_ERROR_TYPE, + SOCKET_HEARTBEAT_TIMEOUT, }; use opensearch::OpenSearchResponse; use send::{send_message, WebsocketSink}; @@ -113,7 +114,10 @@ tokio::spawn(async move { if let Err(err) = connection.await { - error!("Error serving HTTP/WebSocket connection: {:?}", err); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Error serving HTTP/WebSocket connection: {:?}", err + ); } }); } @@ -139,7 +143,10 @@ #[tracing::instrument(skip_all)] async fn close_connection(outgoing: WebsocketSink) { if let Err(e) = outgoing.lock().await.close().await { - error!("Error closing connection: {}", e); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Error closing connection: {}", e + ); } } @@ -229,7 +236,10 @@ let ws_stream = match hyper_ws.await { Ok(stream) => stream, Err(e) => { - error!("WebSocket handshake error: {}", e); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "WebSocket handshake error: {}", e + ); return; } }; @@ -267,13 +277,19 @@ } } _ => { - error!("Invalid authentication message from {}", addr); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Invalid authentication message from {}", addr + ); close_connection(outgoing).await; return; } } } else { - error!("No authentication message from {}", addr); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "No authentication message from {}", addr + ); close_connection(outgoing).await; return; } @@ -309,19 +325,19 @@ ping_timeout = Box::pin(tokio::time::sleep(SOCKET_HEARTBEAT_TIMEOUT)); if let Err(e) = handle_websocket_frame(text, outgoing.clone()).await { - error!("Error handling WebSocket frame: {}", e); + error!(errorType=SEARCH_LOG_ERROR_TYPE, "Error handling WebSocket frame: {}", e); continue; }; } _ => { - error!("Client sent invalid message type"); + error!(errorType=SEARCH_LOG_ERROR_TYPE, "Client sent invalid message type"); break; } } } _ = &mut ping_timeout => { if !got_heartbeat_response { - error!("Connection to {} died.", addr); + error!(errorType=SEARCH_LOG_ERROR_TYPE, "Connection to {} died.", addr); break; } let serialized = serde_json::to_string(&Heartbeat {}).unwrap(); diff --git a/services/identity/src/websockets/send.rs b/services/identity/src/websockets/send.rs --- a/services/identity/src/websockets/send.rs +++ b/services/identity/src/websockets/send.rs @@ -8,12 +8,17 @@ use hyper_tungstenite::WebSocketStream; use tracing::error; +use crate::constants::SEARCH_LOG_ERROR_TYPE; + pub type WebsocketSink = Arc, Message>>>; #[tracing::instrument(skip_all)] pub async fn send_message(message: Message, outgoing: WebsocketSink) { if let Err(e) = outgoing.lock().await.send(message).await { - error!("Failed to send message to device: {}", e); + error!( + errorType = SEARCH_LOG_ERROR_TYPE, + "Failed to send message to device: {}", e + ); } }