Skip to content

Use single socket instance for all xray api calls. #467

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 2 commits into from
Apr 9, 2024

Conversation

purple4reina
Copy link
Contributor

What does this PR do?

  • Use single socket connection for all interactions with the xray api
  • Memoize xray api host/port identification
  • Ensure socket creation is done as lazily as possible

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

  • 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 April 9, 2024 17:59
except Exception as e_send:
logger.error("Error occurred submitting to xray daemon: %s", e_send)

def reset(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reset is used for tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: can we move it to tests files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good call. Done.

self._host_port_tuple = self._get_xray_host_port(
os.environ.get(XrayDaemon.XRAY_DAEMON_ADDRESS, "")
)
return self._host_port_tuple
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 value is now memoized so we only need to parse the env var once.

@@ -623,7 +626,7 @@ def handler(event, context):
self.assertEqual(result.span_id, aws_lambda_span.span_id)
self.assertEqual(result.sampling_priority, 1)
mock_send.assert_called_once()
(_, raw_payload), _ = mock_send.call_args
(raw_payload,), _ = mock_send.call_args
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signature of the xray.send method changed.

@purple4reina
Copy link
Contributor Author

Confirmed metadata is still being sent to the xray api.
Screenshot 2024-04-09 at 11 31 20 AM

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

except Exception as e_send:
logger.error("Error occurred submitting to xray daemon: %s", e_send)

def reset(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: can we move it to tests files?

@purple4reina purple4reina merged commit 3414cfb into main Apr 9, 2024
51 checks passed
@purple4reina purple4reina deleted the rey.abolofia/socket branch April 9, 2024 19:43
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