Use single socket instance for all xray api calls.#467
Merged
purple4reina merged 2 commits intomainfrom Apr 9, 2024
Merged
Conversation
purple4reina
commented
Apr 9, 2024
datadog_lambda/xray.py
Outdated
| except Exception as e_send: | ||
| logger.error("Error occurred submitting to xray daemon: %s", e_send) | ||
|
|
||
| def reset(self): |
Contributor
Author
There was a problem hiding this comment.
reset is used for tests.
Contributor
There was a problem hiding this comment.
nitpick: can we move it to tests files?
Contributor
Author
There was a problem hiding this comment.
Yes, good call. Done.
purple4reina
commented
Apr 9, 2024
| self._host_port_tuple = self._get_xray_host_port( | ||
| os.environ.get(XrayDaemon.XRAY_DAEMON_ADDRESS, "") | ||
| ) | ||
| return self._host_port_tuple |
Contributor
Author
There was a problem hiding this comment.
This value is now memoized so we only need to parse the env var once.
purple4reina
commented
Apr 9, 2024
| self.assertEqual(result.sampling_priority, 1) | ||
| mock_send.assert_called_once() | ||
| (_, raw_payload), _ = mock_send.call_args | ||
| (raw_payload,), _ = mock_send.call_args |
Contributor
Author
There was a problem hiding this comment.
Signature of the xray.send method changed.
Contributor
Author
joeyzhao2018
approved these changes
Apr 9, 2024
datadog_lambda/xray.py
Outdated
| except Exception as e_send: | ||
| logger.error("Error occurred submitting to xray daemon: %s", e_send) | ||
|
|
||
| def reset(self): |
Contributor
There was a problem hiding this comment.
nitpick: can we move it to tests files?
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?
Motivation
The need for speed.
Testing Guidelines
Additional Notes
Previously, we were creating a new socket connection and closing the connection for each xray api call. When xray is enabled, and the lambda has extracted trace context from an upstream event, the xray api is called twice.
When an xray api is called, this change decreases runtime duration by somewhere between 1-5%.
Types of Changes
Check all that apply