Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Caleb: added logging improvement

Caleb Pefferb361a76282e8
diff --git a/.gitignore b/.gitignore
index cbfb076f2..90290129d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@
dump.rdb
/mongo-data
apps/js-sdk/node_modules/
+
+apps/api/.env.local
diff --git a/apps/api/.env.local b/apps/api/.env.local
deleted file mode 100644
index f5c625f21..000000000
--- a/apps/api/.env.local
+++ /dev/null
@@ -1,14 +0,0 @@
-NUM_WORKERS_PER_QUEUE=8
-PORT=
-HOST=
-SUPABASE_ANON_TOKEN=
-SUPABASE_URL=
-SUPABASE_SERVICE_TOKEN=
-REDIS_URL=
-SCRAPING_BEE_API_KEY=
-OPENAI_API_KEY=
-BULL_AUTH_KEY=
-LOGTAIL_KEY=
-PLAYWRIGHT_MICROSERVICE_URL=
-LLAMAPARSE_API_KEY=
-TEST_API_KEY=
\ No newline at end of file
diff --git a/apps/api/src/__tests__/e2e/index.test.ts b/apps/api/src/__tests__/e2e/index.test.ts
index 554453b26..ebf87c6e5 100644
--- a/apps/api/src/__tests__/e2e/index.test.ts
+++ b/apps/api/src/__tests__/e2e/index.test.ts
@@ -3,12 +3,20 @@ import { app } from '../../index';
import dotenv from 'dotenv';
dotenv.config();
-const TEST_URL = 'http://localhost:3002'
+
+// const TEST_URL = 'http://localhost:3002'
+const TEST_URL = 'http://127.0.0.1:3002'
+
+
+
+
describe('E2E Tests for API Routes', () => {
describe('GET /', () => {
it('should return Hello, world! message', async () => {
- const response = await request(TEST_URL).get('/');
+
+ const response = await request(TEST_URL).get('/');
+
expect(response.statusCode).toBe(200);
expect(response.text).toContain('SCRAPERS-JS: Hello, world! Fly.io');
});
@@ -16,6 +24,8 @@ describe('E2E Tests for API Routes', () => {
describe('GET /test', () => {
it('should return Hello, world! message', async () => {
+
+
const response = await request(TEST_URL).get('/test');
expect(response.statusCode).toBe(200);
expect(response.text).toContain('Hello, world!');
diff --git a/apps/api/src/services/logtail.ts b/apps/api/src/services/logtail.ts
index 19ab7730b..8b86a6b1e 100644
--- a/apps/api/src/services/logtail.ts
+++ b/apps/api/src/services/logtail.ts
@@ -1,4 +1,19 @@
-const { Logtail } = require("@logtail/node");
-//dot env
-require("dotenv").config();
-export const logtail = new Logtail(process.env.LOGTAIL_KEY);
+import { Logtail } from "@logtail/node";
+import "dotenv/config";
+
+// A mock Logtail class to handle cases where LOGTAIL_KEY is not provided
+class MockLogtail {
+ info(message: string, context?: Record<string, any>): void {
+ console.log(message, context);
+ }
+ error(message: string, context: Record<string, any> = {}): void {
+ console.error(message, context);
+ }
+}
+
+// Using the actual Logtail class if LOGTAIL_KEY exists, otherwise using the mock class
+// Additionally, print a warning to the terminal if LOGTAIL_KEY is not provided
+export const logtail = process.env.LOGTAIL_KEY ? new Logtail(process.env.LOGTAIL_KEY) : (() => {
+ console.warn("LOGTAIL_KEY is not provided - your events will not be logged. Using MockLogtail as a fallback. see logtail.ts for more.");
+ return new MockLogtail();
+})();