diff --git a/package-lock.json b/package-lock.json index 9d745c3c..40ba848a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@grammyjs/auto-retry": "^1.1.1", "@myrotvorets/envalidators": "^2.1.0", "@myrotvorets/opentelemetry-configurator": "^7.0.0", + "@myrotvorets/otel-utils": "^1.1.1", "@opentelemetry/instrumentation-http": "^0.46.0", "@opentelemetry/instrumentation-knex": "^0.32.1", "debug": "^4.3.4", @@ -334,6 +335,15 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@myrotvorets/create-server": { + "version": "3.1.1", + "resolved": "https://npm.pkg.github.com/download/@myrotvorets/create-server/3.1.1/8be71c6eb5773e769490f939da6c7a15a1df2887", + "integrity": "sha512-1hkd5NS7ZqIXlrw8oG1dQbQ7uElE3u8YWNKG/R/CpRHbjylII621Q5/PIosXtoSvcyl63Z/WseX5CW7YuUz57Q==", + "license": "MIT", + "peerDependencies": { + "envalid": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/@myrotvorets/envalidators": { "version": "2.1.0", "resolved": "https://npm.pkg.github.com/download/@myrotvorets/envalidators/2.1.0/b639169c28020915e02bc05002e438abae0284e5", @@ -443,6 +453,20 @@ "@opentelemetry/semantic-conventions": "^1.17.0" } }, + "node_modules/@myrotvorets/otel-utils": { + "version": "1.1.1", + "resolved": "https://npm.pkg.github.com/download/@myrotvorets/otel-utils/1.1.1/c0045746dd7b2e85fa3e0c8a43aa084ede847a8e", + "integrity": "sha512-oDYcS3SZo2KGrh/vXFPOahyxW1LZ1Z9emx5ws6YKrjQG9j2aFQaokN8C0IT0lUARGSO7kjJmSFNpp/z17knhVQ==", + "license": "MIT", + "dependencies": { + "@myrotvorets/create-server": "^3.1.1" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.6.0", + "@opentelemetry/api-logs": "^0.44.0 || ^0.45.1 || ^0.46.0", + "@opentelemetry/core": "^1.17.1" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index 37eca028..3da4f6d5 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@grammyjs/auto-retry": "^1.1.1", "@myrotvorets/envalidators": "^2.1.0", "@myrotvorets/opentelemetry-configurator": "^7.0.0", + "@myrotvorets/otel-utils": "^1.1.1", "@opentelemetry/instrumentation-http": "^0.46.0", "@opentelemetry/instrumentation-knex": "^0.32.1", "debug": "^4.3.4", diff --git a/src/controllers/lifecycle.mts b/src/controllers/lifecycle.mts index 6b38dbc6..4d49ad43 100644 --- a/src/controllers/lifecycle.mts +++ b/src/controllers/lifecycle.mts @@ -2,13 +2,13 @@ import debug from 'debug'; import { Knex } from 'knex'; import { Bot } from 'grammy'; +import { getTracer } from '@myrotvorets/otel-utils'; import { addPost, checkPostExists, getDB } from '../lib/db.mjs'; import { Environment } from '../lib/environment.mjs'; import { generateDescription } from '../lib/utils.mjs'; import { getFeaturedImageUrl, getPosts } from '../lib/wpapi.mjs'; import type { PostData } from '../lib/types.mjs'; import { Bugsnag } from '../lib/bugsnag.mjs'; -import { configurator } from '../lib/tracing.mjs'; const error = debug('bot:error'); const dbg = debug('bot:debug'); @@ -54,7 +54,7 @@ async function sendNewPosts(bot: Bot, chat: number, data: PostData[]): Promise { - void configurator.tracer().startActiveSpan('Get posts', async (span) => { + void getTracer().startActiveSpan('Get posts', async (span) => { try { const posts = await getNewPosts(env.NEWS_ENDPOINT, getDB()); dbg('Got %d new posts', posts.length); diff --git a/src/lib/tracing.mts b/src/lib/tracing.mts index 675f3fb0..66faef95 100644 --- a/src/lib/tracing.mts +++ b/src/lib/tracing.mts @@ -1,10 +1,14 @@ import { OpenTelemetryConfigurator } from '@myrotvorets/opentelemetry-configurator'; +import { initProcessMetrics } from '@myrotvorets/otel-utils'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import { KnexInstrumentation } from '@opentelemetry/instrumentation-knex'; +process.env['OTEL_SERVICE_NAME'] = 'bot/myrotvorets.news'; + export const configurator = new OpenTelemetryConfigurator({ - serviceName: 'bot/myrotvorets.news', + serviceName: process.env['OTEL_SERVICE_NAME'], instrumentations: [new HttpInstrumentation(), new KnexInstrumentation()], }); configurator.start(); +await initProcessMetrics();