mirror of
https://github.com/moeru-ai/airi.git
synced 2026-05-19 08:10:45 +00:00
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import process, { env } from 'node:process'
|
|
|
|
import { Format, LogLevel, setGlobalFormat, setGlobalLogLevel, useLogg } from '@guiiai/logg'
|
|
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'
|
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'
|
|
import { resourceFromAttributes } from '@opentelemetry/resources'
|
|
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'
|
|
import { NodeSDK } from '@opentelemetry/sdk-node'
|
|
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions'
|
|
|
|
import { startTelegramBot } from './bots/telegram'
|
|
import { initDb } from './db'
|
|
|
|
setGlobalFormat(Format.Pretty)
|
|
setGlobalLogLevel(LogLevel.Debug)
|
|
|
|
async function main() {
|
|
const sdk = new NodeSDK({
|
|
resource: resourceFromAttributes({
|
|
[ATTR_SERVICE_NAME]: 'moeru_ai.airi.telegram_bot',
|
|
[ATTR_SERVICE_VERSION]: '1.0.0',
|
|
}),
|
|
traceExporter: new OTLPTraceExporter({
|
|
url: env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT || 'http://localhost:4318/v1/traces',
|
|
}),
|
|
metricReader: new PeriodicExportingMetricReader({
|
|
exporter: new OTLPMetricExporter({
|
|
url: env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT || 'http://localhost:4318/v1/metrics',
|
|
}),
|
|
exportIntervalMillis: 5000,
|
|
}),
|
|
})
|
|
|
|
sdk.start()
|
|
|
|
await initDb()
|
|
await startTelegramBot()
|
|
}
|
|
|
|
process.on('unhandledRejection', (err) => {
|
|
const log = useLogg('UnhandledRejection').useGlobalConfig()
|
|
log
|
|
.withError(err)
|
|
.withField('cause', (err as any).cause)
|
|
.error('Unhandled rejection')
|
|
})
|
|
|
|
main().catch(console.error)
|