Skip to content

Commit d939259

Browse files
feat(instrumentation): add spans and agent_id context (#1143)
1 parent 552f98b commit d939259

File tree

34 files changed

+168
-207
lines changed

34 files changed

+168
-207
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent-control/src/agent_control/agent_control.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crossbeam::select;
2727
use opamp_client::StartedClient;
2828
use std::sync::Arc;
2929
use std::time::SystemTime;
30-
use tracing::{debug, error, info, warn};
30+
use tracing::{debug, error, info, instrument, warn};
3131

3232
pub struct AgentControl<S, O, HR, SL, DV>
3333
where
@@ -141,6 +141,7 @@ where
141141
// * Recreate the Final Agent using the Agent Type and the latest persisted config
142142
// * Build a Stopped Sub Agent
143143
// * Run the Sub Agent and add it to the Running Sub Agents
144+
#[instrument(skip_all)]
144145
pub(super) fn recreate_sub_agent(
145146
&self,
146147
agent_identity: &AgentIdentity,
@@ -149,12 +150,10 @@ where
149150
>,
150151
) -> Result<(), AgentError> {
151152
running_sub_agents.stop_and_remove(&agent_identity.id)?;
152-
153153
self.build_and_run_sub_agent(agent_identity, running_sub_agents)
154154
}
155155

156-
// build_sub_agents returns a collection of started sub agents given the corresponding
157-
// EffectiveAgents
156+
// build_sub_agents returns a collection of started sub agents
158157
fn build_and_run_sub_agents(
159158
&self,
160159
sub_agents: &SubAgentsMap,
@@ -250,6 +249,7 @@ where
250249
}
251250
}
252251

