You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a user, when using the Metrics utility I want dimensions and metadata added during a function execution to be cleared when flushing. At the same time, I also want default dimensions and service name to be preserved.
Take the function code shown in the "code snippet" section below, then run it twice. The EMF logs emitted should look like this:
First invocation:
{
"_aws": {
"Timestamp": 1667915882250,
"CloudWatchMetrics": [
{
"Namespace": "someNS",
"Dimensions": [
[
"service", // <-- Service dimension is here"foo"
]
],
"Metrics": []
}
]
},
"service": "someName", // <-- Service value is here"foo": "bar"
}
Subsequent invocation:
{
"_aws": {
"Timestamp": 1667915928090,
"CloudWatchMetrics": [
{
"Namespace": "someNS",
"Dimensions": [
[
"service", // <-- Service dimension is still here"foo"
]
],
"Metrics": []
}
]
},
"service": "someName", // <-- Service is still here"foo": "bar"
}
Current Behaviour
After the changes made in #1129 (which correspond to v1.4.0), however the service name is cleared together with the non-default dimensions and metadata.
The function below, executed twice, emits these logs:
First invocation:
{
"_aws": {
"Timestamp": 1667915882250,
"CloudWatchMetrics": [
{
"Namespace": "someNS",
"Dimensions": [
[
"service", // <-- Service dimension is here"foo"
]
],
"Metrics": []
}
]
},
"service": "someName", // <-- Service value is here"foo": "bar"
}
Subsequent invocation:
{
"_aws": {
"Timestamp": 1667915928090,
"CloudWatchMetrics": [
{
"Namespace": "someNS",
"Dimensions": [
[
"foo"
] <-- Service dimension is gone
],
"Metrics": []
}
]
},
"foo": "bar"// <-- Service value is also gone
}
The current Metrics implementation (in v1.4.0) looks like this:
publicpublishStoredMetrics(): void{const target =this.serializeMetrics();console.log(JSON.stringify(target));this.storedMetrics={};this.clearMetrics();this.clearDimensions();// <- this is causing the bugthis.clearMetadata();}publicclearDimensions(): void{
this.dimensions={};}
The above means that every time metrics are flushed, stored metrics, dimensions, and metadata are cleared.
This is fine, however default dimensions and service name should be preserved.
Currently, dimensions and defaultDimensions are stored in two separate objects in a Metrics instance. The clearDimensions empties the former but leaves the latter untouched.
However, the service name is currently being stored in dimensions:
A potential fix would be to instead store the service name in the default dimensions, which would have the side effect of keeping it around when clearDimensions is called.
An alternative solution that would allow to keep storing the service in dimensions would involve saving the value of serviceName passed to the utility constructor & resolving its value using the setService() method after any publishStoredMetrics() call.
Steps to Reproduce
Create a Lambda function using any Node.js runtime and use Powertools v1.4.0, use the code shown in the "Code snippet" section, then run twice.
AWS Lambda Powertools for TypeScript version
v1.4.0 (latest)
AWS Lambda function runtime
16.x
Packaging format used
Lambda Layers, Npm
Debugging logs
No response
The text was updated successfully, but these errors were encountered:
dreamorosi
added
bug
Something isn't working
metrics
This item relates to the Metrics Utility
triage
This item has not been triaged by a maintainer, please wait
labels
Nov 8, 2022
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.
Expected Behaviour
As a user, when using the Metrics utility I want dimensions and metadata added during a function execution to be cleared when flushing. At the same time, I also want default dimensions and service name to be preserved.
Take the function code shown in the "code snippet" section below, then run it twice. The EMF logs emitted should look like this:
First invocation:
Subsequent invocation:
Current Behaviour
After the changes made in #1129 (which correspond to
v1.4.0
), however the service name is cleared together with the non-default dimensions and metadata.The function below, executed twice, emits these logs:
First invocation:
Subsequent invocation:
Code snippet
Possible Solution
The current Metrics implementation (in
v1.4.0
) looks like this:The above means that every time metrics are flushed, stored metrics, dimensions, and metadata are cleared.
This is fine, however default dimensions and service name should be preserved.
Currently,
dimensions
anddefaultDimensions
are stored in two separate objects in aMetrics
instance. TheclearDimensions
empties the former but leaves the latter untouched.However, the service name is currently being stored in
dimensions
:A potential fix would be to instead store the service name in the default dimensions, which would have the side effect of keeping it around when
clearDimensions
is called.An alternative solution that would allow to keep storing the service in
dimensions
would involve saving the value ofserviceName
passed to the utility constructor & resolving its value using thesetService()
method after anypublishStoredMetrics()
call.Steps to Reproduce
Create a Lambda function using any Node.js runtime and use Powertools
v1.4.0
, use the code shown in the "Code snippet" section, then run twice.AWS Lambda Powertools for TypeScript version
v1.4.0 (latest)
AWS Lambda function runtime
16.x
Packaging format used
Lambda Layers, Npm
Debugging logs
No response
The text was updated successfully, but these errors were encountered: