-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
datadog_lambda/wrapper.py
Outdated
try: | ||
lambda_metric( |
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.
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.
datadog_lambda/wrapper.py
Outdated
@@ -72,6 +89,13 @@ def __call__(self, event, context): | |||
self._before(event, context) | |||
try: | |||
return self.func(event, context) | |||
except Exception: | |||
lambda_metric( |
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.
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.
datadog_lambda/wrapper.py
Outdated
|
||
def _before(self, event, context): | ||
global cold_start_request_id |
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.
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()
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.
Might be better to prefix the globals with _
to mark them as "private".
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.
LGTM
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.