Skip to content

Commit d9f0a7f

Browse files
committed
Add trace logs to background agent and api calls
1 parent e624f6a commit d9f0a7f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

agent_api/src/main/java/dev/aikido/agent_api/background/BackgroundProcess.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import dev.aikido.agent_api.background.cloud.api.events.Started;
88
import dev.aikido.agent_api.helpers.env.BlockingEnv;
99
import dev.aikido.agent_api.helpers.env.Token;
10+
import dev.aikido.agent_api.helpers.logging.LogManager;
11+
import dev.aikido.agent_api.helpers.logging.Logger;
1012
import dev.aikido.agent_api.storage.ServiceConfigStore;
1113

1214
import java.util.Optional;
@@ -22,6 +24,7 @@ public class BackgroundProcess extends Thread {
2224
private final static int API_TIMEOUT = 10; // 10 seconds
2325
private final Token token;
2426
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(3);
27+
private static final Logger logger = LogManager.getLogger(BackgroundProcess.class);
2528

2629
public BackgroundProcess(String name, Token token) {
2730
super(name);
@@ -33,6 +36,8 @@ public void run() {
3336
if (!Thread.currentThread().isDaemon() && token == null) {
3437
return; // Can only run if thread is daemon and token needs to be defined.
3538
}
39+
logger.trace("Starting agent thread: %s", Thread.currentThread());
40+
3641
ServiceConfigStore.updateBlocking(new BlockingEnv().getValue());
3742
ReportingApiHTTP api = new ReportingApiHTTP(getAikidoAPIEndpoint(), API_TIMEOUT, token);
3843
RealtimeAPI realtimeApi = new RealtimeAPI(token);
@@ -53,4 +58,4 @@ public void run() {
5358
// one time check to report initial stats
5459
scheduler.schedule(new HeartbeatTask(api, true), 60, TimeUnit.SECONDS);
5560
}
56-
}
61+
}

agent_api/src/main/java/dev/aikido/agent_api/background/cloud/api/ReportingApiHTTP.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public Optional<APIResponse> fetchNewConfig() {
4141

4242
// Send the request and get the response
4343
HttpResponse<String> httpResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
44+
logger.trace("Got response for %s: %s", uri.toString(), httpResponse.body());
4445
return Optional.of(toApiResponse(httpResponse));
4546
} catch (Exception e) {
4647
logger.debug("Error while fetching new config from cloud: %s", e.getMessage());
@@ -60,6 +61,7 @@ public Optional<APIResponse> report(APIEvent event) {
6061

6162
// Send the request and get the response
6263
HttpResponse<String> httpResponse = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
64+
logger.trace("Got response for %s: %s", uri.toString(), httpResponse.body());
6365
return Optional.of(toApiResponse(httpResponse));
6466
} catch (Exception e) {
6567
logger.debug("Error while communicating with cloud: %s", e.getMessage());

0 commit comments

Comments
 (0)