Bug: Adding Metric attribute always results in error.
See original GitHub issueExpected Behaviour
A metric viewable in Cloudwatch
Current Behaviour
Lambda will start and go a few lines into the function handler. We are able to inject the dynamodb connections. And possibly around the first call to DynamoDB it goes like this, but it is not clear what is needed to fix this.
fail System.InvalidOperationException: Unable to determine range key from index name at AWS.Lambda.Powertools.Metrics.MetricsAspectHandler.OnException[T](AspectEventArgs eventArgs, Exception exception)
Code snippet
[Metrics(Namespace = "nl.my.namespace", Service = "Print", RaiseOnEmptyMetrics = false, CaptureColdStart = true)]
public async Task<PrintResponse> FunctionHandlerAsync(PrintRequest input, ILambdaContext context)
Possible Solution
Adding the correct attributes in the models for the Object persistence model we have implemented. Even the ones we do not use. If that works I will update this bugreport.
Steps to Reproduce
Add the metric attribute to a Function handler.
[Metrics(Namespace = “nl.my.namespace”, Service = “Print”, RaiseOnEmptyMetrics = false, CaptureColdStart = true)]
AWS Lambda Powertools for .NET version
1.2.0
AWS Lambda function runtime
dotnet6
Debugging logs
fail System.InvalidOperationException: Unable to determine range key from index name
at AWS.Lambda.Powertools.Metrics.MetricsAspectHandler.OnException[T](AspectEventArgs eventArgs, Exception exception)
at AWS.Lambda.Powertools.Common.MethodAspectAttribute.WrapAsync[T](Func`2 target, Object[] args, AspectEventArgs eventArgs)
at lambda_method1(Closure , Stream , ILambdaContext , Stream )
at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145
at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 55
at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176
Issue Analytics
- State:
- Created 4 months ago
- Comments:9 (4 by maintainers)
Closing this issue. This issue might have highlighted the need to expose stack trace from the originating exception if there is no exception handling and it cascades to the handler and is caught by Powertools. Will discuss in opening an issue for that.
Yes, sorry for the late reply. With the fix in my dynamodb component that error disappeared. But still, an underlying error was mostly obscured by the powertools handling of the error. I am going to test it again soon.