pragmaticivan / nestjs-otel

OpenTelemetry (Tracing + Metrics) module for Nest framework (node.js) 🔭
Apache License 2.0
562 stars 48 forks source link

Access function args in @Span decorator #470

Open dan-cooke opened 8 months ago

dan-cooke commented 8 months ago

First of all ,thanks for the great library! Its been a joy to work with so far

One pattern that I have noticed myself duplicating almost everywhere is this

  @Span('DocumentsService.create')
  async create(userId: string, orgId: string, dto: CreateDocumentDto) {
    this.traceService.getSpan().setAttributes({
      orgId,
      userId,
      dto: JSON.stringify(dto),
    });
// --- snip

Where I annotate a function with Span, and then immediately set the function args into the span attributes.

Question

Is it possible with reflect-metadata to roll that code into @Span , maybe something like this

@Span('DocumentsService.create', ['userId', 'orgId', 'dto'])

Where users have to explicitly set the fields they want to attach to attributes

I am used to this in rust, but I'm not sure if the TS compiler is capable of something like that

pragmaticivan commented 6 months ago

Hey! this is a reasonable ask, PRs are welcome but it will be quite hard if you want to customize the attribute names. You might need to think about a more customizable interface