Description
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 called functionName
that if defined is used instead of request.context.functionName
.
Example usage:
export const handler = middy()
.use(injectLambdaContext(logger, { resetKeys: true }))
.use(
logMetrics(metrics, {
captureColdStartMetric: true,
defaultDimensions: { functionName: LambdaNames.GET_ASSET },
}),
)
.handler(getAssetHandler);
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 the function_name
dimension, though caution would need to be exercised to ensure the value is not overwritten within the cold start check (ref)
Example usage:
export const handler = middy()
.use(injectLambdaContext(logger, { resetKeys: true }))
.use(
logMetrics(metrics, {
captureColdStartMetric: true,
coldStartDimensions: { function_name: LambdaNames.GET_ASSET },
defaultDimensions: { functionName: LambdaNames.GET_ASSET },
}),
)
.handler(getAssetHandler);
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status