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

Use logging filter, remove otel. #422

Merged
merged 7 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions notary-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ serde_yaml = "0.9.21"
sha1 = "0.10"
structopt = "0.3.26"
thiserror = "1"
tlsn-verifier = { path = "../tlsn/tlsn-verifier" }
tlsn-tls-core = { path = "../components/tls/tls-core" }
tlsn-verifier = { path = "../tlsn/tlsn-verifier", features = ["tracing"] }
tokio = { version = "1", features = ["full"] }
tokio-rustls = { version = "0.24.1" }
tokio-util = { version = "0.7", features = ["compat"] }
Expand All @@ -44,6 +43,7 @@ ws_stream_tungstenite = { version = "0.10.0", features = ["tokio_io"] }
[dev-dependencies]
# specify vendored feature to use statically linked copy of OpenSSL
hyper-tls = { version = "0.5.0", features = ["vendored"] }
tlsn-prover = { path = "../tlsn/tlsn-prover", features = ["tracing"] }
tls-server-fixture = { path = "../components/tls/tls-server-fixture" }
tlsn-prover = { path = "../tlsn/tlsn-prover" }
tlsn-tls-core = { path = "../components/tls/tls-core" }
tokio-native-tls = { version = "0.3.1", features = ["vendored"] }
12 changes: 12 additions & 0 deletions notary-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ To perform notarization using the session id (unique id returned upon calling th
##### Query Parameter Type
String

---
## Debugging
The default logging of this server is set to `DEBUG` verbosity level for all crates (both internal and external) using tracing crate's [EnvFilter](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html).
yuroitaki marked this conversation as resolved.
Show resolved Hide resolved

To help with debugging, one can use the following environment variable with the command to launch the server (Cargo or Docker):

`RUST_LOG=notary_server,tlsn_verifier,tls_mpc,tls_client_async=DEBUG`

This effectively reduces the volume of logs by only including DEBUG-level logs from the crates that are useful for most debugging scenarios.

One can always modify this env var to include any crate of interest by following tracing crate's [filter directive syntax](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#example-syntax).

---
## Architecture
### Objective
Expand Down
3 changes: 0 additions & 3 deletions notary-server/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ notary-key:
private-key-pem-path: "./fixture/notary/notary.key"
public-key-pem-path: "./fixture/notary/notary.pub"

tracing:
default-level: DEBUG

authorization:
enabled: false
whitelist-csv-path: "./fixture/auth/whitelist.csv"
9 changes: 0 additions & 9 deletions notary-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ pub struct NotaryServerProperties {
pub tls: TLSProperties,
/// File path of private key (in PEM format) used to sign the notarization
pub notary_key: NotarySigningKeyProperties,
/// Setting for logging/tracing
pub tracing: TracingProperties,
/// Setting for authorization
pub authorization: AuthorizationProperties,
}
Expand Down Expand Up @@ -57,10 +55,3 @@ pub struct NotarySigningKeyProperties {
pub private_key_pem_path: String,
pub public_key_pem_path: String,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct TracingProperties {
/// The minimum logging level, must be either of <https://docs.rs/tracing/latest/tracing/struct.Level.html#implementations>
pub default_level: String,
}
2 changes: 1 addition & 1 deletion notary-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod util;

pub use config::{
AuthorizationProperties, NotarizationProperties, NotaryServerProperties,
NotarySigningKeyProperties, ServerProperties, TLSProperties, TracingProperties,
NotarySigningKeyProperties, ServerProperties, TLSProperties,
};
pub use domain::{
cli::CliFields,
Expand Down
2 changes: 1 addition & 1 deletion notary-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn main() -> Result<(), NotaryServerError> {
let config: NotaryServerProperties = parse_config_file(&cli_fields.config_file)?;

// Set up tracing for logging
init_tracing(&config).map_err(|err| eyre!("Failed to set up tracing: {err}"))?;
init_tracing().map_err(|err| eyre!("Failed to set up tracing: {err}"))?;

debug!(?config, "Server config loaded");

Expand Down
26 changes: 7 additions & 19 deletions notary-server/src/server_tracing.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
use eyre::Result;
use opentelemetry::{
global,
sdk::{export::trace::stdout, propagation::TraceContextPropagator},
};
use tracing::metadata::LevelFilter;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};

use crate::config::NotaryServerProperties;

pub fn init_tracing(config: &NotaryServerProperties) -> Result<()> {
// Create a new OpenTelemetry pipeline
let tracer = stdout::new_pipeline().install_simple();

// Create a tracing layer with the configured tracer
let tracing_layer = tracing_opentelemetry::layer().with_tracer(tracer);

// Set the log level
let env_filter_layer = EnvFilter::new(&config.tracing.default_level);
pub fn init_tracing() -> Result<()> {
// Retrieve log filter logic from RUST_LOG env var
let env_filter_layer = EnvFilter::builder()
// if RUST_LOG is not set, then set DEBUG level logging for all crates
.with_default_directive(LevelFilter::DEBUG.into())
.from_env_lossy();

// Format the log
let format_layer = tracing_subscriber::fmt::layer()
Expand All @@ -24,11 +16,7 @@ pub fn init_tracing(config: &NotaryServerProperties) -> Result<()> {
.with_thread_ids(true)
.with_thread_names(true);

// Set up context propagation
global::set_text_map_propagator(TraceContextPropagator::default());

Registry::default()
.with(tracing_layer)
.with(env_filter_layer)
.with(format_layer)
.try_init()?;
Expand Down
5 changes: 1 addition & 4 deletions notary-server/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use ws_stream_tungstenite::WsStream;
use notary_server::{
read_pem_file, run_server, AuthorizationProperties, NotarizationProperties,
NotarizationSessionRequest, NotarizationSessionResponse, NotaryServerProperties,
NotarySigningKeyProperties, ServerProperties, TLSProperties, TracingProperties,
NotarySigningKeyProperties, ServerProperties, TLSProperties,
};

const NOTARY_CA_CERT_PATH: &str = "./fixture/tls/rootCA.crt";
Expand All @@ -54,9 +54,6 @@ fn get_server_config(port: u16, tls_enabled: bool) -> NotaryServerProperties {
private_key_pem_path: "./fixture/notary/notary.key".to_string(),
public_key_pem_path: "./fixture/notary/notary.pub".to_string(),
},
tracing: TracingProperties {
default_level: "DEBUG".to_string(),
},
authorization: AuthorizationProperties {
enabled: false,
whitelist_csv_path: "./fixture/auth/whitelist.csv".to_string(),
Expand Down
Loading