Skip to content

Conversation

@swfunc
Copy link
Contributor

@swfunc swfunc 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.

@swfunc swfunc requested a review from a team as a code owner October 3, 2019 18:32
cold_start_request_id = context.aws_request_id

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.

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.

logger.debug("datadog_lambda_wrapper initialized")

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.

4 participants