Skip to content
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

Merged
merged 5 commits into from
Oct 24, 2019
Merged

Conversation

sfirrin
Copy link
Contributor

@sfirrin sfirrin commented Oct 11, 2019

What does this PR do?

Increments the aws.lambda.enhanced.invocations distribution metric on each function call and increments aws.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.

@sfirrin sfirrin requested a review from a team as a code owner October 11, 2019 17:19
@@ -18,6 +19,7 @@ export function wrap<TEvent, TResult>(
return async (event: TEvent, context: Context) => {
try {
await onStart(event, context);
incrementInvocationsMetric(context.invokedFunctionArn);
Copy link
Contributor

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.

Copy link
Contributor

@DarcyRaynerDD DarcyRaynerDD Oct 11, 2019

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.

@@ -0,0 +1,27 @@
let _didFunctionColdStart = true;
Copy link
Contributor

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

@@ -0,0 +1,27 @@
let _didFunctionColdStart = true;

let _isColdStartSet = false;
Copy link
Contributor

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-io
Copy link

codecov-io commented Oct 15, 2019

Codecov Report

Merging #28 into master will decrease coverage by 0.15%.
The diff coverage is 89.36%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/metrics/listener.ts 86.04% <ø> (ø) ⬆️
src/metrics/index.ts 100% <100%> (ø) ⬆️
src/index.ts 87.87% <100%> (+1.91%) ⬆️
src/utils/arn.ts 100% <100%> (ø)
src/trace/listener.ts 92.85% <100%> (-0.25%) ⬇️
src/utils/handler.ts 100% <100%> (ø) ⬆️
src/metrics/enhanced-metrics.ts 60% <60%> (ø)
src/utils/cold-start.ts 91.66% <91.66%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e6ee43...edd7466. Read the comment docs.

const ENHANCED_LAMBDA_METRICS_NAMESPACE = "aws.lambda.enhanced";

function areEnhancedMetricsEnabled() {
return getEnvValue("DD_ENHANCED_METRICS", "false").toLowerCase() === "true";
Copy link
Contributor

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?

Copy link
Contributor

@DarcyRaynerDD DarcyRaynerDD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work 🎉

@sfirrin sfirrin merged commit 5b2f1bb into master Oct 24, 2019
@sfirrin sfirrin deleted the stephenf/add-enhanced-metrics branch October 24, 2019 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants