fix otlp
This commit is contained in:
parent
c33f78ac8b
commit
a3e43ef68b
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -3139,6 +3139,15 @@ dependencies = [
|
|||||||
"tonic-build",
|
"tonic-build",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opentelemetry-semantic-conventions"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "985cc35d832d412224b2cffe2f9194b1b89b6aa5d0bef76d080dce09d90e62bd"
|
||||||
|
dependencies = [
|
||||||
|
"opentelemetry",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ordered-multimap"
|
name = "ordered-multimap"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
@ -5280,10 +5289,12 @@ dependencies = [
|
|||||||
"failure",
|
"failure",
|
||||||
"flume",
|
"flume",
|
||||||
"futures",
|
"futures",
|
||||||
|
"hostname",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nix 0.24.1",
|
"nix 0.24.1",
|
||||||
"opentelemetry",
|
"opentelemetry",
|
||||||
"opentelemetry-otlp",
|
"opentelemetry-otlp",
|
||||||
|
"opentelemetry-semantic-conventions",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
"rpassword 6.0.1",
|
"rpassword 6.0.1",
|
||||||
"serde 1.0.137",
|
"serde 1.0.137",
|
||||||
|
@ -90,6 +90,7 @@ impl Default for NetworkManagerStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct ClientWhitelistEntry {
|
struct ClientWhitelistEntry {
|
||||||
last_seen_ts: u64,
|
last_seen_ts: u64,
|
||||||
}
|
}
|
||||||
@ -364,7 +365,6 @@ impl NetworkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
|
||||||
pub fn purge_client_whitelist(&self) {
|
pub fn purge_client_whitelist(&self) {
|
||||||
let timeout_ms = self.config.get().network.client_whitelist_timeout_ms;
|
let timeout_ms = self.config.get().network.client_whitelist_timeout_ms;
|
||||||
let mut inner = self.inner.lock();
|
let mut inner = self.inner.lock();
|
||||||
@ -376,7 +376,8 @@ impl NetworkManager {
|
|||||||
.map(|v| v.1.last_seen_ts < cutoff_timestamp)
|
.map(|v| v.1.last_seen_ts < cutoff_timestamp)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
{
|
{
|
||||||
inner.client_whitelist.remove_lru();
|
let (k, v) = inner.client_whitelist.remove_lru().unwrap();
|
||||||
|
trace!(key=?k, value=?v, "purge_client_whitelist: remove_lru")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ tracing-appender = "^0"
|
|||||||
tracing-opentelemetry = "^0"
|
tracing-opentelemetry = "^0"
|
||||||
opentelemetry = { version = "^0", features = ["rt-async-std"] }
|
opentelemetry = { version = "^0", features = ["rt-async-std"] }
|
||||||
opentelemetry-otlp = { version = "^0", features = ["grpc-sys"] }
|
opentelemetry-otlp = { version = "^0", features = ["grpc-sys"] }
|
||||||
|
opentelemetry-semantic-conventions = "^0"
|
||||||
clap = "^3"
|
clap = "^3"
|
||||||
async-std = { version = "^1", features = ["unstable"] }
|
async-std = { version = "^1", features = ["unstable"] }
|
||||||
async-tungstenite = { version = "^0", features = ["async-std-runtime", "async-tls"] }
|
async-tungstenite = { version = "^0", features = ["async-std-runtime", "async-tls"] }
|
||||||
@ -38,6 +39,7 @@ lazy_static = "^1"
|
|||||||
bugsalot = "^0"
|
bugsalot = "^0"
|
||||||
flume = { version = "^0", features = ["async"] }
|
flume = { version = "^0", features = ["async"] }
|
||||||
rpassword = "^6"
|
rpassword = "^6"
|
||||||
|
hostname = "^0"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows-service = "^0"
|
windows-service = "^0"
|
||||||
|
@ -66,7 +66,7 @@ fn do_clap_matches(default_config_path: &OsStr) -> Result<clap::ArgMatches, clap
|
|||||||
.long("otlp")
|
.long("otlp")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("endpoint")
|
.value_name("endpoint")
|
||||||
.default_missing_value("http://localhost:4317")
|
.default_missing_value("localhost:4317")
|
||||||
.help("Turn on OpenTelemetry tracing"),
|
.help("Turn on OpenTelemetry tracing"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@ -207,15 +207,13 @@ pub fn process_command_line() -> Result<(Settings, ArgMatches), String> {
|
|||||||
}
|
}
|
||||||
if matches.occurrences_of("otlp") != 0 {
|
if matches.occurrences_of("otlp") != 0 {
|
||||||
settingsrw.logging.otlp.enabled = true;
|
settingsrw.logging.otlp.enabled = true;
|
||||||
settingsrw.logging.otlp.grpc_endpoint = Some(
|
settingsrw.logging.otlp.grpc_endpoint = NamedSocketAddrs::from_str(
|
||||||
ParsedUrl::from_str(
|
|
||||||
&matches
|
&matches
|
||||||
.value_of("otlp")
|
.value_of("otlp")
|
||||||
.expect("should not be null because of default missing value")
|
.expect("should not be null because of default missing value")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
.map_err(|e| format!("failed to parse OTLP url: {}", e))?,
|
.map_err(|e| format!("failed to parse OTLP address: {}", e))?;
|
||||||
);
|
|
||||||
settingsrw.logging.otlp.level = LogLevel::Trace;
|
settingsrw.logging.otlp.level = LogLevel::Trace;
|
||||||
}
|
}
|
||||||
if matches.is_present("attach") {
|
if matches.is_present("attach") {
|
||||||
|
@ -39,7 +39,7 @@ logging:
|
|||||||
otlp:
|
otlp:
|
||||||
enabled: false
|
enabled: false
|
||||||
level: 'trace'
|
level: 'trace'
|
||||||
grpc_endpoint: 'http://localhost:4317'
|
grpc_endpoint: 'localhost:4317'
|
||||||
testing:
|
testing:
|
||||||
subnode_index: 0
|
subnode_index: 0
|
||||||
core:
|
core:
|
||||||
@ -435,7 +435,7 @@ pub struct Api {
|
|||||||
pub struct Otlp {
|
pub struct Otlp {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub level: LogLevel,
|
pub level: LogLevel,
|
||||||
pub grpc_endpoint: Option<ParsedUrl>,
|
pub grpc_endpoint: NamedSocketAddrs,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
@ -1423,7 +1423,7 @@ mod tests {
|
|||||||
assert_eq!(s.logging.otlp.level, LogLevel::Trace);
|
assert_eq!(s.logging.otlp.level, LogLevel::Trace);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
s.logging.otlp.grpc_endpoint,
|
s.logging.otlp.grpc_endpoint,
|
||||||
Some(ParsedUrl::from_str("http://127.0.0.1:4317").unwrap())
|
NamedSocketAddrs::from_str("localhost:4317").unwrap()
|
||||||
);
|
);
|
||||||
assert_eq!(s.testing.subnode_index, 0);
|
assert_eq!(s.testing.subnode_index, 0);
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
use crate::settings::*;
|
use crate::settings::*;
|
||||||
use cfg_if::*;
|
use cfg_if::*;
|
||||||
|
use opentelemetry::sdk::*;
|
||||||
|
use opentelemetry::*;
|
||||||
use opentelemetry_otlp::WithExportConfig;
|
use opentelemetry_otlp::WithExportConfig;
|
||||||
use std::path::*;
|
use std::path::*;
|
||||||
use tracing::*;
|
use tracing::*;
|
||||||
@ -61,12 +63,7 @@ impl VeilidLogs {
|
|||||||
convert_loglevel(settingsr.logging.otlp.level)
|
convert_loglevel(settingsr.logging.otlp.level)
|
||||||
.to_tracing_level()
|
.to_tracing_level()
|
||||||
.into();
|
.into();
|
||||||
let grpc_endpoint = match &settingsr.logging.otlp.grpc_endpoint {
|
let grpc_endpoint = settingsr.logging.otlp.grpc_endpoint.name.clone();
|
||||||
Some(v) => &v.urlstring,
|
|
||||||
None => {
|
|
||||||
return Err("missing OTLP GRPC endpoint url".to_owned());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Required for GRPC dns resolution to work
|
// Required for GRPC dns resolution to work
|
||||||
std::env::set_var("GRPC_DNS_RESOLVER", "native");
|
std::env::set_var("GRPC_DNS_RESOLVER", "native");
|
||||||
@ -78,6 +75,17 @@ impl VeilidLogs {
|
|||||||
.grpcio()
|
.grpcio()
|
||||||
.with_endpoint(grpc_endpoint),
|
.with_endpoint(grpc_endpoint),
|
||||||
)
|
)
|
||||||
|
.with_trace_config(opentelemetry::sdk::trace::config().with_resource(
|
||||||
|
Resource::new(vec![KeyValue::new(
|
||||||
|
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
|
||||||
|
format!(
|
||||||
|
"veilid_server:{}",
|
||||||
|
hostname::get()
|
||||||
|
.map(|s| s.to_string_lossy().into_owned())
|
||||||
|
.unwrap_or_else(|_| "unknown".to_owned())
|
||||||
|
),
|
||||||
|
)]),
|
||||||
|
))
|
||||||
.install_batch(opentelemetry::runtime::AsyncStd)
|
.install_batch(opentelemetry::runtime::AsyncStd)
|
||||||
.map_err(|e| format!("failed to install OpenTelemetry tracer: {}", e))?;
|
.map_err(|e| format!("failed to install OpenTelemetry tracer: {}", e))?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user