Skip to content

Commit

Permalink
feat: remove pyroscope
Browse files Browse the repository at this point in the history
  • Loading branch information
batleforc committed Aug 10, 2024
1 parent 20b8861 commit 70464d7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 44 deletions.
2 changes: 0 additions & 2 deletions libs/tool_tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ opentelemetry-otlp = { version = "0.16" }
tracing-opentelemetry = "0.24"
serde_json = "1.0"
tokio = { version = "1.39.2", features = ["rt-multi-thread", "macros"] }
pyroscope = "0.5.7"
pyroscope_pprofrs = "0.2.7"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
Expand Down
45 changes: 4 additions & 41 deletions libs/tool_tracing/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use super::tracing_kind::{Tracing, TracingKind};
use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{runtime, trace, Resource};
use pyroscope::pyroscope::PyroscopeAgentRunning;
use pyroscope::PyroscopeAgent;
use pyroscope_pprofrs::{pprof_backend, PprofConfig};
use std::{fs::File, sync::Arc, vec};
use time::format_description;
use tracing::level_filters::LevelFilter;
Expand All @@ -17,12 +14,8 @@ use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::{fmt, EnvFilter, Layer, Registry};

#[cfg_attr(coverage_nightly, coverage(off))]
pub fn init_tracing(
tracing_config: Vec<Tracing>,
name: String,
) -> Option<PyroscopeAgent<PyroscopeAgentRunning>> {
pub fn init_tracing(tracing_config: Vec<Tracing>, name: String) {
let mut layers = vec![];
let mut super_agent = None;
for config in tracing_config {
match config.kind {
TracingKind::File => {
Expand Down Expand Up @@ -81,47 +74,17 @@ pub fn init_tracing(
let tele_layer = OpenTelemetryLayer::new(telemetry).with_filter(env_filter);
layers.push(tele_layer.boxed());
}
TracingKind::Pprof => {
// ERROR ! pprof does not work yet
let sample_rate = match config.additional.get("sample_rate") {
Some(sample_rate) => {
sample_rate.parse().expect("sample_rate should be a number")
}
None => 100,
};
let backend_impl = pprof_backend(PprofConfig::new().sample_rate(sample_rate));
let pyro_url = match config.additional.get("pyroscope_url") {
Some(url) => url.to_string(),
None => "http://localhost:4040".to_string(),
};
let agent = match PyroscopeAgent::builder(pyro_url, name.clone())
.backend(backend_impl)
.build()
{
Ok(agent) => agent,
Err(e) => panic!("Failed to create pyroscope agent: {}", e),
};
super_agent = Some(agent.start().unwrap());
}
}
}
subscriber::set_global_default(Registry::default().with(layers))
.expect("setting default subscriber failed");
super_agent
}

#[cfg_attr(coverage_nightly, coverage(off))]
pub fn stop_tracing(
tracing_config: Vec<Tracing>,
_name: String,
super_agent: Option<PyroscopeAgent<PyroscopeAgentRunning>>,
) {
pub fn stop_tracing(tracing_config: Vec<Tracing>, _name: String) {
if tracing_config.iter().any(|x| x.kind == TracingKind::Otel) {
opentelemetry::global::shutdown_tracer_provider();
}
if tracing_config.iter().any(|x| x.kind == TracingKind::Pprof) {
super_agent.unwrap().shutdown();
}
}

#[cfg(test)]
Expand Down Expand Up @@ -156,11 +119,11 @@ mod tests {
tracing_config[2]
.additional
.insert("endpoint".to_string(), "http://localhost:4317".to_string());
let agent = init_tracing(tracing_config.clone(), "test".to_string());
init_tracing(tracing_config.clone(), "test".to_string());
tracing::info!("test part of test_init_tracing");
tracing::error!("test part of test_init_tracing");
tokio::spawn(async {
stop_tracing(tracing_config, "test".to_string(), agent);
stop_tracing(tracing_config, "test".to_string());
});
remove_file("trace.log").unwrap();
}
Expand Down
1 change: 0 additions & 1 deletion libs/tool_tracing/src/tracing_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub enum TracingKind {
File,
Console,
Otel,
Pprof,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
Expand Down

0 comments on commit 70464d7

Please sign in to comment.