From 8614c9a8c83d2f45d84beffbe504ea057cfac532 Mon Sep 17 00:00:00 2001 From: Islam Shehata Date: Wed, 7 Aug 2024 12:57:53 +0300 Subject: [PATCH] Dropped Vercel's log drain utilization --- src/logger.ts | 9 --------- tests/vercelConfig.test.ts | 18 ++++++++---------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 2733c290..3aefb389 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -208,15 +208,6 @@ export class Logger { return; } - // if vercel integration is enabled, we can utilize the log drain - // to send logs to Axiom without HTTP. - // This saves resources and time on lambda and edge functions - if (isVercelIntegration && (this.config.source === 'edge-log' || this.config.source === 'lambda-log')) { - this.logEvents.forEach((ev) => console.log(JSON.stringify(ev))); - this.logEvents = []; - return; - } - const method = 'POST'; const keepalive = true; const body = JSON.stringify(this.logEvents); diff --git a/tests/vercelConfig.test.ts b/tests/vercelConfig.test.ts index ba4a94ad..188efddb 100644 --- a/tests/vercelConfig.test.ts +++ b/tests/vercelConfig.test.ts @@ -1,5 +1,5 @@ import { test, expect, vi } from 'vitest'; -import { config, isVercelIntegration } from '../src/config'; +import { config } from '../src/config'; import { EndpointType } from '../src/shared'; import { Logger } from '../src/logger'; @@ -16,10 +16,13 @@ test('reading vercel ingest endpoint', () => { expect(url).toEqual('https://api.axiom.co/v1/integrations/vercel?type=logs'); }); -test('logging to console when running on lambda', async () => { +test('logging to Axiom when running on lambda', async () => { vi.useFakeTimers(); const mockedConsole = vi.spyOn(console, 'log'); - const time = new Date(Date.now()).toISOString(); + global.fetch = vi.fn(async () => { + const resp = new Response('', { status: 200 }); + return Promise.resolve(resp); + }); const logger = new Logger({ source: 'lambda-log', @@ -28,11 +31,6 @@ test('logging to console when running on lambda', async () => { logger.info('hello, world!'); await logger.flush(); - expect(mockedConsole).toHaveBeenCalledTimes(1); - - const calledWithPayload = JSON.parse(mockedConsole.mock.calls[0][0]); - expect(calledWithPayload.message).toEqual('hello, world!'); - expect(calledWithPayload.level).toEqual('info'); - expect(calledWithPayload._time).toEqual(time); - expect(calledWithPayload.vercel.source).toEqual('lambda-log'); + expect(mockedConsole).toHaveBeenCalledTimes(0); + expect(fetch).toHaveBeenCalledTimes(1); });