Add tracing

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 2 years ago
parent 9bd9b9fdb0
commit ad25766058
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

27
Cargo.lock generated

@ -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]]

@ -1,6 +1,6 @@
[package]
name = "animethemes-rs"
version = "0.4.0"
version = "0.4.1"
authors = ["trivernis <trivernis@protonmail.com>"]
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"

@ -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<Anime> {
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<Artist> {
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<ThemeEntry> {
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<Image> {
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<Resource> {
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<Series> {
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<Song> {
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<AnimeSynonym> {
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<Theme> {
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<Video> {
self.entry_by_id_with_include("video", basename, include.includes())
.await
}
/// Generic endpoint with the format /<endpoint>/<id> returning the type on the json field <endpoint>
async fn entry_by_id_with_include<T: DeserializeOwned, I: Display>(
#[tracing::instrument(level = "debug", skip(self))]
async fn entry_by_id_with_include<T: DeserializeOwned, I: Display + Debug>(
&self,
endpoint: &str,
id: I,
@ -156,7 +168,12 @@ impl AnimeThemesClient {
}
/// Starts a get request to the API endpoint
async fn api_get<T: Serialize + ?Sized>(&self, path: &str, query: &T) -> ApiResult<Response> {
#[tracing::instrument(level = "trace", skip(self))]
async fn api_get<T: Serialize + Debug + ?Sized>(
&self,
path: &str,
query: &T,
) -> ApiResult<Response> {
let response = self
.client
.get(format!("{}{}", self.api_endpoint, path))

Loading…
Cancel
Save