Skip to content

Commit

Permalink
Merge pull request #792 from saschagrunert/tracing-pid
Browse files Browse the repository at this point in the history
Add conmon-rs process ID and host name to tracing output
  • Loading branch information
openshift-merge-robot authored Oct 11, 2022
2 parents 06cb619 + d4ed008 commit 7fe60f6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions conmon-rs/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ nix = "0.25.0"
notify = "5.0.0"
opentelemetry = { version = "0.18.0", features = ["rt-tokio"] }
opentelemetry-otlp = "0.11.0"
opentelemetry-semantic-conventions = "0.10.0"
prctl = "1.0.0"
regex = "1.6.0"
sendfd = { version = "0.4.3", features = ["tokio"] }
Expand Down
26 changes: 16 additions & 10 deletions conmon-rs/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use nix::{
errno,
libc::_exit,
sys::signal::Signal,
unistd::{fork, ForkResult},
unistd::{fork, gethostname, ForkResult},
};
use opentelemetry::{
global,
Expand All @@ -30,9 +30,9 @@ use opentelemetry::{
trace::{self, Tracer},
Resource,
},
KeyValue,
};
use opentelemetry_otlp::{ExportConfig, Protocol, WithExportConfig};
use opentelemetry_semantic_conventions::resource::{HOST_NAME, PROCESS_PID, SERVICE_NAME};
use std::{fs::File, io::Write, path::Path, process, str::FromStr, sync::Arc, time::Duration};
use tokio::{
fs,
Expand Down Expand Up @@ -170,14 +170,20 @@ impl Server {
timeout: Duration::from_secs(3),
protocol: Protocol::Grpc,
});
let tracer =
opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(exporter)
.with_trace_config(trace::config().with_resource(Resource::new(vec![
KeyValue::new("service.name", crate_name!()),
])))
.install_batch(Tokio)?;
let hostname = gethostname()
.context("get hostname")?
.to_str()
.context("convert hostname to string")?
.to_string();
let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(exporter)
.with_trace_config(trace::config().with_resource(Resource::new(vec![
SERVICE_NAME.string(crate_name!()),
PROCESS_PID.i64(process::id() as i64),
HOST_NAME.string(hostname),
])))
.install_batch(Tokio)?;

Ok(tracing_opentelemetry::layer().with_tracer(tracer).into())
}
Expand Down

0 comments on commit 7fe60f6

Please sign in to comment.