Skip to content

Commit

Permalink
feat: add opentelemetry exporter layer for tracing (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov authored Oct 17, 2023
1 parent bc064e8 commit af97660
Show file tree
Hide file tree
Showing 15 changed files with 1,023 additions and 512 deletions.
1,118 changes: 641 additions & 477 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde_json = "1"
testcontainers = { version = "0.14", features = ["experimental"] }
tokio = { version = "1.28", features = ["full"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
workspaces = { git = "https://github.com/near/workspaces-rs", branch = "main" }
near-workspaces = { git = "https://github.com/near/workspaces-rs", branch = "main" }
toml = "0.8.1"

[dev-dependencies]
Expand Down
13 changes: 8 additions & 5 deletions integration-tests/src/env/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use near_primitives::borsh::BorshSerialize;
use near_primitives::delegate_action::{DelegateAction, SignedDelegateAction};
use near_primitives::transaction::{Action, AddKeyAction, DeleteKeyAction};
use near_primitives::views::FinalExecutionStatus;
use near_workspaces::AccountId;
use once_cell::sync::Lazy;
use testcontainers::{
clients::Cli,
Expand All @@ -38,12 +39,12 @@ use testcontainers::{
};
use tokio::io::AsyncWriteExt;
use tracing;
use workspaces::AccountId;

use std::fs;

use crate::env::{Context, LeaderNodeApi, SignerNodeApi};
use crate::util::{self, create_key_file, create_relayer_cofig_file};
use mpc_recovery::logging;

static NETWORK_MUTEX: Lazy<Mutex<i32>> = Lazy::new(|| Mutex::new(0));

Expand Down Expand Up @@ -296,11 +297,11 @@ impl<'a> Relayer<'a> {
near_rpc: &str,
redis_full_address: &str,
relayer_account_id: &AccountId,
relayer_account_sk: &workspaces::types::SecretKey,
relayer_account_sk: &near_workspaces::types::SecretKey,
creator_account_id: &AccountId,
social_db_id: &AccountId,
social_account_id: &AccountId,
social_account_sk: &workspaces::types::SecretKey,
social_account_sk: &near_workspaces::types::SecretKey,
relayer_id: &str,
) -> anyhow::Result<Relayer<'a>> {
tracing::info!("Running relayer container...");
Expand Down Expand Up @@ -529,6 +530,7 @@ impl SignerNode<'_> {
gcp_project_id: ctx.gcp_project_id.clone(),
gcp_datastore_url: Some(ctx.datastore.address.clone()),
jwt_signature_pk_url: ctx.oidc_provider.jwt_pk_url.clone(),
logging_options: logging::Options::default(),
}
.into_str_args();

Expand All @@ -547,7 +549,7 @@ impl SignerNode<'_> {

container.exec(ExecCommand {
cmd: format!("bash -c 'while [[ \"$(curl -s -o /dev/null -w ''%{{http_code}}'' localhost:{})\" != \"200\" ]]; do sleep 1; done'", Self::CONTAINER_PORT),
ready_conditions: vec![WaitFor::message_on_stdout("node is ready to accept connections")]
ready_conditions: vec![WaitFor::message_on_stderr("node is ready to accept connections")]
});

let full_address = format!("http://{ip_address}:{}", Self::CONTAINER_PORT);
Expand Down Expand Up @@ -661,6 +663,7 @@ impl<'a> LeaderNode<'a> {
gcp_project_id: ctx.gcp_project_id.clone(),
gcp_datastore_url: Some(ctx.datastore.address.to_string()),
jwt_signature_pk_url: ctx.oidc_provider.jwt_pk_url.to_string(),
logging_options: logging::Options::default(),
}
.into_str_args();

Expand All @@ -679,7 +682,7 @@ impl<'a> LeaderNode<'a> {

container.exec(ExecCommand {
cmd: format!("bash -c 'while [[ \"$(curl -s -o /dev/null -w ''%{{http_code}}'' localhost:{})\" != \"200\" ]]; do sleep 1; done'", Self::CONTAINER_PORT),
ready_conditions: vec![WaitFor::message_on_stdout("node is ready to accept connections")]
ready_conditions: vec![WaitFor::message_on_stderr("node is ready to accept connections")]
});

let full_address = format!("http://{ip_address}:{}", Self::CONTAINER_PORT);
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/src/env/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use multi_party_eddsa::protocols::ExpandedKeyPair;

use crate::env::{LeaderNodeApi, SignerNodeApi};
use crate::util;
use mpc_recovery::logging;

pub struct SignerNode {
pub address: String,
Expand Down Expand Up @@ -49,6 +50,7 @@ impl SignerNode {
gcp_project_id: ctx.gcp_project_id.clone(),
gcp_datastore_url: Some(ctx.datastore.local_address.clone()),
jwt_signature_pk_url: ctx.oidc_provider.jwt_pk_local_url.clone(),
logging_options: logging::Options::default(),
}
.into_str_args();

Expand Down Expand Up @@ -126,6 +128,7 @@ impl LeaderNode {
gcp_project_id: ctx.gcp_project_id.clone(),
gcp_datastore_url: Some(ctx.datastore.local_address.clone()),
jwt_signature_pk_url: ctx.oidc_provider.jwt_pk_local_url.clone(),
logging_options: logging::Options::default(),
}
.into_str_args();

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bollard::exec::{CreateExecOptions, StartExecResults};
use futures::StreamExt;
use near_crypto::KeyFile;
use near_units::parse_near;
use workspaces::{
use near_workspaces::{
network::{Sandbox, ValidatorKey},
Account, Worker,
};
Expand Down Expand Up @@ -72,7 +72,7 @@ pub async fn initialize_relayer<'a>(
let validator_key = fetch_validator_keys(docker_client, &sandbox).await?;

tracing::info!("Initializing sandbox worker...");
let worker = workspaces::sandbox()
let worker = near_workspaces::sandbox()
.rpc_addr(&format!(
"http://127.0.0.1:{}",
sandbox
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/sandbox.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use workspaces::{network::Sandbox, Account, Contract, Worker};
use near_workspaces::{network::Sandbox, Account, Contract, Worker};

pub async fn initialize_social_db(worker: &Worker<Sandbox>) -> anyhow::Result<Contract> {
tracing::info!("Initializing social DB contract...");
let social_db = worker
.import_contract(&"social.near".parse()?, &workspaces::mainnet().await?)
.import_contract(&"social.near".parse()?, &near_workspaces::mainnet().await?)
.transact()
.await?;
social_db
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::{
use anyhow::Context;
use async_process::{Child, Command, Stdio};
use hyper::{Body, Client, Method, Request, StatusCode, Uri};
use near_workspaces::{types::SecretKey, AccountId};
use serde::{Deserialize, Serialize};
use toml::Value;
use workspaces::{types::SecretKey, AccountId};

use crate::containers::RelayerConfig;

Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mpc_recovery::{
};
use mpc_recovery_integration_tests::env;
use mpc_recovery_integration_tests::env::containers::DockerClient;
use workspaces::{network::Sandbox, Worker};
use near_workspaces::{network::Sandbox, Worker};

pub struct TestContext {
env: String,
Expand Down Expand Up @@ -58,8 +58,8 @@ where
}

mod account {
use near_workspaces::{network::Sandbox, AccountId, Worker};
use rand::{distributions::Alphanumeric, Rng};
use workspaces::{network::Sandbox, AccountId, Worker};

pub fn random(worker: &Worker<Sandbox>) -> anyhow::Result<AccountId> {
let account_id_rand: String = rand::thread_rng()
Expand Down Expand Up @@ -117,7 +117,7 @@ mod key {
mod check {
use crate::TestContext;
use near_crypto::PublicKey;
use workspaces::AccountId;
use near_workspaces::AccountId;

pub async fn access_key_exists(
ctx: &TestContext,
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/mpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mpc_recovery::msg::{NewAccountResponse, UserCredentialsResponse};
use mpc_recovery::sign_node::oidc::OidcToken;
use mpc_recovery::transaction::LimitedAccessKey;
use near_crypto::{PublicKey, SecretKey};
use workspaces::AccountId;
use near_workspaces::AccountId;

use crate::{account, check, key, MpcCheck, TestContext};

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/mpc/negative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use near_primitives::{
DeployContractAction, FunctionCallAction, StakeAction, TransferAction,
},
};
use near_workspaces::AccountId;
use std::{str::FromStr, time::Duration};
use test_log::test;
use workspaces::AccountId;

#[test(tokio::test)]
async fn whitlisted_actions_test() -> anyhow::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/tests/mpc/positive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::mpc::{add_pk_and_check_validity, fetch_recovery_pk, new_random_accoun
use crate::{account, key, with_nodes, MpcCheck};

use hyper::StatusCode;
use workspaces::types::AccessKeyPermission;
use near_workspaces::types::AccessKeyPermission;

use mpc_recovery::{
gcp::value::{FromValue, IntoValue},
Expand Down
6 changes: 6 additions & 0 deletions mpc-recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ aes-gcm = "0.10"
actix-rt = "2.8"
anyhow = "1"
async-trait = "0.1"
atty = "0.2"
axum = "0.6.19"
axum-extra = "0.7"
base64 = "0.21"
Expand All @@ -26,6 +27,9 @@ hyper = { version = "0.14", features = ["full"] }
hyper-rustls = { version = "=0.23", features = ["http2"] }
jsonwebtoken = "8.3.0"
lazy_static = "1.4.0"
opentelemetry = { version = "0.20.0", features = ["rt-tokio", "trace"] }
opentelemetry-otlp = "0.13.0"
opentelemetry-semantic-conventions = "0.12.0"
prometheus = { version = "0.13.3", features = ["process"] }
rand = "0.7"
rand8 = { package = "rand", version = "0.8" }
Expand All @@ -37,7 +41,9 @@ thiserror = "1"
tokio = { version = "1.28", features = ["full"] }
tokio-retry = "0.3"
tracing = "0.1"
tracing-appender = "0.2.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-opentelemetry = "0.21.0"
near-jsonrpc-client = "0.6"
near-jsonrpc-primitives = "0.17"
near-primitives = "0.17"
Expand Down
2 changes: 0 additions & 2 deletions mpc-recovery/src/leader_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::transaction::{
};
use crate::utils::{check_digest_signature, user_credentials_request_digest};
use crate::{metrics, nar};

use anyhow::Context;
use axum::extract::MatchedPath;
use axum::middleware::{self, Next};
Expand All @@ -35,7 +34,6 @@ use near_primitives::transaction::{Action, DeleteKeyAction};
use near_primitives::types::AccountId;
use prometheus::{Encoder, TextEncoder};
use rand::{distributions::Alphanumeric, Rng};

use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Instant;
Expand Down
Loading

0 comments on commit af97660

Please sign in to comment.