feat(observability): add structured pino logging

This commit is contained in:
2026-03-09 01:03:08 +04:00
parent 0ed22641ec
commit 8645a0a096
14 changed files with 279 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
export interface BotRuntimeConfig {
port: number
logLevel: 'debug' | 'info' | 'warn' | 'error'
telegramBotToken: string
telegramWebhookSecret: string
telegramWebhookPath: string
@@ -33,6 +34,25 @@ function parsePort(raw: string | undefined): number {
return parsed
}
function parseLogLevel(raw: string | undefined): 'debug' | 'info' | 'warn' | 'error' {
if (raw === undefined) {
return 'info'
}
const normalized = raw.trim().toLowerCase()
if (
normalized === 'debug' ||
normalized === 'info' ||
normalized === 'warn' ||
normalized === 'error'
) {
return normalized
}
throw new Error(`Invalid LOG_LEVEL value: ${raw}`)
}
function requireValue(value: string | undefined, key: string): string {
if (!value || value.trim().length === 0) {
throw new Error(`${key} environment variable is required`)
@@ -103,6 +123,7 @@ export function getBotRuntimeConfig(env: NodeJS.ProcessEnv = process.env): BotRu
const runtime: BotRuntimeConfig = {
port: parsePort(env.PORT),
logLevel: parseLogLevel(env.LOG_LEVEL),
telegramBotToken: requireValue(env.TELEGRAM_BOT_TOKEN, 'TELEGRAM_BOT_TOKEN'),
telegramWebhookSecret: requireValue(env.TELEGRAM_WEBHOOK_SECRET, 'TELEGRAM_WEBHOOK_SECRET'),
telegramWebhookPath: env.TELEGRAM_WEBHOOK_PATH ?? '/webhook/telegram',