This commit is contained in:
John Smith
2022-06-15 15:03:13 -04:00
parent c33f78ac8b
commit a3e43ef68b
6 changed files with 41 additions and 21 deletions

View File

@@ -17,6 +17,7 @@ tracing-appender = "^0"
tracing-opentelemetry = "^0"
opentelemetry = { version = "^0", features = ["rt-async-std"] }
opentelemetry-otlp = { version = "^0", features = ["grpc-sys"] }
opentelemetry-semantic-conventions = "^0"
clap = "^3"
async-std = { version = "^1", features = ["unstable"] }
async-tungstenite = { version = "^0", features = ["async-std-runtime", "async-tls"] }
@@ -38,6 +39,7 @@ lazy_static = "^1"
bugsalot = "^0"
flume = { version = "^0", features = ["async"] }
rpassword = "^6"
hostname = "^0"
[target.'cfg(windows)'.dependencies]
windows-service = "^0"

View File

@@ -66,7 +66,7 @@ fn do_clap_matches(default_config_path: &OsStr) -> Result<clap::ArgMatches, clap
.long("otlp")
.takes_value(true)
.value_name("endpoint")
.default_missing_value("http://localhost:4317")
.default_missing_value("localhost:4317")
.help("Turn on OpenTelemetry tracing"),
)
.arg(
@@ -207,15 +207,13 @@ pub fn process_command_line() -> Result<(Settings, ArgMatches), String> {
}
if matches.occurrences_of("otlp") != 0 {
settingsrw.logging.otlp.enabled = true;
settingsrw.logging.otlp.grpc_endpoint = Some(
ParsedUrl::from_str(
&matches
.value_of("otlp")
.expect("should not be null because of default missing value")
.to_string(),
)
.map_err(|e| format!("failed to parse OTLP url: {}", e))?,
);
settingsrw.logging.otlp.grpc_endpoint = NamedSocketAddrs::from_str(
&matches
.value_of("otlp")
.expect("should not be null because of default missing value")
.to_string(),
)
.map_err(|e| format!("failed to parse OTLP address: {}", e))?;
settingsrw.logging.otlp.level = LogLevel::Trace;
}
if matches.is_present("attach") {

View File

@@ -39,7 +39,7 @@ logging:
otlp:
enabled: false
level: 'trace'
grpc_endpoint: 'http://localhost:4317'
grpc_endpoint: 'localhost:4317'
testing:
subnode_index: 0
core:
@@ -435,7 +435,7 @@ pub struct Api {
pub struct Otlp {
pub enabled: bool,
pub level: LogLevel,
pub grpc_endpoint: Option<ParsedUrl>,
pub grpc_endpoint: NamedSocketAddrs,
}
#[derive(Debug, Deserialize, Serialize)]
@@ -1423,7 +1423,7 @@ mod tests {
assert_eq!(s.logging.otlp.level, LogLevel::Trace);
assert_eq!(
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);

View File

@@ -1,5 +1,7 @@
use crate::settings::*;
use cfg_if::*;
use opentelemetry::sdk::*;
use opentelemetry::*;
use opentelemetry_otlp::WithExportConfig;
use std::path::*;
use tracing::*;
@@ -61,12 +63,7 @@ impl VeilidLogs {
convert_loglevel(settingsr.logging.otlp.level)
.to_tracing_level()
.into();
let grpc_endpoint = match &settingsr.logging.otlp.grpc_endpoint {
Some(v) => &v.urlstring,
None => {
return Err("missing OTLP GRPC endpoint url".to_owned());
}
};
let grpc_endpoint = settingsr.logging.otlp.grpc_endpoint.name.clone();
// Required for GRPC dns resolution to work
std::env::set_var("GRPC_DNS_RESOLVER", "native");
@@ -78,6 +75,17 @@ impl VeilidLogs {
.grpcio()
.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)
.map_err(|e| format!("failed to install OpenTelemetry tracer: {}", e))?;