Skip to content

Catch invocation event tag extraction exceptions #157

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 1 commit into from
Aug 3, 2021

Conversation

DylanLovesCoffee
Copy link
Contributor

What does this PR do?

Moves self.response initialization and the logic to extract span tags from the event that invokes the Lambda function within a try...catch so it doesn't break the Lambda.

Motivation

In general, we shouldn't break the user's function from executing. In this case, if the invoking event is not what we expect, we can break the function from being executed. For example, an S3 event that doesn't have an arn field raised this error:

{
  "errorMessage": "'arn'",
  "errorType": "KeyError",
  "stackTrace": [
    "  File \"/opt/python/lib/python3.8/site-packages/datadog_lambda/wrapper.py\", line 55, in __call__\n    return self.func(*args, **kwargs)\n",
    ...
    "  File \"/opt/python/lib/python3.8/site-packages/datadog_lambda/trigger.py\", line 87, in parse_event_source_arn\n    return event_record.get(\"s3\")[\"bucket\"][\"arn\"]\n"
  ]
}

Catching the exception won't break the execution of the function and will still allow us to debug an issue.

Testing Guidelines

Passed unit tests and integration tests. Also tested my own build of the layer.

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@DylanLovesCoffee DylanLovesCoffee requested a review from a team as a code owner July 30, 2021 22:56
@DylanLovesCoffee DylanLovesCoffee merged commit 709a7b5 into main Aug 3, 2021
@DylanLovesCoffee DylanLovesCoffee deleted the dyl/catch-invoke-event-tag-exceptions branch August 3, 2021 14:00
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.

2 participants