Submit metrics for invocations and errors#19
Merged
Conversation
tianchu
reviewed
Oct 3, 2019
datadog_lambda/wrapper.py
Outdated
| cold_start_request_id = context.aws_request_id | ||
|
|
||
| try: | ||
| lambda_metric( |
Collaborator
There was a problem hiding this comment.
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
| try: | ||
| return self.func(event, context) | ||
| except Exception: | ||
| lambda_metric( |
Collaborator
There was a problem hiding this comment.
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
| logger.debug("datadog_lambda_wrapper initialized") | ||
|
|
||
| def _before(self, event, context): | ||
| global cold_start_request_id |
Collaborator
There was a problem hiding this comment.
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()
Collaborator
There was a problem hiding this comment.
Might be better to prefix the globals with _ to mark them as "private".
This was referenced Oct 24, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.