Skip to content

Commit c971366

Browse files
delbonisstoropoli
andcommitted
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: Jose Storopoli <[email protected]>
1 parent d5c5bcd commit c971366

File tree

12 files changed

+324
-28
lines changed

12 files changed

+324
-28
lines changed

Cargo.lock

Lines changed: 132 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ members = [
3737
"crates/sync",
3838
"crates/tasks",
3939
"crates/test-utils",
40+
"crates/tx-parser",
4041
"crates/util/mmr",
4142
"crates/util/shrex",
4243
"crates/vtxjmt",
@@ -46,12 +47,10 @@ members = [
4647
# binaries listed separately
4748
"bin/bridge-client",
4849
"bin/datatool",
49-
"bin/prover-client",
5050
"bin/strata-cli",
5151
"bin/strata-client",
5252
"bin/strata-reth",
53-
"bin/datatool",
54-
"crates/tx-parser",
53+
"bin/prover-client",
5554

5655
# integration tests
5756
"tests",
@@ -143,6 +142,9 @@ miniscript = "12.2.0"
143142
mockall = "0.11"
144143
musig2 = { version = "0.1.0", features = ["serde"] }
145144
num_enum = "0.7"
145+
opentelemetry = "0.26"
146+
opentelemetry-otlp = { version = "0.26", features = ["grpc-tonic"] }
147+
opentelemetry_sdk = { version = "0.26", features = ["rt-tokio"] }
146148
parking_lot = "0.12.3"
147149
paste = "1.0"
148150
rand = "0.8.5"
@@ -208,7 +210,8 @@ threadpool = "1.8"
208210
tokio = { version = "1.37", features = ["full"] }
209211
toml = "0.5"
210212
tower = "0.4"
211-
tracing = "0.1.40"
213+
tracing = "0.1"
214+
tracing-opentelemetry = "0.27"
212215
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
213216
uuid = { version = "1.0", features = ["v4", "serde"] }
214217

bin/bridge-client/src/descriptor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ mod tests {
146146

147147
#[tokio::test]
148148
async fn bitcoind_import_descriptors() {
149-
logging::init();
149+
logging::init(logging::LoggerConfig::with_base_name(
150+
"bridge-client-descriptor-tests",
151+
));
150152
let bitcoind = BitcoinD::from_downloaded().unwrap();
151153
let url = bitcoind.rpc_url();
152154
let (user, password) = get_auth(&bitcoind);

bin/bridge-client/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub(crate) mod rpc_server;
1313

1414
use args::{Cli, OperationMode};
1515
use modes::{challenger, operator};
16-
use strata_common::logging;
16+
use strata_common::logging::{self, LoggerConfig};
1717
use tracing::info;
1818

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

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

bin/prover-client/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ mod task;
3535

3636
#[tokio::main]
3737
async fn main() {
38-
logging::init();
38+
logging::init(logging::LoggerConfig::with_base_name(
39+
"strata-prover-client",
40+
));
3941
info!("Running strata prover client in dev mode");
4042

4143
let args: Args = argh::from_env();

bin/strata-client/src/extractor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ mod tests {
218218

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

223224
let (mock_db, db_config) =
224225
get_rocksdb_tmp_instance().expect("should be able to get tmp rocksdb instance");

bin/strata-client/src/main.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use strata_storage::{
3636
use strata_sync::{self, L2SyncContext, RpcSyncPeer};
3737
use strata_tasks::{ShutdownSignal, TaskExecutor, TaskManager};
3838
use tokio::{
39-
runtime::Runtime,
39+
runtime::{Handle, Runtime},
4040
sync::{broadcast, oneshot},
4141
};
4242
use tracing::*;
@@ -73,7 +73,15 @@ fn main() -> anyhow::Result<()> {
7373
}
7474

7575
fn main_inner(args: Args) -> anyhow::Result<()> {
76-
logging::init();
76+
// Start runtime for async IO tasks.
77+
let runtime = tokio::runtime::Builder::new_multi_thread()
78+
.enable_all()
79+
.thread_name("strata-rt")
80+
.build()
81+
.expect("init: build rt");
82+
83+
// Init the logging before we do anything else.
84+
init_logging(runtime.handle());
7785

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

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

103-
// Start runtime for async IO tasks.
104-
let runtime = tokio::runtime::Builder::new_multi_thread()
105-
.enable_all()
106-
.thread_name("strata-rt")
107-
.build()
108-
.expect("init: build rt");
109-
110111
// Init thread pool for batch jobs.
111112
// TODO switch to num_cpus
112113
let pool = threadpool::ThreadPool::with_name("strata-pool".to_owned(), 8);
@@ -133,6 +134,8 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
133134
genesis::init_client_state(&params, database.as_ref())?;
134135
}
135136

137+
info!("init finished, starting main tasks");
138+
136139
let ctx = start_core_tasks(
137140
&executor,
138141
pool,
@@ -215,6 +218,29 @@ fn main_inner(args: Args) -> anyhow::Result<()> {
215218
Ok(())
216219
}
217220

221+
/// Sets up the logging system given a handle to a runtime context to possibly
222+
/// start the OTLP output on.
223+
fn init_logging(rt: &Handle) {
224+
let mut lconfig = logging::LoggerConfig::with_base_name("strata-client");
225+
226+
// Set the OpenTelemetry URL if set.
227+
let otlp_url = logging::get_otlp_url_from_env();
228+
if let Some(url) = &otlp_url {
229+
lconfig.set_otlp_url(url.clone());
230+
}
231+
232+
{
233+
// Need to set the runtime context because of nonsense.
234+
let _g = rt.enter();
235+
logging::init(lconfig);
236+
}
237+
238+
// Have to log this after we start the logging formally.
239+
if let Some(url) = &otlp_url {
240+
info!(%url, "using OpenTelemetry tracing output");
241+
}
242+
}
243+
218244
#[derive(Clone)]
219245
pub struct CoreContext {
220246
pub database: Arc<CommonDb>,

contrib/jaeger.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Script for standing up a local instance of Jaeger, so we can use it for
3+
# running fntests, for example.
4+
#
5+
# Adapted from: https://www.jaegertracing.io/docs/1.6/getting-started/
6+
7+
TAG_VER=1.62.0
8+
9+
OTLP_GRPC_PORT=4317
10+
WEB_PORT=16686
11+
12+
docker run -d \
13+
--name jaeger \
14+
-e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
15+
-e COLLECTOR_OTLP_ENABLED=true \
16+
-p $OTLP_GRPC_PORT:4317 \
17+
-p 4318:4318 \
18+
-p 5775:5775/udp \
19+
-p 6831:6831/udp \
20+
-p 6832:6832/udp \
21+
-p 5778:5778 \
22+
-p $WEB_PORT:16686 \
23+
-p 14268:14268 \
24+
-p 9411:9411 \
25+
jaegertracing/all-in-one:$TAG_VER
26+
27+
echo "Set envvar: 'export STRATA_OTLP_URL=http://127.0.0.1:$OTLP_GRPC_PORT'"
28+
echo "Open http://localhost:$WEB_PORT/ in your browser."

crates/btcio/src/rpc/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ mod test {
424424

425425
#[tokio::test()]
426426
async fn client_works() {
427-
logging::init();
427+
logging::init(logging::LoggerConfig::with_base_name("btcio-tests"));
428+
428429
// setting the ENV variable `BITCOIN_XPRIV_RETRIEVABLE` to retrieve the xpriv
429430
set_var("BITCOIN_XPRIV_RETRIEVABLE", "true");
430431
let bitcoind = BitcoinD::from_downloaded().unwrap();

crates/common/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ name = "strata-common"
44
version = "0.1.0"
55

66
[dependencies]
7+
opentelemetry.workspace = true
8+
opentelemetry-otlp.workspace = true
9+
opentelemetry_sdk.workspace = true
710
tracing.workspace = true
11+
tracing-opentelemetry.workspace = true
812
tracing-subscriber.workspace = true

0 commit comments

Comments
 (0)