Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add opentelemetry exporter layer for tracing #318

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,221 changes: 582 additions & 639 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ aes-gcm = "0.10"
anyhow = { version = "1.0", features = ["backtrace"] }
bollard = "0.11"
clap = { version = "4.2", features = ["derive", "env"] }
ed25519-dalek = {version = "1.0.1", features = ["serde"]}
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
futures = "0.3"
hex = "0.4.3"
hyper = { version = "0.14", features = ["full"] }
Expand All @@ -26,7 +26,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
12 changes: 6 additions & 6 deletions integration-tests/src/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,7 +39,6 @@ use testcontainers::{
};
use tokio::io::AsyncWriteExt;
use tracing;
use workspaces::AccountId;

use std::fs;

Expand Down Expand Up @@ -289,11 +289,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 @@ -553,7 +553,7 @@ impl<'a> SignerNode<'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 Expand Up @@ -649,7 +649,7 @@ impl<'a> LeaderNode<'a> {
gcp_project_id: &str,
near_root_account: &AccountId,
account_creator_id: &AccountId,
account_creator_sk: &workspaces::types::SecretKey,
account_creator_sk: &near_workspaces::types::SecretKey,
firebase_audience_id: &str,
oidc_provider_url: &str,
) -> anyhow::Result<LeaderNode<'a>> {
Expand Down Expand Up @@ -705,7 +705,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
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 @@ -70,7 +70,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://localhost:{}",
sandbox
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async fn main() -> anyhow::Result<()> {

tracing::info!("Please run the command below to start a leader node:");
tracing::info!(
"RUST_LOG=mpc_recovery=debug cargo run --bin mpc-recovery -- {}",
"RUST_BACKTRACE=1 RUST_LOG=mpc_recovery=debug cargo run --bin mpc-recovery -- {}",
cmd.join(" ")
);
tracing::info!("====================================");
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 @@ -5,9 +5,9 @@ use std::{

use anyhow::{Context, Ok};
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 @@ -12,7 +12,7 @@ use mpc_recovery::{
};
use mpc_recovery_integration_tests::containers;
use near_primitives::utils::generate_random_string;
use workspaces::{network::Sandbox, Worker};
use near_workspaces::{network::Sandbox, Worker};

const NETWORK: &str = "mpc_it_network";
const GCP_PROJECT_ID: &str = "mpc-recovery-gcp-project";
Expand Down Expand Up @@ -119,8 +119,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 @@ -178,7 +178,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
1 change: 1 addition & 0 deletions mpc-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod firewall;
pub mod gcp;
pub mod key_recovery;
pub mod leader_node;
pub mod logging;
pub mod metrics;
pub mod msg;
pub mod nar;
Expand Down
Loading
Loading