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 6 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
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"] }
10 changes: 10 additions & 0 deletions notary-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
yuroitaki marked this conversation as resolved.
Show resolved Hide resolved

`notary_server=DEBUG,tlsn_verifier=DEBUG,tls_mpc=DEBUG,tls_client_async=DEBUG`
yuroitaki marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
4 changes: 2 additions & 2 deletions notary-server/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

yuroitaki marked this conversation as resolved.
Show resolved Hide resolved
authorization:
enabled: false
Expand Down
14 changes: 9 additions & 5 deletions notary-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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>,
}
4 changes: 2 additions & 2 deletions notary-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 14 additions & 17 deletions notary-server/src/server_tracing.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()?;

Expand Down
9 changes: 5 additions & 4 deletions notary-server/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down
Loading