Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

Fix: host.docker.internal not available outside of Docker Desktop (#143)

Marc Klingen87f21407c9f2
diff --git a/cron.js b/cron.js
index e07876d6fb..bec96d381d 100644
--- a/cron.js
+++ b/cron.js
@@ -1,16 +1,38 @@
var CronJob = require("cron").CronJob;
+var os = require("os");
-// var job = new CronJob(
-// "*/5 * * * *", // Every 5 minutes
-// function () {
-// fetch("http://host.docker.internal:3000/api/cron/telemetry").catch((err) =>
-// console.log(err),
-// );
-// },
-// );
+try {
+ // get internal ip address
+ var networkInterfaces = os.networkInterfaces();
+ console.log("CRON: fetched network interfaces", networkInterfaces);
+ var ip = undefined;
-// if (
-// process.env.TELEMETRY_ENABLED === undefined ||
-// process.env.TELEMETRY_ENABLED === "true"
-// )
-// job.start();
+ if ("eth0" in networkInterfaces) {
+ var ipaddresses = networkInterfaces["eth0"]
+ .filter((networkInterface) => networkInterface.family === "IPv4")
+ .map((networkInterface) => networkInterface.address);
+ if (ipaddresses.length > 0) {
+ ip = ipaddresses[0];
+ }
+ }
+ console.log("CRON: IP", ip);
+
+ if (ip) {
+ var job = new CronJob("*/5 * * * *", function () {
+ console.log("CRON: Sending telemetry");
+ fetch(`http://${ip}:3000/api/cron/telemetry`).catch((err) =>
+ console.log(err),
+ );
+ });
+
+ if (
+ process.env.TELEMETRY_ENABLED === undefined ||
+ process.env.TELEMETRY_ENABLED === "true"
+ )
+ job.start();
+ } else {
+ console.log("CRON: No ip address found, not starting cron job");
+ }
+} catch (err) {
+ console.log("CRON: Error", err);
+}
\ No newline at end of file