Skip to content
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

Detect exceptions raised outside of the handler #475

Merged
merged 7 commits into from
May 1, 2024

Conversation

TalUsvyatsky
Copy link
Contributor

@TalUsvyatsky TalUsvyatsky commented Apr 17, 2024

What does this PR do?

This PR adds telemetry for exceptions that occur outside of the handler function.

When an exception occurs outside of the handler function:

  1. aws.lambda.enhanced.errors is emitted
  2. A trace with an error span is created

Motivation

Testing Guidelines

  1. Created a handler file like this:
  import json
 
  0/0 # Purposely raise an exception

  def hello(event, context):
      body = {
          "message": "some message",
          "input": event,
      }
      return {"statusCode": 200, "body": json.dumps(body)}
  1. Deployed my function and invoked it via function URL
  2. Saw traces with an error span from the call (example trace)
  3. Saw aws.lambda.enhanced.errors emitted (graph)
  4. Traces appear in serverless detail page invocation table (link to search for function)
  5. Issues appear in error tracking and are informative

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)

https://datadoghq.atlassian.net/browse/SVLS-4666

@TalUsvyatsky TalUsvyatsky force-pushed the tal.usvyatsky/capture-handler-import-failure branch 8 times, most recently from 80486fd to 76e5cee Compare April 23, 2024 14:17
@TalUsvyatsky TalUsvyatsky marked this pull request as ready for review April 23, 2024 14:32
@TalUsvyatsky TalUsvyatsky requested a review from a team as a code owner April 23, 2024 14:32
@TalUsvyatsky TalUsvyatsky force-pushed the tal.usvyatsky/capture-handler-import-failure branch from 85d0d7d to 0bc08fd Compare April 23, 2024 19:00
@purple4reina
Copy link
Contributor

FYI, pulling from main should fix the check layer size test failure.

@TalUsvyatsky TalUsvyatsky force-pushed the tal.usvyatsky/capture-handler-import-failure branch from 39af365 to f0e8c5e Compare April 24, 2024 13:32
Copy link
Contributor

@duncanista duncanista left a comment

Choose a reason for hiding this comment

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

Amazing work – LGTM.

There's one nit:

tags = None
if context:
function_arn = (context.invoked_function_arn or "").lower()
tk = function_arn.split(":")
function_arn = ":".join(tk[0:7]) if len(tk) > 7 else function_arn
function_version = tk[7] if len(tk) > 7 else "$LATEST"
tags = {
"cold_start": str(is_cold_start).lower(),
"function_arn": function_arn,
"function_version": function_version,
"request_id": context.aws_request_id,
"resource_names": context.function_name,
"functionname": context.function_name.lower()
if context.function_name
else None,
"datadog_lambda": datadog_lambda_version,
"dd_trace": ddtrace_version,
"span.name": "aws.lambda",
}
tags = tags or {}

Should we care about some of the tags that can be added from this? i.e. functionname, cold_start (which should always be true if we are loading), datadog_lambda_version, ddtrace_version

@TalUsvyatsky TalUsvyatsky force-pushed the tal.usvyatsky/capture-handler-import-failure branch 2 times, most recently from 26ed616 to 47c0dab Compare April 29, 2024 17:16
Copy link
Contributor

@duncanista duncanista left a comment

Choose a reason for hiding this comment

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

LGTM – left a nit.

datadog_lambda/tags.py Outdated Show resolved Hide resolved
Copy link
Contributor

@joeyzhao2018 joeyzhao2018 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@TalUsvyatsky TalUsvyatsky force-pushed the tal.usvyatsky/capture-handler-import-failure branch from f6a8496 to 7c5aa58 Compare May 1, 2024 13:55
@TalUsvyatsky TalUsvyatsky merged commit a95341e into main May 1, 2024
51 checks passed
@TalUsvyatsky TalUsvyatsky deleted the tal.usvyatsky/capture-handler-import-failure branch May 1, 2024 14:15
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