Skip to content

Commit

Permalink
add tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
UMR1352 committed Jan 24, 2024
1 parent ac9f73a commit 7b1dac2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bindings/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ serde_json = { version = "1.0.108", features = ["alloc"] }
thiserror = "1.0.50"
rand = "0.8.5"
serde = { version = "1.0.193", features = ["derive", "alloc"] }
tracing = { version = "0.1.40", features = ["async-await"] }
tracing-subscriber = "0.3.18"

[dev-dependencies]
identity_storage = { path = "../../identity_storage", features = ["memstore"] }
Expand Down
8 changes: 6 additions & 2 deletions bindings/grpc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ use identity_grpc::server::GRpcServer;
use iota_sdk::client::Client;

#[tokio::main]
#[tracing::instrument(err)]
async fn main() -> anyhow::Result<()> {
tracing::subscriber::set_global_default(tracing_subscriber::fmt().compact().finish())
.expect("Failed to setup global tracing subscriber.");

let api_endpoint = std::env::var("API_ENDPOINT").context("Missing environmental variable API_ENDPOINT")?;

let client: Client = Client::builder()
.with_primary_node(&api_endpoint, None)?
.finish()
.await?;

let addr = "127.0.0.1:50051".parse()?;
println!("gRPC server listening on {}", addr);
let addr = "0.0.0.0:50051".parse()?;
tracing::info!("gRPC server listening on {}", addr);
GRpcServer::new(client).serve(addr).await?;

Ok(())
Expand Down
7 changes: 7 additions & 0 deletions bindings/grpc/src/services/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ impl CredentialVerifier {

#[tonic::async_trait]
impl CredentialRevocation for CredentialVerifier {
#[tracing::instrument(
name = "credential_check",
skip_all,
fields(request = ?req.get_ref())
ret,
err,
)]
async fn check(
&self,
req: Request<RevocationCheckRequest>,
Expand Down
7 changes: 7 additions & 0 deletions bindings/grpc/src/services/health_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub struct HealthChecker {}

#[tonic::async_trait]
impl HealthCheck for HealthChecker {
#[tracing::instrument(
name = "health_check",
skip_all,
fields(request = ?_req.get_ref())
ret,
err,
)]
async fn check(&self, _req: Request<HealthCheckRequest>) -> Result<Response<HealthCheckResponse>, Status> {
Ok(Response::new(HealthCheckResponse { status: "OK".into() }))
}
Expand Down
7 changes: 7 additions & 0 deletions bindings/grpc/src/services/sd_jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ impl SdJwtService {

#[tonic::async_trait]
impl Verification for SdJwtService {
#[tracing::instrument(
name = "sd_jwt_verification",
skip_all,
fields(request = ?request.get_ref())
ret,
err,
)]
async fn verify(
&self,
request: tonic::Request<VerificationRequest>,
Expand Down
2 changes: 2 additions & 0 deletions bindings/grpc/tests/api/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct TestServer {

impl TestServer {
pub async fn new() -> Self {
let _ = tracing::subscriber::set_global_default(tracing_subscriber::fmt().compact().finish());

let listener = TcpListener::bind("127.0.0.1:0")
.await
.expect("Failed to bind to random OS's port");
Expand Down

0 comments on commit 7b1dac2

Please sign in to comment.