mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-09 21:38:00 -05:00
Use logging filter, remove otel. (#422)
* Use env var for logging filter, remove otel. * Fix directives. * Revert to using config for logging filter. * Modify default logging strategy and make filter optional. * Revert formatting of other crates. * Update README. * Update notary-server/README.md Co-authored-by: Hendrik Eeckhaut <hendrik@eeckhaut.org> --------- Co-authored-by: Hendrik Eeckhaut <hendrik@eeckhaut.org>
This commit is contained in:
committed by
GitHub
parent
29fb409409
commit
de4d0240ab
@@ -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"] }
|
||||
@@ -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"] }
|
||||
|
||||
@@ -82,6 +82,16 @@ To perform notarization using the session id (unique id returned upon calling th
|
||||
##### Query Parameter Type
|
||||
String
|
||||
|
||||
---
|
||||
## Logging
|
||||
The default logging strategy of this server is set to `DEBUG` verbosity level for the crates that are useful for most debugging scenarios, i.e. using the following filtering logic:
|
||||
|
||||
`notary_server=DEBUG,tlsn_verifier=DEBUG,tls_mpc=DEBUG,tls_client_async=DEBUG`
|
||||
|
||||
In the config [file](./config/config.yaml), one can toggle the verbosity level for these crates using the `level` field under `logging`.
|
||||
|
||||
One can also provide custom filtering logic by adding a `filter` field under `logging` in the config file above, and use a value that follows tracing crate's [filter directive syntax](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#example-syntax).
|
||||
|
||||
---
|
||||
## Architecture
|
||||
### Objective
|
||||
|
||||
@@ -15,8 +15,8 @@ notary-key:
|
||||
private-key-pem-path: "./fixture/notary/notary.key"
|
||||
public-key-pem-path: "./fixture/notary/notary.pub"
|
||||
|
||||
tracing:
|
||||
default-level: DEBUG
|
||||
logging:
|
||||
level: DEBUG
|
||||
|
||||
authorization:
|
||||
enabled: false
|
||||
|
||||
@@ -11,8 +11,8 @@ 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 logging
|
||||
pub logging: LoggingProperties,
|
||||
/// Setting for authorization
|
||||
pub authorization: AuthorizationProperties,
|
||||
}
|
||||
@@ -60,7 +60,11 @@ pub struct NotarySigningKeyProperties {
|
||||
|
||||
#[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,
|
||||
pub struct LoggingProperties {
|
||||
/// Log verbosity level of the default filtering logic, which is notary_server=<level>,tlsn_verifier=<level>,tls_mpc=<level>
|
||||
/// Must be either of <https://docs.rs/tracing/latest/tracing/struct.Level.html#implementations>
|
||||
pub level: String,
|
||||
/// Custom filtering logic, refer to the syntax here https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#example-syntax
|
||||
/// This will override the default filtering logic above
|
||||
pub filter: Option<String>,
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ mod service;
|
||||
mod util;
|
||||
|
||||
pub use config::{
|
||||
AuthorizationProperties, NotarizationProperties, NotaryServerProperties,
|
||||
NotarySigningKeyProperties, ServerProperties, TLSProperties, TracingProperties,
|
||||
AuthorizationProperties, LoggingProperties, NotarizationProperties, NotaryServerProperties,
|
||||
NotarySigningKeyProperties, ServerProperties, TLSProperties,
|
||||
};
|
||||
pub use domain::{
|
||||
cli::CliFields,
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
use eyre::Result;
|
||||
use opentelemetry::{
|
||||
global,
|
||||
sdk::{export::trace::stdout, propagation::TraceContextPropagator},
|
||||
};
|
||||
use std::str::FromStr;
|
||||
use tracing::Level;
|
||||
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);
|
||||
// Retrieve log filtering logic from config
|
||||
let directives = match &config.logging.filter {
|
||||
// Use custom filter that is provided by user
|
||||
Some(filter) => filter.clone(),
|
||||
// Use the default filter when only verbosity level is provided
|
||||
None => {
|
||||
let level = Level::from_str(&config.logging.level)?;
|
||||
format!("notary_server={level},tlsn_verifier={level},tls_mpc={level}")
|
||||
}
|
||||
};
|
||||
let filter_layer = EnvFilter::builder().parse(directives)?;
|
||||
|
||||
// Format the log
|
||||
let format_layer = tracing_subscriber::fmt::layer()
|
||||
@@ -24,12 +25,8 @@ 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(filter_layer)
|
||||
.with(format_layer)
|
||||
.try_init()?;
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@ use tracing::debug;
|
||||
use ws_stream_tungstenite::WsStream;
|
||||
|
||||
use notary_server::{
|
||||
read_pem_file, run_server, AuthorizationProperties, NotarizationProperties,
|
||||
read_pem_file, run_server, AuthorizationProperties, LoggingProperties, NotarizationProperties,
|
||||
NotarizationSessionRequest, NotarizationSessionResponse, NotaryServerProperties,
|
||||
NotarySigningKeyProperties, ServerProperties, TLSProperties, TracingProperties,
|
||||
NotarySigningKeyProperties, ServerProperties, TLSProperties,
|
||||
};
|
||||
|
||||
const NOTARY_CA_CERT_PATH: &str = "./fixture/tls/rootCA.crt";
|
||||
@@ -54,8 +54,9 @@ 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(),
|
||||
logging: LoggingProperties {
|
||||
level: "DEBUG".to_string(),
|
||||
filter: None,
|
||||
},
|
||||
authorization: AuthorizationProperties {
|
||||
enabled: false,
|
||||
|
||||
Reference in New Issue
Block a user