feat: add opentelemetry

This commit is contained in:
Sergey Krylov 2026-03-27 06:46:29 +03:00
parent 7a0db391b0
commit 3726ccc369
4 changed files with 1126 additions and 4 deletions

View File

@ -28,6 +28,11 @@
"@nestjs/mapped-types": "*", "@nestjs/mapped-types": "*",
"@nestjs/microservices": "^11.1.14", "@nestjs/microservices": "^11.1.14",
"@nestjs/platform-express": "^11.0.1", "@nestjs/platform-express": "^11.0.1",
"@opentelemetry/auto-instrumentations-node": "^0.72.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.214.0",
"@opentelemetry/resources": "^2.6.1",
"@opentelemetry/sdk-node": "^0.214.0",
"@opentelemetry/semantic-conventions": "^1.40.0",
"@teacinema/contracts": "^1.1.0", "@teacinema/contracts": "^1.1.0",
"@teacinema/core": "^1.0.9", "@teacinema/core": "^1.0.9",
"@willsoto/nestjs-prometheus": "^6.0.2", "@willsoto/nestjs-prometheus": "^6.0.2",

View File

@ -3,6 +3,7 @@ import { NestFactory } from '@nestjs/core'
import { MicroserviceOptions, Transport } from '@nestjs/microservices' import { MicroserviceOptions, Transport } from '@nestjs/microservices'
import { AppModule } from './app.module' import { AppModule } from './app.module'
import './observability/tracing'
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule) const app = await NestFactory.create(AppModule)

View File

@ -0,0 +1,24 @@
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'
import { resourceFromAttributes } from '@opentelemetry/resources'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'
const traceExporter = new OTLPTraceExporter({
url: 'http://jaeger:4317'
})
const otelSdk = new NodeSDK({
traceExporter,
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'notification-service'
}),
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-http': { enabled: true },
'@opentelemetry/instrumentation-nestjs-core': { enabled: true }
})
]
})
otelSdk.start()

1100
yarn.lock

File diff suppressed because it is too large Load Diff