-
Notifications
You must be signed in to change notification settings - Fork 154
Feature request: Support setting functionName for cold-starts via middy #3642
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hey @steven10172 thanks for opening the issue. After a bit of testing I realise that having this option would reduce the number of metrics for a cold start. It is possible with the right query, but the number of metric will still increase with each Lambda resource replacement. We have seen a similar request recently to decouple resource names from configuration, i.e. Idempotency records and function names. I see a risk for users to unintentionally override the name which makes it hard to track back the actual resource of the function, but that is the price of the customisation. Maybe I am missing something, but I'd put the I am curious to hear @hjgraca, @phipag and @leandrodamascena views, how they'd see it in Python, .NET and Java |
Hi @am29d! Thanks for tagging me here.
Are you talking about adding this as a default dimension? If so, I completely agree that we shouldn't do this using default dimensions because the experience isn't the best and you'll probably end up with multiple dimensions, making it harder to search, potentially losing data, and the customers will probably paying twice for the metrics.
Yes, that's a good option! I'm just wondering if the name should be |
Hey @am29d! The behavior in Java is the same. It is not possible to customize the function name. It is extracted from the Lambda context. I agree with the option to add a I want to make sure I understand this correctly: Adding the |
That's correct - this is also why we are not adding it to the |
I think we all agree that we should allow customers to modify the function name. The two additional points to resolve is where to add it. In Java the Metrics class is static, so the only option is to pass it to the decorator - I suspect the same is true for .NET (is it @hjgraca?). For Python & TS, we can go either way: Option 1 const metrics = new Metrics({
functionName: 'foo'
});
export const handler = middy()
.use(logMetrics(metrics, {
captureColdStart: true,
})
.handler( ... ) Option 2 const metrics = new Metrics();
export const handler = middy()
.use(logMetrics(metrics, {
captureColdStart: true,
functionName: 'foo'
})
.handler( ... ) Java/.NET are going for something similar to option 2. Personally I'd prefer option 1, but for consistency's sake and also because |
My preference is option 2 as it works better for projects with 100s of handlers and run across 100s of lambdas. For simplicity my team has a generic metric object we consume, though I could make option 1 work via ENV injection of the value. Note: 🤔 maybe an ENV variable that sets the value could be of use here. It would allow more stable/connected values via CDK. Another reason for option 2, is that outside of middy you can already set the function name via
It's just that middy always sets the value to context, so maybe an alternative to option 2 is to only set the name if not currently defined. In theory you could offer the following:
And optionally you could support overriding of edit: spelling and grammar adjustments |
I agree, this will to use this feature for all options we provide, with or without middy. |
@steven10172 will be working on the PRs for these change. |
This issue is now closed. Please be mindful that future comments 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. |
This is now released under v2.17.0 version! |
Use case
I would like to use the
logMetrics
middleware and specify an alternative function name. This would allow for names to be more static since CDK may sometimes replaces functions and the trailing characters are random.Solution/User Experience
I would recommend updating the middy
ExtraOptions
interface to accept another property calledfunctionName
that if defined is used instead ofrequest.context.functionName
.Example usage:
Alternative solutions
Another solution would be to expose an object to the
ExtraOptions
interface that would allow attaching any dimensions to the cold start metric. This can then be used to override thefunction_name
dimension, though caution would need to be exercised to ensure the value is not overwritten within the cold start check (ref)Example usage:
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: