powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature (Tracer): Allow users to specify segment names for captured methods

Open misterjoshua opened this issue 3 years ago • 2 comments

Description of the feature request

Problem statement

Tracer's capture decorators currently try to determine the name of the segment from the function it decorates. While this is fine for a small project, for a larger app, auto-generated names like ### render are not descriptive enough to identify which part of the code is represented by the segment.

Summary of the feature

I'd like the ability to specify the segment name when I capture methods.

Code examples

const tracer = new Tracer(); // aws lambda powertools

interface MyInterface {
   render(): Promise<string>;
}

class ImplA implements MyInterface {
  @tracer.captureMethod({ segmentName: '### ImplA.render' })
  async render() { ... }
}

class ImplB implements MyInterface {
  @tracer.captureMethod({ segmentName: '### ImplB.render' })
  async render() { ... }
}

Benefits for you and the wider AWS community

Allows developers to more clearly identify the sources of segments in larger codebases. This would make navigating a trace in the X-Ray console easier.

Describe alternatives you've considered

I've been putting metadata in the segments to help identify the source code associated with a segment, but this requires a lot of clicking in the X-Ray console to find what I'm looking for.

Additional context

In my example above, I named my segments to reference the corresponding concrete class names. In an ideal world, I'd want the automatic naming to replicate this. But I was unsure of two things:

  • Whether TypeScript can identify the class name; and
  • Whether we should consider changing the segment naming scheme a breaking change.

Related issues, RFCs

None

misterjoshua avatar Sep 08 '22 22:09 misterjoshua

Thanks for opening this issue. I agree with you about the benefits highlighted and this is certainly a feature we could consider adding in the future. Please allow us some time to discuss this and come back to you.

saragerion avatar Sep 09 '22 08:09 saragerion

@dreamorosi Just as an aside, here's another interesting edge case where specifying subSegmentName will be useful.

image

In this case, the tracer tries to derive the name of the segment from the anonymous function returned by the @Retryable decorator - but the anonymous function will not have a name, so we get an empty segment name as shown in the trace.

image

And here's a workaround for now:

image

Edit: I've opened an issue for this edge case #1093, as I think it's a fixable problem.

misterjoshua avatar Sep 19 '22 22:09 misterjoshua

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Oct 11 '22 12:10 github-actions[bot]