-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add enhanced lambda metrics #28
Conversation
src/utils/handler.ts
Outdated
@@ -18,6 +19,7 @@ export function wrap<TEvent, TResult>( | |||
return async (event: TEvent, context: Context) => { | |||
try { | |||
await onStart(event, context); | |||
incrementInvocationsMetric(context.invokedFunctionArn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The incrementInvocationsMetric/incrementErrorsMetric logic should probably be moved inside the onStart/onComplete handlers. The idea behind this class is that it's a utility that could be moved out of dd-lambda-js, and potentially be used to wrap one handler multiple times. onComplete can be modified to accept an result or error object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do you think we should make this an opt-in config setting? I'm a little worried about customers accidentally adding synchronous metric calls to their lambdas.
src/utils/cold-start.ts
Outdated
@@ -0,0 +1,27 @@ | |||
let _didFunctionColdStart = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should reuse this logic in the trace handler, since that tracks cold starts as well: https://github.com/DataDog/datadog-lambda-layer-js/blob/2e6ee435fd009896384184cce3dfa40f68b75fe5/src/trace/listener.ts#L19
src/utils/cold-start.ts
Outdated
@@ -0,0 +1,27 @@ | |||
let _didFunctionColdStart = true; | |||
|
|||
let _isColdStartSet = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably inconsistent with how we write js in other repos, but I don't think this repo uses underscores for global variables anywhere else.
Codecov Report
@@ Coverage Diff @@
## master #28 +/- ##
=========================================
- Coverage 89.95% 89.8% -0.16%
=========================================
Files 18 21 +3
Lines 468 510 +42
Branches 72 76 +4
=========================================
+ Hits 421 458 +37
- Misses 27 32 +5
Partials 20 20
Continue to review full report at Codecov.
|
src/metrics/enhanced-metrics.ts
Outdated
const ENHANCED_LAMBDA_METRICS_NAMESPACE = "aws.lambda.enhanced"; | ||
|
||
function areEnhancedMetricsEnabled() { | ||
return getEnvValue("DD_ENHANCED_METRICS", "false").toLowerCase() === "true"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work with most of these changes. One small thing, the other config options are usually exposed both as an environment variable and a config property which we resolve in index.ts . Would you be able to move this logic there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice Work 🎉
What does this PR do?
Increments the
aws.lambda.enhanced.invocations
distribution metric on each function call and incrementsaws.lambda.enhanced.errors
when the Lambda handler throws an exception.Testing Guidelines
Unit tests for the metrics, currently adding the updated layer to functions in the demo account.