replace logtail with baselime
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
dd53a5757a
commit
971e645bdd
@@ -23,9 +23,7 @@ const port = parseInt(process.env.API_PORT || '3000', 10);
|
||||
const startServer = async () => {
|
||||
logInfo('Starting server');
|
||||
try {
|
||||
const fastify = Fastify({
|
||||
logger: logger,
|
||||
});
|
||||
const fastify = Fastify();
|
||||
|
||||
fastify.register(cors, {
|
||||
origin: '*',
|
||||
@@ -38,7 +36,7 @@ const startServer = async () => {
|
||||
fastify.register(miscRouter, { prefix: '/misc' });
|
||||
fastify.register(exportRouter, { prefix: '/export' });
|
||||
fastify.setErrorHandler((error) => {
|
||||
fastify.log.error(error);
|
||||
logger.error(error, 'Error in request');
|
||||
});
|
||||
fastify.get('/', (_request, reply) => {
|
||||
reply.send({ name: 'openpanel sdk api' });
|
||||
@@ -70,7 +68,7 @@ const startServer = async () => {
|
||||
// Notify when keys expires
|
||||
redisPub.config('SET', 'notify-keyspace-events', 'Ex');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
logger.error(e, 'Failed to start server');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { isBot } from '@/bots';
|
||||
import * as controller from '@/controllers/event.controller';
|
||||
import { validateSdkRequest } from '@/utils/auth';
|
||||
import { logger } from '@/utils/logger';
|
||||
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
|
||||
|
||||
import { createBotEvent } from '@openpanel/db';
|
||||
@@ -17,7 +18,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||
) => {
|
||||
try {
|
||||
const projectId = await validateSdkRequest(req.headers).catch(
|
||||
req.log.error
|
||||
logger.error
|
||||
);
|
||||
if (!projectId) {
|
||||
return reply.status(401).send();
|
||||
@@ -31,7 +32,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||
if (bot) {
|
||||
const path = (req.body?.properties?.__path ||
|
||||
req.body?.properties?.path) as string | undefined;
|
||||
req.log.warn({ ...req.headers, bot }, 'Bot detected (event)');
|
||||
logger.warn({ ...req.headers, bot }, 'Bot detected (event)');
|
||||
await createBotEvent({
|
||||
...bot,
|
||||
projectId,
|
||||
@@ -41,7 +42,7 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||
reply.status(202).send('OK');
|
||||
}
|
||||
} catch (e) {
|
||||
req.log.error(e, 'Failed to create bot event');
|
||||
logger.error(e, 'Failed to create bot event');
|
||||
reply.status(401).send();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { isBot } from '@/bots';
|
||||
import * as controller from '@/controllers/profile.controller';
|
||||
import { validateSdkRequest } from '@/utils/auth';
|
||||
import { logger } from '@/utils/logger';
|
||||
import type { FastifyPluginCallback } from 'fastify';
|
||||
|
||||
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||
fastify.addHook('preHandler', async (req, reply) => {
|
||||
try {
|
||||
const projectId = await validateSdkRequest(req.headers).catch(
|
||||
req.log.error
|
||||
logger.error
|
||||
);
|
||||
if (!projectId) {
|
||||
return reply.status(401).send();
|
||||
|
||||
@@ -5,8 +5,8 @@ const targets: TransportTargetOptions[] =
|
||||
process.env.NODE_ENV === 'production'
|
||||
? [
|
||||
{
|
||||
target: '@logtail/pino',
|
||||
options: { sourceToken: process.env.BETTERSTACK_TOKEN },
|
||||
target: '@baselime/pino-transport',
|
||||
options: { baselimeApiKey: process.env.BASELIME_API_KEY },
|
||||
},
|
||||
]
|
||||
: [
|
||||
|
||||
Reference in New Issue
Block a user