252+
#[instrument(skip_all)]
253253
// apply an agent control remote config
254254
pub(super) fn apply_remote_agent_control_config(
255255
&self,

agent-control/src/agent_control/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::opamp::instance_id;
1010
use crate::opamp::remote_config::RemoteConfigError;
1111
use crate::sub_agent::effective_agents_assembler::EffectiveAgentsAssemblerError;
1212
use crate::sub_agent::error::{SubAgentBuilderError, SubAgentCollectionError, SubAgentError};
13-
use crate::utils::thread_context::ThreadContextStopperError;
1413
use crate::values::yaml_config::YAMLConfigError;
1514
use crate::values::yaml_config_repository::YAMLConfigRepositoryError;
1615
use fs::file_reader::FileReaderError;

agent-control/src/agent_control/event_handler/opamp/remote_config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use opamp_client::StartedClient;
2-
use tracing::{error, info};
3-
41
use crate::agent_control::config_storer::loader_storer::{
52
AgentControlDynamicConfigDeleter, AgentControlDynamicConfigLoader,
63
AgentControlDynamicConfigStorer,
@@ -13,6 +10,8 @@ use crate::{
1310
opamp::{hash_repository::HashRepository, remote_config::RemoteConfig},
1411
sub_agent::{collection::StartedSubAgents, NotStartedSubAgent, SubAgentBuilder},
1512
};
13+
use opamp_client::StartedClient;
14+
use tracing::{error, info};
1615

1716
impl<S, O, HR, SL, DV> AgentControl<S, O, HR, SL, DV>
1817
where
@@ -38,7 +37,7 @@ where
3837
unreachable!("got remote config without OpAMP being enabled");
3938
};
4039

41-
info!(agent_id=%remote_config.agent_id, "Applying remote config");
40+
info!("Applying remote config");
4241
OpampRemoteConfigStatus::Applying.report(opamp_client, &remote_config.hash)?;
4342

4443
match self.apply_remote_agent_control_config(&remote_config, sub_agents) {

agent-control/src/instrumentation/config/otel.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ const DEFAULT_BATCH_SCHEDULED_DELAY: Duration = Duration::from_secs(30);
1919
const TRACES_SUFFIX: &str = "/v1/traces";
2020
/// Metrics suffix for the OpenTelemetry endpoint
2121
const METRICS_SUFFIX: &str = "/v1/metrics";
22-
/// Logs suffix for the OpenTelemetry endpoint
23-
const LOGS_SUFFIX: &str = "/v1/logs";
2422

2523
/// Represents the OpenTelemetry configuration
2624
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]

agent-control/src/k8s/garbage_collector.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::utils::thread_context::{NotStartedThreadContext, StartedThreadContext
1818
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
1919
use kube::api::TypeMeta;
2020
use std::{sync::Arc, time::Duration};
21-
use tracing::{debug, error, info, trace, warn};
21+
use tracing::{debug, error, info, instrument, trace, warn};
2222

2323
const THREAD_NAME: &str = "Garbage collector";
2424

@@ -106,6 +106,7 @@ where
106106
/// Garbage collect all resources managed by the SA associated to removed sub-agents.
107107
/// Collection is stateful, only happens when the list of active agents has changed from
108108
/// the previous execution.
109+
#[instrument(skip_all, name = "garbage_collector_collect")]
109110
pub fn collect(&mut self) -> Result<(), GarbageCollectorK8sError> {
110111
// check if current active agents differs from previous execution.
111112
if !self.update_active_config()? {

agent-control/src/opamp/client_builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,13 @@ where
9292
) -> Result<Self::Client, OpAMPClientBuilderError> {
9393
let http_client = self.http_client_builder.build()?;
9494
let effective_config_loader = self.effective_config_loader_builder.build(agent_id.clone());
95-
let callbacks =
96-
AgentCallbacks::new(agent_id.clone(), opamp_publisher, effective_config_loader);
95+
let callbacks = AgentCallbacks::new(agent_id, opamp_publisher, effective_config_loader);
9796
let not_started_client = NotStartedHttpClient::new(http_client, callbacks, start_settings)?;
9897
let mut not_started_client = not_started_client.with_interval(self.poll_interval);
9998
if self.disable_startup_check {
10099
not_started_client = not_started_client.with_startup_check_disabled();
101100
}
102-
info!(%agent_id,"OpAMP client started");
101+
info!("OpAMP client started");
103102
Ok(not_started_client.start()?)
104103
}
105104
}

agent-control/src/opamp/instance_id/getter.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ where
4242
{
4343
fn get(&self, agent_id: &AgentID) -> Result<InstanceID, GetterError> {
4444
let storer = self.storer.lock().expect("failed to acquire the lock");
45-
debug!(%agent_id, "retrieving instance id");
45+
debug!("retrieving instance id");
4646
let data = storer.get(agent_id)?;
4747

4848
match data {
4949
None => {
50-
debug!(%agent_id, "storer returned no data");
50+
debug!("storer returned no data");
5151
}
5252
Some(d) if d.identifiers == self.identifiers => return Ok(d.instance_id),
5353
Some(d) => debug!(
54-
%agent_id,
5554
"stored data had different identifiers {:?}!={:?}",
5655
d.identifiers, self.identifiers
5756
),
@@ -62,7 +61,7 @@ where
6261
identifiers: self.identifiers.clone(),
6362
};
6463

65-
debug!(%agent_id, "persisting instance id {}", new_data.instance_id);
64+
debug!("persisting instance id {}", new_data.instance_id);
6665
storer.set(agent_id, &new_data)?;
6766

6867
Ok(new_data.instance_id)

agent-control/src/opamp/instance_id/on_host/getter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::opamp::instance_id::on_host::storer::StorerError;
33
use resource_detection::cloud::aws::detector::{
44
AWSDetector, AWS_IPV4_METADATA_ENDPOINT, AWS_IPV4_METADATA_TOKEN_ENDPOINT,
55
};
6-
use resource_detection::cloud::aws::http_client::AWSHttpClient;
76
use resource_detection::cloud::azure::detector::{AzureDetector, AZURE_IPV4_METADATA_ENDPOINT};
87
use resource_detection::cloud::cloud_id::detector::CloudIdDetector;
98
use resource_detection::cloud::gcp::detector::{GCPDetector, GCP_IPV4_METADATA_ENDPOINT};

agent-control/src/sub_agent/collection.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ impl<S> StartedSubAgents<S>
1111
where
1212
S: StartedSubAgent,
1313
{
14+
#[tracing::instrument(skip_all)]
1415
pub(crate) fn stop_and_remove(
1516
&mut self,
1617
agent_id: &AgentID,
@@ -22,8 +23,8 @@ where
2223
agent_id.to_string(),
2324
))?;
2425

25-
info!(%agent_id, "Stopping sub agent");
26-
Self::stop_sub_agent(sub_agent, agent_id);
26+
info!("Stopping sub agent");
27+
Self::stop_sub_agent(sub_agent);
2728

2829
Ok(())
2930
}
@@ -34,16 +35,17 @@ where
3435
}
3536

3637
pub(crate) fn stop(self) {
37-
self.0.into_iter().for_each(|(agent_id, sub_agent)| {
38-
info!(%agent_id, "Stopping sub agent");
39-
Self::stop_sub_agent(sub_agent, &agent_id);
38+
self.0.into_iter().for_each(|(_, sub_agent)| {
39+
info!("Stopping sub agent");
40+
Self::stop_sub_agent(sub_agent);
4041
})
4142
}
4243

43-
fn stop_sub_agent(sub_agent: S, agent_id: &AgentID) {
44+
#[tracing::instrument(skip_all)]
45+
fn stop_sub_agent(sub_agent: S) {
4446
let _ = sub_agent
4547
.stop()
46-
.inspect_err(|err| error!(%agent_id, %err, "Error stopping sub agent"));
48+
.inspect_err(|err| error!(%err, "Error stopping sub agent"));
4749
}
4850
}
4951

0 commit comments

Comments
 (0)