Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context.getHandler().name returns PropertyDescriptor for methods annotated with @Span #503

Open
snigdha920 opened this issue Oct 17, 2024 · 0 comments

Comments

@snigdha920
Copy link

snigdha920 commented Oct 17, 2024

I have a controller method annotated with @Span:

import { Controller, Get } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Movie } from './movie.entity';
import { MovieService } from './movie.service';
import { Span } from 'nestjs-otel';

@Controller('movies')
@ApiTags('movies')
export class MovieController {
  constructor(private readonly movieService: MovieService) {}

  @Get('')
  @Span()
  list(): Promise<Movie[]> {
    return this.movieService.findAll();
  }
}

This is my interceptor where I do context.getHandler().name:

import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { PinoLogger } from 'nestjs-pino';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

@Injectable()
export class LoggingInterceptor implements NestInterceptor {
  constructor(private readonly logger: PinoLogger) {}
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    const controller = context.getClass().name;
    const handler = context.getHandler().name; // Here is the isse, I expect the name of the method, but I get `PropertyDescriptor` instead

    this.logger.info(`Before... ${controller} ${handler}`);

    const now = Date.now();
    return next
      .handle()
      .pipe(
        tap(() => this.logger.info(`After... ${Date.now() - now}ms ${controller} ${handler}`)),
      );
  }
}

I expect the log MovieController list but I get MovieController PropertyDescriptor instead:

image

Here is the minimum reproduction repo: https://github.com/snigdha920/nestjs-otel-prom-grafana-tempo

Think the issue happens here:

const wrappedFunction = function PropertyDescriptor(...args: any[]) {
And it should be fine if we set the wrappedFunction's name correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant