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

Properly parent lazily loaded module imports. #446

Merged
merged 3 commits into from Mar 14, 2024

Conversation

purple4reina
Copy link
Contributor

What does this PR do?

Properly parent aws.lambda.import spans for packages that are imported during function execution. Currently app spans are children of the cold start span, which is incorrect.

Screenshot 2024-03-06 at 1 01 36 PM

Motivation

Testing Guidelines

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)

@purple4reina purple4reina requested a review from a team as a code owner March 12, 2024 19:15
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import-parent branch 2 times, most recently from aa30bd6 to a60841b Compare March 13, 2024 18:16
@purple4reina purple4reina force-pushed the rey.abolofia/lazy-import-parent branch from a60841b to 9ccbed9 Compare March 13, 2024 18:20
@@ -29,6 +31,7 @@ def set_cold_start(init_timestamp_ns):
_cold_start = False
_proactive_initialization = False
_lambda_container_initialized = True
from ddtrace import tracer as _tracer
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't know that you could just assign a value by doing an as wow

Comment on lines 78 to +79
def reset_node_stacks():
global root_nodes
root_nodes = []
global import_stack
import_stack = []
root_nodes.clear()
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we removing the globals?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Replacing the lists with new ones was causing my test to fail because somewhere we're holding onto an old reference to these objects. The correct solution is to just remove all the stuff from inside the list.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yet, this would create an O(n) complexity instead of O(1) of reassigning right? Although I guess we'd have the remaining O(n) space in the wild while reassigning. I tried researching which was the best solution for this, but theres like 5 ways of doing it. So I'll take this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method does not do an allocation where as the previous did.

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 overall, left some questions.

Copy link
Contributor

@astuyve astuyve left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Nice Work!

@purple4reina purple4reina merged commit 1015d8d into main Mar 14, 2024
51 checks passed
@purple4reina purple4reina deleted the rey.abolofia/lazy-import-parent branch March 14, 2024 17:55
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.

None yet

4 participants