More instrument

dess/opentelemetry
Aode (lion) 2021-12-07 17:11:05 -06:00
parent ea41e5531c
commit 4d1e9c640b
4 changed files with 32 additions and 2 deletions

View File

@ -45,6 +45,7 @@ where
res res
} }
#[tracing::instrument(skip_all)]
pub async fn is_mod_or_admin( pub async fn is_mod_or_admin(
pool: &DbPool, pool: &DbPool,
person_id: PersonId, person_id: PersonId,
@ -67,6 +68,7 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> { pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
blocking(pool, move |conn| Post::read(conn, post_id)) blocking(pool, move |conn| Post::read(conn, post_id))
.await? .await?
@ -74,6 +76,7 @@ pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError
.map_err(|e| e.with_message("couldnt_find_post")) .map_err(|e| e.with_message("couldnt_find_post"))
} }
#[tracing::instrument(skip_all)]
pub async fn mark_post_as_read( pub async fn mark_post_as_read(
person_id: PersonId, person_id: PersonId,
post_id: PostId, post_id: PostId,
@ -89,6 +92,7 @@ pub async fn mark_post_as_read(
.map_err(|e| e.with_message("couldnt_mark_post_as_read")) .map_err(|e| e.with_message("couldnt_mark_post_as_read"))
} }
#[tracing::instrument(skip_all)]
pub async fn mark_post_as_unread( pub async fn mark_post_as_unread(
person_id: PersonId, person_id: PersonId,
post_id: PostId, post_id: PostId,
@ -104,6 +108,7 @@ pub async fn mark_post_as_unread(
.map_err(|e| e.with_message("couldnt_mark_post_as_read")) .map_err(|e| e.with_message("couldnt_mark_post_as_read"))
} }
#[tracing::instrument(skip_all)]
pub async fn get_local_user_view_from_jwt( pub async fn get_local_user_view_from_jwt(
jwt: &str, jwt: &str,
pool: &DbPool, pool: &DbPool,
@ -144,6 +149,7 @@ pub fn check_validator_time(
} }
} }
#[tracing::instrument(skip_all)]
pub async fn get_local_user_view_from_jwt_opt( pub async fn get_local_user_view_from_jwt_opt(
jwt: Option<&Sensitive<String>>, jwt: Option<&Sensitive<String>>,
pool: &DbPool, pool: &DbPool,
@ -155,6 +161,7 @@ pub async fn get_local_user_view_from_jwt_opt(
} }
} }
#[tracing::instrument(skip_all)]
pub async fn get_local_user_settings_view_from_jwt( pub async fn get_local_user_settings_view_from_jwt(
jwt: &Sensitive<String>, jwt: &Sensitive<String>,
pool: &DbPool, pool: &DbPool,
@ -179,6 +186,7 @@ pub async fn get_local_user_settings_view_from_jwt(
Ok(local_user_view) Ok(local_user_view)
} }
#[tracing::instrument(skip_all)]
pub async fn get_local_user_settings_view_from_jwt_opt( pub async fn get_local_user_settings_view_from_jwt_opt(
jwt: Option<&Sensitive<String>>, jwt: Option<&Sensitive<String>>,
pool: &DbPool, pool: &DbPool,
@ -192,6 +200,7 @@ pub async fn get_local_user_settings_view_from_jwt_opt(
} }
} }
#[tracing::instrument(skip_all)]
pub async fn check_community_ban( pub async fn check_community_ban(
person_id: PersonId, person_id: PersonId,
community_id: CommunityId, community_id: CommunityId,
@ -206,6 +215,7 @@ pub async fn check_community_ban(
} }
} }
#[tracing::instrument(skip_all)]
pub async fn check_community_deleted_or_removed( pub async fn check_community_deleted_or_removed(
community_id: CommunityId, community_id: CommunityId,
pool: &DbPool, pool: &DbPool,
@ -229,6 +239,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
} }
} }
#[tracing::instrument(skip_all)]
pub async fn check_person_block( pub async fn check_person_block(
my_id: PersonId, my_id: PersonId,
potential_blocker_id: PersonId, potential_blocker_id: PersonId,
@ -242,6 +253,7 @@ pub async fn check_person_block(
} }
} }
#[tracing::instrument(skip_all)]
pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), LemmyError> { pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), LemmyError> {
if score == -1 { if score == -1 {
let site = blocking(pool, Site::read_simple).await??; let site = blocking(pool, Site::read_simple).await??;
@ -252,6 +264,7 @@ pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), Le
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
pub async fn build_federated_instances( pub async fn build_federated_instances(
pool: &DbPool, pool: &DbPool,
federation_config: &FederationConfig, federation_config: &FederationConfig,

View File

@ -31,7 +31,7 @@ use lemmy_utils::{
LemmyError, LemmyError,
}; };
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use tracing::warn; use tracing::{warn, Instrument};
use url::Url; use url::Url;
use webmention::{Webmention, WebmentionError}; use webmention::{Webmention, WebmentionError};
@ -132,7 +132,11 @@ impl PerformCrud for CreatePost {
let mut webmention = let mut webmention =
Webmention::new::<Url>(updated_post.ap_id.clone().into(), url.clone().into())?; Webmention::new::<Url>(updated_post.ap_id.clone().into(), url.clone().into())?;
webmention.set_checked(true); webmention.set_checked(true);
match webmention.send().await { match webmention
.send()
.instrument(tracing::info_span!("Sending webmention"))
.await
{
Ok(_) => {} Ok(_) => {}
Err(WebmentionError::NoEndpointDiscovered(_)) => {} Err(WebmentionError::NoEndpointDiscovered(_)) => {}
Err(e) => warn!("Failed to send webmention: {}", e), Err(e) => warn!("Failed to send webmention: {}", e),

View File

@ -17,6 +17,7 @@ struct SendError(pub String);
#[error("Error receiving response, {0}")] #[error("Error receiving response, {0}")]
pub struct RecvError(pub String); pub struct RecvError(pub String);
#[tracing::instrument(skip_all)]
pub async fn retry<F, Fut, T>(f: F) -> Result<T, reqwest_middleware::Error> pub async fn retry<F, Fut, T>(f: F) -> Result<T, reqwest_middleware::Error>
where where
F: Fn() -> Fut, F: Fn() -> Fut,
@ -25,6 +26,7 @@ where
retry_custom(|| async { Ok((f)().await) }).await retry_custom(|| async { Ok((f)().await) }).await
} }
#[tracing::instrument(skip_all)]
async fn retry_custom<F, Fut, T>(f: F) -> Result<T, reqwest_middleware::Error> async fn retry_custom<F, Fut, T>(f: F) -> Result<T, reqwest_middleware::Error>
where where
F: Fn() -> Fut, F: Fn() -> Fut,
@ -60,6 +62,7 @@ pub struct SiteMetadata {
} }
/// Fetches the post link html tags (like title, description, image, etc) /// Fetches the post link html tags (like title, description, image, etc)
#[tracing::instrument(skip_all)]
pub async fn fetch_site_metadata( pub async fn fetch_site_metadata(
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
url: &Url, url: &Url,
@ -124,6 +127,7 @@ pub(crate) struct PictrsFile {
delete_token: String, delete_token: String,
} }
#[tracing::instrument(skip_all)]
pub(crate) async fn fetch_pictrs( pub(crate) async fn fetch_pictrs(
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
settings: &Settings, settings: &Settings,
@ -157,6 +161,7 @@ pub(crate) async fn fetch_pictrs(
/// Both are options, since the URL might be either an html page, or an image /// Both are options, since the URL might be either an html page, or an image
/// Returns the SiteMetadata, and a Pictrs URL, if there is a picture associated /// Returns the SiteMetadata, and a Pictrs URL, if there is a picture associated
#[tracing::instrument(skip_all)]
pub async fn fetch_site_data( pub async fn fetch_site_data(
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
settings: &Settings, settings: &Settings,
@ -207,6 +212,7 @@ pub async fn fetch_site_data(
} }
} }
#[tracing::instrument(skip_all)]
async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> { async fn is_image_content_type(client: &ClientWithMiddleware, url: &Url) -> Result<(), LemmyError> {
let response = client.get(url.as_str()).send().await?; let response = client.get(url.as_str()).send().await?;
if response if response

View File

@ -37,6 +37,7 @@ use lemmy_utils::{
}; };
use tracing::error; use tracing::error;
#[tracing::instrument(skip_all)]
pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>( pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>(
post_id: PostId, post_id: PostId,
op: OP, op: OP,
@ -62,6 +63,7 @@ pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>
// TODO: in many call sites in apub crate, we are setting an empty vec for recipient_ids, // TODO: in many call sites in apub crate, we are setting an empty vec for recipient_ids,
// we should get the actual recipient actors from somewhere // we should get the actual recipient actors from somewhere
#[tracing::instrument(skip_all)]
pub async fn send_comment_ws_message_simple<OP: ToString + Send + OperationType + 'static>( pub async fn send_comment_ws_message_simple<OP: ToString + Send + OperationType + 'static>(
comment_id: CommentId, comment_id: CommentId,
op: OP, op: OP,
@ -70,6 +72,7 @@ pub async fn send_comment_ws_message_simple<OP: ToString + Send + OperationType
send_comment_ws_message(comment_id, op, None, None, None, vec![], context).await send_comment_ws_message(comment_id, op, None, None, None, vec![], context).await
} }
#[tracing::instrument(skip_all)]
pub async fn send_comment_ws_message<OP: ToString + Send + OperationType + 'static>( pub async fn send_comment_ws_message<OP: ToString + Send + OperationType + 'static>(
comment_id: CommentId, comment_id: CommentId,
op: OP, op: OP,
@ -108,6 +111,7 @@ pub async fn send_comment_ws_message<OP: ToString + Send + OperationType + 'stat
Ok(res) Ok(res)
} }
#[tracing::instrument(skip_all)]
pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'static>( pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'static>(
community_id: CommunityId, community_id: CommunityId,
op: OP, op: OP,
@ -136,6 +140,7 @@ pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'st
Ok(res) Ok(res)
} }
#[tracing::instrument(skip_all)]
pub async fn send_pm_ws_message<OP: ToString + Send + OperationType + 'static>( pub async fn send_pm_ws_message<OP: ToString + Send + OperationType + 'static>(
private_message_id: PrivateMessageId, private_message_id: PrivateMessageId,
op: OP, op: OP,
@ -174,6 +179,7 @@ pub async fn send_pm_ws_message<OP: ToString + Send + OperationType + 'static>(
Ok(res) Ok(res)
} }
#[tracing::instrument(skip_all)]
pub async fn send_local_notifs( pub async fn send_local_notifs(
mentions: Vec<MentionData>, mentions: Vec<MentionData>,
comment: &Comment, comment: &Comment,
@ -297,6 +303,7 @@ pub async fn send_local_notifs(
Ok(recipient_ids) Ok(recipient_ids)
} }
#[tracing::instrument(skip_all)]
pub fn send_email_to_user( pub fn send_email_to_user(
local_user_view: &LocalUserView, local_user_view: &LocalUserView,
subject_text: &str, subject_text: &str,