Skip to content

Commit

Permalink
applied patch from STR-440-opentelemetry-output (#473)
Browse files Browse the repository at this point in the history
STR-440 OpenTelemetry tracing exporter (#342)

* common: tried to set up otlp

This deletes Cargo.lock because we couldn't get the deps to work anyways.

* fix: bump opentelemetry stuff to 0.26

now it compiles at least-ish

* common: added more correct init for OTLP tracing output

* common, contrib: fixed some more logging stuff, added Jaeger util script

* common, stratad: reworked logging init some more to try to make it work

* contrib: fixed Jaeger init script to use a recent version

* bridge-client: fixed broken test, fixed Tokio version

* common: added `service.name` property to OTLP params

* prover-client: fixed missing `LoggerConfig`

* stratad: fixed broken tests??? idk why this is here

* tests: fixed broken logging

* btcio: fixed broken logging

---------

Co-authored-by: Trey Del Bonis <[email protected]>
  • Loading branch information
storopoli and delbonis authored Nov 14, 2024
1 parent d5c5bcd commit 9c45b61
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 28 deletions.
134 changes: 132 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ members = [
"crates/sync",
"crates/tasks",
"crates/test-utils",
"crates/tx-parser",
"crates/util/mmr",
"crates/util/shrex",
"crates/vtxjmt",
Expand All @@ -46,12 +47,10 @@ members = [
# binaries listed separately
"bin/bridge-client",
"bin/datatool",
"bin/prover-client",
"bin/strata-cli",
"bin/strata-client",
"bin/strata-reth",
"bin/datatool",
"crates/tx-parser",
"bin/prover-client",

# integration tests
"tests",
Expand Down Expand Up @@ -143,6 +142,9 @@ miniscript = "12.2.0"
mockall = "0.11"
musig2 = { version = "0.1.0", features = ["serde"] }
num_enum = "0.7"
opentelemetry = "0.26"
opentelemetry-otlp = { version = "0.26", features = ["grpc-tonic"] }
opentelemetry_sdk = { version = "0.26", features = ["rt-tokio"] }
parking_lot = "0.12.3"
paste = "1.0"
rand = "0.8.5"
Expand Down Expand Up @@ -208,7 +210,8 @@ threadpool = "1.8"
tokio = { version = "1.37", features = ["full"] }
toml = "0.5"
tower = "0.4"
tracing = "0.1.40"
tracing = "0.1"
tracing-opentelemetry = "0.27"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
uuid = { version = "1.0", features = ["v4", "serde"] }

Expand Down
4 changes: 3 additions & 1 deletion bin/bridge-client/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ mod tests {

#[tokio::test]
async fn bitcoind_import_descriptors() {
logging::init();
logging::init(logging::LoggerConfig::with_base_name(
"bridge-client-descriptor-tests",
));
let bitcoind = BitcoinD::from_downloaded().unwrap();
let url = bitcoind.rpc_url();
let (user, password) = get_auth(&bitcoind);
Expand Down
4 changes: 2 additions & 2 deletions bin/bridge-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub(crate) mod rpc_server;

use args::{Cli, OperationMode};
use modes::{challenger, operator};
use strata_common::logging;
use strata_common::logging::{self, LoggerConfig};
use tracing::info;

#[tokio::main]
async fn main() {
logging::init();
logging::init(LoggerConfig::with_base_name("strata-bridge-client"));

let cli_args: Cli = argh::from_env();

Expand Down
4 changes: 3 additions & 1 deletion bin/prover-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ mod task;

#[tokio::main]
async fn main() {
logging::init();
logging::init(logging::LoggerConfig::with_base_name(
"strata-prover-client",
));
info!("Running strata prover client in dev mode");

let args: Args = argh::from_env();
Expand Down
3 changes: 2 additions & 1 deletion bin/strata-client/src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ mod tests {

#[tokio::test]
async fn test_extract_deposit_requests() {
logging::init();
// FIXME this is absurd, why are we doing this here?
logging::init(logging::LoggerConfig::with_base_name("strata-client-tests"));

let (mock_db, db_config) =
get_rocksdb_tmp_instance().expect("should be able to get tmp rocksdb instance");
Expand Down
44 changes: 35 additions & 9 deletions bin/strata-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use strata_storage::{
use strata_sync::{self, L2SyncContext, RpcSyncPeer};
use strata_tasks::{ShutdownSignal, TaskExecutor, TaskManager};
use tokio::{
runtime::Runtime,
runtime::{Handle, Runtime},
sync::{broadcast, oneshot},
};
use tracing::*;
Expand Down Expand Up @@ -73,7 +73,15 @@ fn main() -> anyhow::Result<()> {
}

fn main_inner(args: Args) -> anyhow::Result<()> {
logging::init();
// Start runtime for async IO tasks.
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("strata-rt")
.build()
.expect("init: build rt");

// Init the logging before we do anything else.
init_logging(runtime.handle());

let config = get_config(args.clone())?;

Expand All @@ -100,13 +108,6 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
// initialize core databases
let database = init_core_dbs(rbdb.clone(), ops_config);

// Start runtime for async IO tasks.
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.thread_name("strata-rt")
.build()
.expect("init: build rt");

// Init thread pool for batch jobs.
// TODO switch to num_cpus
let pool = threadpool::ThreadPool::with_name("strata-pool".to_owned(), 8);
Expand All @@ -133,6 +134,8 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
genesis::init_client_state(&params, database.as_ref())?;
}

info!("init finished, starting main tasks");

let ctx = start_core_tasks(
&executor,
pool,
Expand Down Expand Up @@ -215,6 +218,29 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
Ok(())
}

/// Sets up the logging system given a handle to a runtime context to possibly
/// start the OTLP output on.
fn init_logging(rt: &Handle) {
let mut lconfig = logging::LoggerConfig::with_base_name("strata-client");

// Set the OpenTelemetry URL if set.
let otlp_url = logging::get_otlp_url_from_env();
if let Some(url) = &otlp_url {
lconfig.set_otlp_url(url.clone());
}

{
// Need to set the runtime context because of nonsense.
let _g = rt.enter();
logging::init(lconfig);
}

// Have to log this after we start the logging formally.
if let Some(url) = &otlp_url {
info!(%url, "using OpenTelemetry tracing output");
}
}

#[derive(Clone)]
pub struct CoreContext {
pub database: Arc<CommonDb>,
Expand Down
28 changes: 28 additions & 0 deletions contrib/jaeger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Script for standing up a local instance of Jaeger, so we can use it for
# running fntests, for example.
#
# Adapted from: https://www.jaegertracing.io/docs/1.6/getting-started/

TAG_VER=1.62.0

OTLP_GRPC_PORT=4317
WEB_PORT=16686

docker run -d \
--name jaeger \
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
-e COLLECTOR_OTLP_ENABLED=true \
-p $OTLP_GRPC_PORT:4317 \
-p 4318:4318 \
-p 5775:5775/udp \
-p 6831:6831/udp \
-p 6832:6832/udp \
-p 5778:5778 \
-p $WEB_PORT:16686 \
-p 14268:14268 \
-p 9411:9411 \
jaegertracing/all-in-one:$TAG_VER

echo "Set envvar: 'export STRATA_OTLP_URL=http://127.0.0.1:$OTLP_GRPC_PORT'"
echo "Open http://localhost:$WEB_PORT/ in your browser."
3 changes: 2 additions & 1 deletion crates/btcio/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ mod test {

#[tokio::test()]
async fn client_works() {
logging::init();
logging::init(logging::LoggerConfig::with_base_name("btcio-tests"));

// setting the ENV variable `BITCOIN_XPRIV_RETRIEVABLE` to retrieve the xpriv
set_var("BITCOIN_XPRIV_RETRIEVABLE", "true");
let bitcoind = BitcoinD::from_downloaded().unwrap();
Expand Down
4 changes: 4 additions & 0 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ name = "strata-common"
version = "0.1.0"

[dependencies]
opentelemetry.workspace = true
opentelemetry-otlp.workspace = true
opentelemetry_sdk.workspace = true
tracing.workspace = true
tracing-opentelemetry.workspace = true
tracing-subscriber.workspace = true
Loading

0 comments on commit 9c45b61

Please sign in to comment.