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

feat(elasticsearch): support @elastic/elasticsearch client #1877

Merged
merged 42 commits into from
Dec 16, 2020

Conversation

trentm
Copy link
Member

@trentm trentm commented Nov 17, 2020

Based on earlier work in:
#1266

Fixes #968

This commit is very incomplete, based on earlier work in:
#1266
@apmmachine
Copy link
Contributor

apmmachine commented Nov 17, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #1877 updated

  • Start Time: 2020-12-15T18:26:13.389+0000

  • Duration: 18 min 12 sec

Test stats 🧪

Test Results
Failed 0
Passed 16398
Skipped 0
Total 16398

@trentm trentm marked this pull request as ready for review November 20, 2020 01:53
@trentm
Copy link
Member Author

trentm commented Nov 20, 2020

This is ready to review now. There are a few "TODO" comments in there:

% git diff master.. | grep TODO
+// TODO: ask Tomas about apiName addition to RequestEvent
+        // TODO set "span.outcome" (from err and result.statusCode)
+          // TODO: rebuild error object to avoid serialization issues?
+    // TODO test that httpSpan is child of esSpan? currently it isn't

that I don't think all need to be done now.

@delvedor You are welcome to review and/or play with this, but I don't expect you to.

@trentm trentm requested a review from astorm November 20, 2020 01:57
@trentm
Copy link
Member Author

trentm commented Nov 20, 2020

review note: the linting "error" will go away when these commits are squashed

@trentm trentm changed the title feat(elasticsearch): add support @elastic/elasticsearch client feat(elasticsearch): support @elastic/elasticsearch client Nov 20, 2020
Copy link
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

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

I took an initial pass at this -- it looks like a solid start and captures the functionality of the previous instrumentation and @delvedor's first pass at this well. The use of the WeakMap is a nice call-out as well -- Trust your Mechanic Garbage Collector :)

It doesn't look like sub-classing is the common approach for instrumentation in the agent -- normally we'd identify the request method, wrap it, start our business, call the original method, and then clean up our business.

I think the sub-classing/event approach can work though -- and in some ways seems less intrusive than the direct monkey-patching we normally do. There's a few additional defensive measures we'll want to take, but otherwise I'm down with this approach.

Improve the `pathIsAQuery` handling to determine if DB context is set:
- add "_async_search" endpoints
- clarify the regex: match a full URL path segment & no point in
  optionally matching "/template" suffix on "_search"

Also some review feedback for fwd compat:
- guard on CLient constructor function signature change
- gracefully handle `.Client` being renamed
@trentm trentm requested a review from astorm November 21, 2020 04:00
@trentm
Copy link
Member Author

trentm commented Nov 21, 2020

I think the sub-classing/event approach can work though -- and in some ways seems less intrusive than the direct monkey-patching we normally do.

My understanding is this was intentional. The 'request' and 'response' events described at https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/observability.html were, at least in part, intended for this kind of thing.

@trentm
Copy link
Member Author

trentm commented Nov 23, 2020

Remaining TODOs before merging:

  • Decide on error serialization. From the original PR: "we should figure out how to serialize the errors to avoid the loss of important information"
  • Docs and changelog entry.

Related TODOs that can be done separate from this PR (IMHO):

@trentm trentm removed the request for review from astorm November 23, 2020 16:59
@trentm trentm marked this pull request as draft November 23, 2020 17:00
@trentm
Copy link
Member Author

trentm commented Nov 25, 2020

I am moving the TODO item Look into getting the http span(s) to be a child of the Elasticsearch span to a separate ticket, because handling that is a bigger change to agent behaviour: #1889

@trentm trentm added the agent-nodejs Make available for APM Agents project planning. label Dec 11, 2020
…visCI) that resulted in this test failing at least once
Recently on a run of the test suite on TravisCI it was observed that
these tests failed a number of times. The tests are inherently relying
on winning a race: that the setTimeout inside the elasticsearch client's
code is created and fires (even with a short 1ms timeout) before the
elasticsearch query completes. Clearly we can lose this race in test
runs and sometimes frequently on over burdened test infra. It isn't
worth having these flaky tests when we already have other tests for
the error handling path.
@trentm
Copy link
Member Author

trentm commented Dec 14, 2020

jenkins run the module tests for elasticsearch,@elastic/elasticsearch

@trentm
Copy link
Member Author

trentm commented Dec 15, 2020

jenkins run the module tests for elasticsearch,@elastic/elasticsearch

@trentm
Copy link
Member Author

trentm commented Dec 15, 2020

jenkins run the module tests for elasticsearch,@elastic/elasticsearch

@trentm
Copy link
Member Author

trentm commented Dec 15, 2020

jenkins run the module tests for ALL

@trentm
Copy link
Member Author

trentm commented Dec 15, 2020

Since the last time y'all reviewed:

This is ready for re-review when you have the time. Thanks.

Copy link
Contributor

@astorm astorm left a comment

Choose a reason for hiding this comment

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

Looks good from here -- previous feedback's been address and it gets us instrumentation for the modern @elastic/elasticsearch client. One dealer's choice comment on some additional test coverage, but I think we're good to go as it. Approving.

.ci/docker/docker-compose.yml Show resolved Hide resolved
lib/instrumentation/modules/elasticsearch.js Show resolved Hide resolved
lib/parsers.js Show resolved Hide resolved
.tav.yml Show resolved Hide resolved
@trentm trentm merged commit 532e962 into master Dec 16, 2020
@trentm trentm deleted the trentm/new-elasticsearch-client branch December 16, 2020 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instrument the @elastic/elasticsearch module
5 participants