Skip to content

Submit metrics for invocations and errors #19

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

Merged
merged 4 commits into from
Oct 24, 2019

Conversation

sfirrin
Copy link
Contributor

@sfirrin sfirrin commented Oct 3, 2019

What does this PR do?

Submits aws.lambda.enhanced.invocations and aws.lambda.enhanced.errors metrics from the wrapper.

Testing Guidelines

Added and updated unit tests.

Also updated some of the functions in the demo account that the metrics are reporting for the functions with the new version of the layer.

@sfirrin sfirrin requested a review from a team as a code owner October 3, 2019 18:32
try:
lambda_metric(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although this is a oneliner, I would make it a function in metric.py, to keep the wrapper focus on code flow rather than details.

@@ -72,6 +89,13 @@ def __call__(self, event, context):
self._before(event, context)
try:
return self.func(event, context)
except Exception:
lambda_metric(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Although this is a oneliner, I would make it a function in metric.py, to keep the wrapper focus on code flow rather than details.


def _before(self, event, context):
global cold_start_request_id
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm pretty sure context.aws_request_id stays the same for retried requests, which is gonna cause incorrect cold start? Also if you are not using the actual request id, how about?

# In a `cold_start.py` or `utils.py`?
initialized = False
cold_start = True

def set_cold_start():
    global initialized
    global cold_start
    cold_start = (initialized == False)
    initialized = True

def is_cold_start():
    global cold_start
    return cold_start

# In wrapper.py (here)
from utils import set_cold_start
def _before(self, event, context):
    set_cold_start()

# use is_cold_start in, say, metric.py
from utils import is_cold_start
is_cold_start()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be better to prefix the globals with _ to mark them as "private".

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.

LGTM

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