From ad25766058016672cac328558c35fe0f4ef285be Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 3 Jul 2022 16:38:48 +0200 Subject: [PATCH] Add tracing Signed-off-by: trivernis --- Cargo.lock | 27 ++++++++++++++++++++------- Cargo.toml | 3 ++- src/client.rs | 23 ++++++++++++++++++++--- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ed910a8..b65d73d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,6 +10,7 @@ dependencies = [ "serde", "thiserror", "tokio", + "tracing", ] [[package]] @@ -376,9 +377,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.7.2" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" [[package]] name = "openssl" @@ -774,22 +775,34 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.26" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" +checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ "cfg-if", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" -version = "0.1.18" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" +checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6a79a4a..335a63f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "animethemes-rs" -version = "0.4.0" +version = "0.4.1" authors = ["trivernis "] edition = "2021" readme = "README.md" @@ -12,6 +12,7 @@ description = "A Rust wrapper for the AnimeThemes api" [dependencies] thiserror = "1.0.31" +tracing = "0.1.35" [dependencies.reqwest] version = "0.11.11" diff --git a/src/client.rs b/src/client.rs index 204fd85..2c52674 100644 --- a/src/client.rs +++ b/src/client.rs @@ -8,7 +8,7 @@ use reqwest::Response; use serde::de::DeserializeOwned; use serde::Serialize; use std::collections::HashMap; -use std::fmt::Display; +use std::fmt::{Debug, Display}; pub static DEFAULT_API_ENDPOINT: &str = "https://staging.animethemes.moe/api"; pub static DEFAULT_VIDEO_ENDPOINT: &str = "https://animethemes.moe/video/"; @@ -58,6 +58,7 @@ impl AnimeThemesClient { /// assert!(response.songs.is_some()); /// # Ok(()) } /// ``` + #[tracing::instrument(level = "debug", skip(self))] pub async fn search( &self, query: &str, @@ -77,67 +78,78 @@ impl AnimeThemesClient { } /// Returns an anime by a given slug string + #[tracing::instrument(level = "debug", skip(self))] pub async fn anime(&self, slug: &str, include: AnimeInclude) -> ApiResult { self.entry_by_id_with_include("anime", slug, include.includes()) .await } /// Returns an artist by a given slug string + #[tracing::instrument(level = "debug", skip(self))] pub async fn artist(&self, slug: &str, include: ArtistInclude) -> ApiResult { self.entry_by_id_with_include("artist", slug, include.includes()) .await } /// Returns an entry by a given id + #[tracing::instrument(level = "debug", skip(self))] pub async fn entry(&self, id: u32, include: ThemeEntryInclude) -> ApiResult { self.entry_by_id_with_include("animethemeentry", id, include.includes()) .await } /// Returns an image by id + #[tracing::instrument(level = "debug", skip(self))] pub async fn image(&self, id: u32, include: ImageInclude) -> ApiResult { self.entry_by_id_with_include("image", id, include.includes()) .await } /// Returns a resource by id + #[tracing::instrument(level = "debug", skip(self))] pub async fn resource(&self, id: u32, include: ResourceInclude) -> ApiResult { self.entry_by_id_with_include("resource", id, include.includes()) .await } /// Returns a series by slug + #[tracing::instrument(level = "debug", skip(self))] pub async fn series(&self, slug: &str, include: SeriesInclude) -> ApiResult { self.entry_by_id_with_include("series", slug, include.includes()) .await } /// Returns a song by id + #[tracing::instrument(level = "debug", skip(self))] pub async fn song(&self, id: u32, include: SongInclude) -> ApiResult { self.entry_by_id_with_include("song", id, include.includes()) .await } /// Returns a synonym by id + #[tracing::instrument(level = "debug", skip(self))] pub async fn synonym(&self, id: u32, include: SynonymInclude) -> ApiResult { self.entry_by_id_with_include("animesynonym", id, include.includes()) .await } /// Returns a theme by id + #[tracing::instrument(level = "debug", skip(self))] pub async fn theme(&self, id: u32, include: ThemeInclude) -> ApiResult { self.entry_by_id_with_include("animetheme", id, include.includes()) .await } /// Returns a video by basename + #[tracing::instrument(level = "debug", skip(self))] pub async fn video(&self, basename: &str, include: VideoInclude) -> ApiResult