Skip to content

Commit

Permalink
Dropped Vercel's log drain utilization
Browse files Browse the repository at this point in the history
  • Loading branch information
dasfmi committed Aug 7, 2024
1 parent e495e17 commit 8614c9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
9 changes: 0 additions & 9 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions tests/vercelConfig.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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',
Expand All @@ -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);
});

0 comments on commit 8614c9a

Please sign in to comment.