Skip to content

feat: open telemetry support #304

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build PBS Docker Image

on:
push:
branches:
- "lt/otel-support"

permissions:
contents: read
packages: write

jobs:
build-and-push-pbs-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push PBS Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/commit-boost/pbs:otel-support
cache-from: type=registry,ref=ghcr.io/commit-boost/pbs:buildcache
cache-to: type=registry,ref=ghcr.io/commit-boost/pbs:buildcache,mode=max
file: provisioning/pbs.Dockerfile
113 changes: 113 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ eyre = "0.6.12"
futures = "0.3.30"
headers = "0.4.0"
indexmap = "2.2.6"
jsonwebtoken = { version = "9.3.1", default-features = false }
lazy_static = "1.5.0"
opentelemetry = { version = "0.29", features = ["trace"] }
opentelemetry-otlp = { version = "0.29", features = ["grpc-tonic", "http-proto", "trace"] }
opentelemetry_sdk = { version = "0.29", features = ["rt-tokio", "trace"] }
parking_lot = "0.12.3"
pbkdf2 = "0.12.2"
prometheus = "0.13.4"
Expand All @@ -63,11 +67,11 @@ tonic = { version = "0.12.3", features = ["channel", "prost", "tls"] }
tonic-build = "0.12.3"
tracing = "0.1.40"
tracing-appender = "0.2.3"
tracing-opentelemetry = "0.30"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
tree_hash = "0.9"
tree_hash_derive = "0.9"
typenum = "1.17.0"
unicode-normalization = "0.1.24"
url = { version = "2.5.0", features = ["serde"] }
uuid = { version = "1.8.0", features = ["fast-rng", "serde", "v4"] }
jsonwebtoken = { version = "9.3.1", default-features = false }
13 changes: 12 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ loader = "./tests/data/mux_keys.example.json"
# loader = { url = "http://localhost:8000/keys" }
# loader = { registry = "lido", node_operator_id = 8 }
# loader = { registry = "ssv", node_operator_id = 8 }
timeout_get_header_ms = 900
late_in_slot_time_ms = 1500
timeout_get_header_ms = 900
# For each mux, one or more [[mux.relays]] can be defined, which will be used for the matching validator pubkeys
# Only the relays defined here will be used, and the relays defined in the main [[relays]] config will be ignored
# The fields specified here are the same as in [[relays]] (headers, get_params, enable_timing_games, target_first_request_ms, frequency_get_header_ms)
Expand Down Expand Up @@ -254,6 +254,12 @@ host = "127.0.0.1"
# OPTIONAL, DEFAULT: 10000
start_port = 10000

[logs]
# Whether to export OpenTelemtry traces. OTEL is configured via env variables, set those in the [env] section or in your docker compose.
# For more info see: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md
# OPTIONAL, DEFAULT: false
export_traces = false

# Configuration stdout logs
# OPTIONAL, DEFAULT: enabled
[logs.stdout]
Expand Down Expand Up @@ -288,3 +294,8 @@ dir_path = "./logs"
# Maximum number of log files to keep
# OPTIONAL
max_files = 30

# Env variables set for all services.
# OPTIONAL
[env]
A_COMMON_ENV = "a_common_value"
11 changes: 11 additions & 0 deletions crates/cli/src/docker_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
// targets to pass to prometheus
let mut targets = Vec::new();

let mut service_common_envs = IndexMap::new();
for (key, val) in cb_config.env {
let (key, val) = get_env_val(key.as_str(), val.as_str());
service_common_envs.insert(key, val);
}

// address for signer API communication
let signer_port = 20000;
let signer_server =
Expand Down Expand Up @@ -112,6 +118,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
get_env_interp(MODULE_JWT_ENV, &jwt_name),
get_env_val(SIGNER_URL_ENV, &signer_server),
]);
module_envs.extend(service_common_envs.clone());

// Pass on the env variables
if let Some(envs) = module.env {
Expand Down Expand Up @@ -198,6 +205,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
get_env_val(CONFIG_ENV, CONFIG_DEFAULT),
get_env_uval(BUILDER_PORT_ENV, builder_events_port),
]);
module_envs.extend(service_common_envs.clone());

if let Some((key, val)) = chain_spec_env.clone() {
module_envs.insert(key, val);
Expand Down Expand Up @@ -247,6 +255,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
// setup pbs service

let mut pbs_envs = IndexMap::from([get_env_val(CONFIG_ENV, CONFIG_DEFAULT)]);
pbs_envs.extend(service_common_envs.clone());
let mut pbs_volumes = vec![config_volume.clone()];

// ports
Expand Down Expand Up @@ -336,6 +345,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
get_env_same(JWTS_ENV),
get_env_uval(SIGNER_PORT_ENV, signer_port as u64),
]);
signer_envs.extend(service_common_envs.clone());

let mut ports = vec![];

Expand Down Expand Up @@ -464,6 +474,7 @@ pub async fn handle_docker_init(config_path: PathBuf, output_dir: PathBuf) -> Re
get_env_val(DIRK_KEY_ENV, DIRK_KEY_DEFAULT),
get_env_val(DIRK_DIR_SECRETS_ENV, DIRK_DIR_SECRETS_DEFAULT),
]);
signer_envs.extend(service_common_envs.clone());

let mut ports = vec![];

Expand Down
6 changes: 5 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ ethereum_serde_utils.workspace = true
ethereum_ssz.workspace = true
ethereum_ssz_derive.workspace = true
eyre.workspace = true
jsonwebtoken.workspace = true
opentelemetry.workspace = true
opentelemetry-otlp.workspace = true
opentelemetry_sdk.workspace = true
pbkdf2.workspace = true
rand.workspace = true
reqwest.workspace = true
Expand All @@ -35,9 +39,9 @@ toml.workspace = true
tonic.workspace = true
tracing.workspace = true
tracing-appender.workspace = true
tracing-opentelemetry.workspace = true
tracing-subscriber.workspace = true
tree_hash.workspace = true
tree_hash_derive.workspace = true
unicode-normalization.workspace = true
url.workspace = true
jsonwebtoken.workspace = true
5 changes: 5 additions & 0 deletions crates/common/src/config/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use crate::utils::default_bool;

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct LogsSettings {
/// Whether to export OpenTelemetry traces
#[serde(default = "default_bool::<false>")]
pub export_traces: bool,
#[serde(default)]
pub stdout: StdoutLogSettings,
#[serde(default)]
pub file: FileLogSettings,
}

Expand Down
7 changes: 6 additions & 1 deletion crates/common/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};

use eyre::Result;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -35,6 +35,8 @@ pub struct CommitBoostConfig {
pub metrics: Option<MetricsConfig>,
#[serde(default)]
pub logs: LogsSettings,
#[serde(default)]
pub env: HashMap<String, String>,
}

impl CommitBoostConfig {
Expand Down Expand Up @@ -81,6 +83,7 @@ impl CommitBoostConfig {
signer: helper_config.signer,
metrics: helper_config.metrics,
logs: helper_config.logs,
env: helper_config.env,
};

Ok(config)
Expand Down Expand Up @@ -120,4 +123,6 @@ struct HelperConfig {
metrics: Option<MetricsConfig>,
#[serde(default)]
logs: LogsSettings,
#[serde(default)]
env: HashMap<String, String>,
}
Loading
Loading