opentelemetry-js
opentelemetry-js copied to clipboard
Missing active context in the Prisma event listener
trafficstars
I am trying to log Prisma queries, but the active context is missing in the event listener. Maybe someone knows how to fix it?
@Injectable()
export class PrismaService extends PrismaClient<LogEvents, 'info' | 'warn' | 'error' | 'query'> implements OnModuleInit {
constructor() {
super({ log: [{ emit: 'event', level: 'query' }] });
}
public async onModuleInit(): Promise<void> {
this.$on('query', () => {
console.log(context.active()); // no active context
});
await this.$connect();
}
}
Init telemetry
...
const sdk = new NodeSDK({
autoDetectResources: true,
contextManager: new AsyncLocalStorageContextManager(),
spanProcessors,
metricReader,
instrumentations: [
new NestInstrumentation(),
new HttpInstrumentation(),
new ExpressInstrumentation(),
new PrismaInstrumentation({ middleware: true }),
],
});
sdk.start();
- [x] This only affects the JavaScript OpenTelemetry library
- [x] This may affect other libraries, but I would like to get opinions here first