MetinSeylan / Nestjs-OpenTelemetry

🔭 Deeply Integrated and Auto Instrumented OpenTelemetry module for NestJS
361 stars 42 forks source link

Question: How does this module work? #37

Closed MattGson closed 2 years ago

MattGson commented 2 years ago

My understanding is that the NodeJS OTEL implementation has to monkey patch the instrumented modules BEFORE any other modules require them.

This module only initialises the SDK after bootstrapping the app, which means that all modules must have been imported into the app module already.

Am I misunderstanding something here?

Asking more out of curiosity than anything.

Maklestiguan commented 2 years ago

It probably won't work with every instrumentation, say mongoose or amqplib or pino, but seem to work fine with http instrumentation. I'm not sure why http does work but here's some speculations:

This is what I had using even non-module way of starting SDK:

This works and said libraries get instrumented:

import openTelemetrySDK from './shared/open-telemetry/tracing-telemetry-sdk.setup'
import { Logger } from 'nestjs-pino'
...other imports

const logger = new Logger('AppBootstrap')

async function bootstrap(): Promise<void> {
    try {
        await openTelemetrySDK.start()

This setup won't be able to patch mongoose, pino etc. and traces won't be shown in jaeger/injected in pino logs. But some instrumentations will still work somehow

...other imports (I think `AppModule` import being one of the most important in this case)
import { Logger } from 'nestjs-pino'
import openTelemetrySDK from './shared/open-telemetry/tracing-telemetry-sdk.setup'

const logger = new Logger('AppBootstrap')

async function bootstrap(): Promise<void> {
    try {
        await openTelemetrySDK.start()

So I think the main goal for this library is tracing what's inside the app without going too deep in other things such as injections in logs, DBs, queues etc. If that's the case - the current implementation is good to go

In the end I'd say that you might face some issues when trying to go for a more detailed setup since as you said

NodeJS OTEL implementation has to monkey patch the instrumented modules BEFORE any other modules require them

temarusanov commented 2 years ago

Why did you close this? @MetinSeylan