Replies: 3 comments 4 replies
-
Thanks for opening the discussion, I appreciate the effort you put in laying out the use cases. As I mentioned in my original post the team is keen to gather some additional datapoints before making a decision. If anyone reads this and is interested in this type of feature please leave a 👍 to the original post, or leave a comment below if you want to share your point of view / use case. |
Beta Was this translation helpful? Give feedback.
-
Perhaps instead of doing this, which IMO is an anti-pattern. // Easy imports for most use-cases
import { logger } from '@aws-lambda-powertools/logger/defaults'
import { metrics } from '@aws-lambda-powertools/metrics/defaults'
import { tracer } from '@aws-lambda-powertools/tracer/defaults' We could release separate packages that offer ready-to-go instances: // Easy imports for most use-cases
import logger from '@aws-lambda-powertools/logger-instance'
import metrics from '@aws-lambda-powertools/metrics-instance'
import tracer from '@aws-lambda-powertools/tracer-instance' |
Beta Was this translation helpful? Give feedback.
-
(I got here via @saragerion 's tweet - thanks Sara! - https://twitter.com/Sarutule/status/1549732065242923009) Weird / possibly ignorant question on my part - what does "vend" mean? :) E.g. I think if I use the word "provide" instead of "vend" here it all makes sense to me, but I wonder if I'm missing meaning? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Porting the discussion over from #777.
Relevant quotes from the issue:
@bilalq:
@dreamorosi:
My take on this is that nothing is lost by vending default instances. You wouldn't be "losing the chance to configure the class via constructor parameters", because that option would remain available if you wanted it. However, the default setup becomes a lot easier to use. The added convenience is not just "saving one line". With default instances, the following advantages exist:
powertools.ts
file per lambda. This does not just save one line of code, but dozens of lines of highly repetitive code per lambda that could better be expressed as configuration elsewhere. As an anecdotal point, we run many distinct lambda functions, so this amounts to literally hundreds of lines of code we could avoid.If we look at other libraries attempting to solve similar problems, they all vend default implementations that are ready to go. Notable examples include the popular lambda-log library and the DAZN Lambda PowerTools that this library is inspired by.
For advanced usage, the option of instantiating a specially configured instance is always there. But I would conjecture that vending default instances serves the vast majority and essentially comes out as a way to use this library with sane defaults rather than forcing them to go through an architectural decision point of either building their own conventions around ad-hoc singletons or setting up dependency injection just to get logging/tracing/metrics working.
Beta Was this translation helpful? Give feedback.
All reactions