Skip to content

Commit

Permalink
Fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Dec 21, 2023
1 parent 8db811b commit fe1fe26
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/lifecycle.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -54,7 +54,7 @@ async function sendNewPosts(bot: Bot, chat: number, data: PostData[]): Promise<v

export function lifecycle(env: Environment, bot: Bot): void {
const inner = (): void => {
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);
Expand Down
6 changes: 5 additions & 1 deletion src/lib/tracing.mts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit fe1fe26

Please sign in to comment.