Caleb: added logging improvement

This commit is contained in:
Caleb Peffer 2024-04-20 19:53:04 -07:00
parent 389ac90f51
commit b361a76282
4 changed files with 33 additions and 20 deletions

2
.gitignore vendored
View File

@ -6,3 +6,5 @@
dump.rdb dump.rdb
/mongo-data /mongo-data
apps/js-sdk/node_modules/ apps/js-sdk/node_modules/
apps/api/.env.local

View File

@ -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=

View File

@ -3,12 +3,20 @@ import { app } from '../../index';
import dotenv from 'dotenv'; import dotenv from 'dotenv';
dotenv.config(); 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('E2E Tests for API Routes', () => {
describe('GET /', () => { describe('GET /', () => {
it('should return Hello, world! message', async () => { 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.statusCode).toBe(200);
expect(response.text).toContain('SCRAPERS-JS: Hello, world! Fly.io'); expect(response.text).toContain('SCRAPERS-JS: Hello, world! Fly.io');
}); });
@ -16,6 +24,8 @@ describe('E2E Tests for API Routes', () => {
describe('GET /test', () => { describe('GET /test', () => {
it('should return Hello, world! message', async () => { it('should return Hello, world! message', async () => {
const response = await request(TEST_URL).get('/test'); const response = await request(TEST_URL).get('/test');
expect(response.statusCode).toBe(200); expect(response.statusCode).toBe(200);
expect(response.text).toContain('Hello, world!'); expect(response.text).toContain('Hello, world!');

View File

@ -1,4 +1,19 @@
const { Logtail } = require("@logtail/node"); import { Logtail } from "@logtail/node";
//dot env import "dotenv/config";
require("dotenv").config();
export const logtail = new Logtail(process.env.LOGTAIL_KEY); // 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();
})();