feat: instrument api, relay and worker with opentelemetry

This commit is contained in:
2026-11-20 12:55:53 +03:00
parent 9ed32e2d15
commit 307b658bfb
18 changed files with 1843 additions and 49 deletions
+18 -5
View File
@@ -1,4 +1,5 @@
import { Logger } from '@nestjs/common';
import { SpanStatusCode, trace } from '@opentelemetry/api';
import { Attachment, AttachmentJob, PrismaClient } from '@prisma/client';
import { createHash, randomUUID } from 'crypto';
import {
@@ -50,6 +51,8 @@ class PermanentError extends Error {
class TimeoutError extends Error {}
const tracer = trace.getTracer('messenger-worker');
export class JobProcessor {
private readonly logger = new Logger('JobProcessor');
@@ -141,11 +144,21 @@ export class JobProcessor {
}
let variants: RenderedVariant[];
try {
variants = await renderVariants(
original,
this.options.maxPixels,
Math.ceil(this.options.timeoutMs / 1000),
);
variants = await tracer.startActiveSpan('attachment.render_variants', async (span) => {
span.setAttribute('messenger.image.bytes', original.length);
try {
return await renderVariants(
original,
this.options.maxPixels,
Math.ceil(this.options.timeoutMs / 1000),
);
} catch (error) {
span.setStatus({ code: SpanStatusCode.ERROR, message: error instanceof Error ? error.name : 'error' });
throw error;
} finally {
span.end();
}
});
} catch (error) {
if (error instanceof InvalidImageError) {
throw new PermanentError('invalid_image', 'image cannot be decoded');